Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Magento仅保存特殊产品类型_Magento_Observers - Fatal编程技术网

Magento仅保存特殊产品类型

Magento仅保存特殊产品类型,magento,observers,Magento,Observers,我正在编写一个自定义模块,其中添加了一个自定义产品类型。如何仅为该自定义产品类型编写观察者目录\u product\u save\u?您不能为该类型的产品添加观察者,但可以在观察者中检查产品是否有效。如果没有,那就什么也不做 public function doSomething($observer){ $product = $observer->getEvent()->getProduct(); if ($product->getTypeId() != 'YOUR

我正在编写一个自定义模块,其中添加了一个自定义产品类型。如何仅为该自定义产品类型编写观察者目录\u product\u save\u?

您不能为该类型的产品添加观察者,但可以在观察者中检查产品是否有效。如果没有,那就什么也不做

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

*\u save\u after
事件是从
Varien\u对象
类触发的,并且是动态的,具体取决于类。因此,对于所有产品类型来说,这将是相同的事件

您仍然可以在事件发生后观察目录\产品\保存\并根据产品类型执行操作:

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

}