Magento Forum

   
On product creation, how can I set one attribute’s value from another attribute? 
 
maburoe
Jr. Member
 
Total Posts:  8
Joined:  2008-05-14
Kyoto, Japan
 

When a product is being newly created(saved), I want to set the SKU value to URL key.
Which class should I overload?

 
Magento Community Magento Community
Magento Community
Magento Community
 
maburoe
Jr. Member
 
Total Posts:  8
Joined:  2008-05-14
Kyoto, Japan
 

I found the way:

I overloaded the following class & functions.

Mage_Adminhtml_Catalog_ProductController::_initProductSave()

protected function _initProductSave()
    
{
        $product 
parent::_initProductSave();
        
        
//Set SKU value to URL-key
        
$product->setData('url_key'$product->getData('sku'));
        
        return 
$product;
    
}

Mage_Adminhtml_Catalog_ProductController::_initProductSave()

public function saveAction()
    
{
        parent
::saveAction();
    
}

Since I’m overloading controller, I also edited etc/config.xml file.

<rewrite>
            <
mynamespace_mymodule_catalog_product_save>
                <
from><![CDATA[#^/admin/catalog_product/save/$#]]></from>
                
<to>/mymodule/catalog_product/save/</to>
            </
mynamespace_mymodule_catalog_product_save>
        </
rewrite>

Then, no matter what value you enter for URL-key, the URL-key value will be the value of SKU.

You can check How to overload a controller for more details about overloading controller.

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