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
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.
$quoteItem->getQuote()->removeItem($quoteItem->getId());
Mage::throwException('Your error message');