Integrity constraint violation in Magento custom module

前端 未结 2 2059
挽巷
挽巷 2020-12-09 14:05

I have a similar probelm to Integrity constraint violation creating Product in Magento (unanswered) but I am creating a custom Observer that hooks into the catalog_product_s

相关标签:
2条回答
  • 2020-12-09 14:25

    In this case, I'd recommend not using the catalog_product_save_after event. Instead, try using catalog_product_prepare_save which is fired after the POST data is applied to the product, but before ->save() is called. That way you don't have to mess with with saving or that ugly $_singletonFlag!

    Also, with catalog_product_prepare_save you get the HTTP Request object inside the Observer Event. No need for Mage::app()->getRequest(). Woot!

    0 讨论(0)
  • 2020-12-09 14:47

    Instead of using $product->save() try using the resource model, a la $product->getResource()->save($product).

    The reason being $product->save() will re-trigger all save events, hence running whatever is saving the cataloginventory_stock and throwing the error.

    0 讨论(0)
提交回复
热议问题