How can I create a validation during the add to cart process and return it to the same page with an error message if the validation fails?

1 Answer 1


You can use event checkout_cart_product_add_after

$quoteItem = $observer->getEvent()->getQuoteItem();
$product = $observer->getEvent()->getProduct();

// you can check your condition here and if it fails remove item from cart and throw exception.

Mage::throwException('Your error message');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.