Search code examples
magentoobservers

Magento observe save only special product type


I'm writing a custom module, where i've added a custom product type. How can i write an observer catalog_product_save_after only for that custom product type?


Solution

  • You cannot add an observer for that type of product, but you can check in the observer if the product is valid. If not then do nothing.

    public function doSomething($observer){
       $product = $observer->getEvent()->getProduct();
       if ($product->getTypeId() != 'YOUR TYPE HERE'){
           return $this;
       }
       //your magic here
    }