Frage

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?

War es hilfreich?

Lösung

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
}

Andere Tipps

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
    }

}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top