Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Problem Overwriting catalog_product_link API Methods
 
Dieter21
Member
 
Avatar
Total Posts:  51
Joined:  2008-03-29
Belgium
 

Hello,

I want to overwrite the function _getTypeId($type) in file app/code/core/Mage/Catalog/Model/Product/Link/Api.php.
At the moment that function looks as followed:

class Mage_Catalog_Model_Product_Link_Api extends Mage_Catalog_Model_Api_Resource
{
...
    protected 
$_typeMap = array(
        
'related'       => Mage_Catalog_Model_Product_Link::LINK_TYPE_RELATED,
        
'up_sell'       => Mage_Catalog_Model_Product_Link::LINK_TYPE_UPSELL,
        
'cross_sell'    => Mage_Catalog_Model_Product_Link::LINK_TYPE_CROSSSELL,
    );
...
    protected function 
_getTypeId($type)
    
{
        
if (!isset($this->_typeMap[$type])) {
            $this
->_fault('type_not_exists');
        
}

        
return $this->_typeMap[$type];
    
}
...
}

I want to add an array-element ‘grouped’ to the $_typeMap variable so that it looks as follows:

protected $_typeMap = array(
        
'related'       => Mage_Catalog_Model_Product_Link::LINK_TYPE_RELATED,
        
'up_sell'       => Mage_Catalog_Model_Product_Link::LINK_TYPE_UPSELL,
        
'cross_sell'    => Mage_Catalog_Model_Product_Link::LINK_TYPE_CROSSSELL,
        
'grouped'    => Mage_Catalog_Model_Product_Link::LINK_TYPE_GROUPED
    
);

So far I’ve made my own module in app/code/community/Linux4ever/MagentoXtender/Model/Api.php that looks like this:

<?php

class Linux4ever_MagentoXtender_Model_Api extends Mage_Catalog_Model_Product_Link_Api //Mage_Core_Model_Abstract
{
    
/** OVERWRITE ARRAY IN BASE CLASS */
    
protected $_typeMap = array(
        
'related'       => Mage_Catalog_Model_Product_Link::LINK_TYPE_RELATED,
        
'up_sell'       => Mage_Catalog_Model_Product_Link::LINK_TYPE_UPSELL,
        
'cross_sell'    => Mage_Catalog_Model_Product_Link::LINK_TYPE_CROSSSELL,
        
'grouped'       => Mage_Catalog_Model_Product_Link::LINK_TYPE_GROUPED
    
);
    
    
/** OVERWRITE FUNCTION IN BASE CLASS */
    
protected function _getTypeId($type)
    
{
        
if (!isset($this->_typeMap[$type])) {
            $this
->_fault('type_not_exists');
        
}

        
return $this->_typeMap[$type];
    
}
}

?>

I’ve tried some things in app/code/community/Linux4ever/MagentoXtender/etc/config.xml like this:

<config>
<global>
<
models>
<
Catalog_Product_Link_Api>
<class>
Linux4ever_MagentoXtender_Model</class>
</
Catalog_Product_Link_Api>
</
models>
</global>
</
config>
But this doesn’t work.

How do I force Magento to use my class (Linux4ever_MagentoXtender_Model_Api) for all the catalog_product_link API Methods instead of Magento’s class(Mage_Catalog_Model_Product_Link_Api )?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Dieter21
Member
 
Avatar
Total Posts:  51
Joined:  2008-03-29
Belgium
 

In the meantime I have found the solution to my problem.

I created a module in \app\code\community\Linux4ever\MagentoXtender.

In the file \app\code\community\Linux4ever\MagentoXtender\Model\Product\Link\api.php i put the following code:

<?php

class Linux4ever_MagentoXtender_Model_Product_Link_Api extends Mage_Catalog_Model_Product_Link_Api //Mage_Core_Model_Abstract
{
    
/** OVERWRITE ARRAY IN BASE CLASS */
    
protected $_typeMap = array(
        
'related'       => Mage_Catalog_Model_Product_Link::LINK_TYPE_RELATED,
        
'up_sell'       => Mage_Catalog_Model_Product_Link::LINK_TYPE_UPSELL,
        
'cross_sell'    => Mage_Catalog_Model_Product_Link::LINK_TYPE_CROSSSELL,
        
'grouped'       => Mage_Catalog_Model_Product_Link::LINK_TYPE_GROUPED
    
);
    
    
/** OVERWRITE FUNCTION IN BASE CLASS */
    
protected function _getTypeId($type)
    
{
        
if (!isset($this->_typeMap[$type])) {
            $this
->_fault('type_not_exists');
        
}

        
return $this->_typeMap[$type];
    
}
}

?>

In the file \app\code\community\Linux4ever\MagentoXtender\etc\api.xml i put the following code:

<config>
    <
api>
        <
resources>
             <
catalog_product_link>
                <
model>magentoxtender/product_link_api</model>
            </
catalog_product_link>
        </
resources>
    </
api>
</
config>

And the next code is what did the trick to get it working.
In the file \app\etc\modules\Linux4ever_MagentoXtender.xml i put the following code:

<?xml version="1.0"?>
<config>
    <
modules>
        <
Linux4ever_MagentoXtender>
            <
active>true</active>
            <
codePool>community</codePool>
            <
depends>
                    <
Mage_Catalog />
            </
depends>
        </
Linux4ever_MagentoXtender>
    </
modules>
</
config>

The <depends>...</depends> entry forces the config generator to first load the \app\code\core\Mage\Catalog\etc\api.xml file and than overwrite the config entries with the ones from \app\code\community\Linux4ever\MagentoXtender\etc\api.xml

Hopefully someone finds this usefull smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
LeeSaferite
Guru
 
Avatar
Total Posts:  322
Joined:  2007-08-31
Lake City, FL
 

Why are you overriding the _getTypeId() method? 
Doesn’t overriding the variable by itself work?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Dieter21
Member
 
Avatar
Total Posts:  51
Joined:  2008-03-29
Belgium
 

I haven’t actually tried that Lee smile I will try it and let you know if it works.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top