Pergunta

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?

Foi útil?

Solução

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
}

Outras dicas

The *_save_after events are fired from the Varien_Object class, and is dynamic depending on the class. So it is gonna be the same event for all product types.

You can still observe the catalog_product_save_after event and perform your actions depending on the product type :

public function yourObserverMethod($observer)
{          
    $product = $observer->getEvent()->getProduct();
    if($product == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) {
        // Your stuff
    }

}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top