Question

I use this Event Observer on a multistore for a custom URL Structure Manufacturer in product url key.
The problem is now that I need this for only one specific store id. How can I set a custom Event Observer for specific store id?

Was it helpful?

Solution

you can just check inside the observer if you are on the right store view.

public function updateurl($observer)
{
    $storeId = your store id here;
    if (Mage::app()->getStore()->getId() == $storeId) {
        //your code goes here.
    }
}

OTHER TIPS

In this case,i am suggesting to you use catalog_product_save_after.

And if you want for a particular store then use $observer->getEvent()->getProduct()->getStoreId() that give your product store id.

see why i suggest you that use $observer->getEvent()->getProduct()->getStoreId() because of this link How can I get the correct store context in the product save observer?

So you need to put the below condition for at your observer

if ($observer->getEvent()->getProduct()->getStoreId() == 'Your_Match_Store_id') {
}

Observer

class MageStack_24869_Model_Observer
{
    public function updateurl($observer)
    {
        if ($observer->getEvent()->getProduct()) {
            if ($observer->getEvent()->getProduct()->getStoreId() == 'Your_Match_Store_id') {
                $product = $observer->getEvent()->getProduct();
                $url = '';

                if (!is_null($product->getData('country_of_manufacture'))) {
                    $url .= $product->getAttributeText('country_of_manufacture') . '-';
                }

                if (!is_null($product->getData('sku'))) {
                    $url .= $product->getData('sku') . '-';
                }

                if(!is_null($product->getData('name'))) {
                    $url .= $product->getData('name');
                }

                $product->setData('url_key', $url);      
            }
        }
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top