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
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!
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.