1

I am creating a small module. In which I have built my own tab in System- Configuration, Name "ZARA" which consists of a textbox. I can enter words in the textbox and save the configuration.

Now my problem is, I want that the module should append the word entered in the configuration to the product name through a so-called observer whenever a product is saved.

for example, I entered "Test" as a test word in the configuration. I then open a product in the backend in product management, which is called "RedShirt". When I save this now, it's called "RedShirtTest". If I save it again, it's called "RedShirtTestTest". Thank you in advance if anybody can clear my issue. I'm totally new to Magento. Please answer regarding Magento 1.9.

0

Add this to your module. If you want to use this only in backend change global node to adminhtml ...

app/code/community/My/Module/etc/config.xml

<global>
    ...
    <events>
        <catalog_product_save_before>
            <observers>
                <my_module_append_text>
                    <class>my_module/observer</class>
                    <method>addText</method>
               </my_module_append_text>
            </observers>
        </catalog_product_save_before>
    </events>
</global>

app/code/community/My/Module/Model/Observer.php

class My_Module_Model_Observer
{
    public function addText(Varien_Event_Observer $observer)
    {
        /** @var Mage_Catalog_Model_Product $product */
        $product = $observer->getData('product');
        $text = Mage::getStoreConfig('path/to/field');

        $product->setName($product->getName() . $text);
    }
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.