0

I want to create a dynamic name for a product. I want to add color and brand as product name after saving a product it should create name as color + brand. I'll give an example. I'm selecting "black" as color and "acer" as brand then my product name should save as "black acer".

Is this possible? Please Give example or about that I'm using magento 1.9.1.0 version.

1
  • Yes it's possible but with your own module. Make name attribute as not required and create observer for event catalog_product_save_before there you can generate name.
    – kuba_ceg
    Sep 4, 2015 at 6:31

1 Answer 1

1

Yes this is possible using observers.

In your modules config.xml set up the observer like so;

...
<events>
    <catalog_product_save_before>
        <observers>
            <create_name>
                <class>[Namespace]_[ModuleName]_Model_Observer</class>
                <method>createName</method>
            </create_name>
        </observers>
    </catalog_product_save_before>
</events>
...

and then create your observer to manipulate the name

<?php

// app/code/[codePool]/[Namespace]/[ModuleName]/Model/Observer.php
class [Namespace]_[ModuleName]_Model_Observer
{
    public function createName($observer)
    {
        // get the product from the observer
        $product = $observer->getEvent()->getProduct();

        // the original name
        $name = $product->getName();

        // manipulate the name
        $name = "Woop Woop $name";

        // reset the name on the product
        $product->setName($name);
    }
}

In your observer method you can get whatever data you are about to save against the product. That includes the attributes you have entered like colour etc. You can build your name up from those and set it against the product again.

If you are manipulating the name you may also want to change things like the url key that is created for you based on the name in the same way.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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