0
votes

The prices of our website depend on a webservice that get the prices from an external database. Sometimes this process fails and set the product price to '0'.

I want to design an observer that stops the adding to cart process of this product.

I know how to «observe» the event with the checkout_cart_product_add_after (the 'before' one seems to not work at all) observer. What I don't know is how to stop the adding to cart process.

With this observer I can check the product ID and then remove it from the cart. But this is executed before the product is added, so unless the consumer adds the product again, it's useless. How can I then stop the process?

Thank

1
The checkout_cart_add_product_complete observer doesn't work either, it seems to act before the product is on the cart. - PauGNU
OK. I've just found out that it's easier than I thought. The checkout_cart_product_add_after observer is acting before the product is added to the cart. So I just need to check the product price and redirect the customer to the product page. - PauGNU

1 Answers

2
votes

throw an exception in your observer's method:

Mage::throwException(Mage::helper('yourmodule')->__('An error has ocurred.'));

HTH