I have a
checkout_cart_product_add_after event that calls to a observer file in which i want to check a condition. If that condition is false i block the product from adding to the cart and want to return a error message to the frontend.
I'm using this code if the condition is true:
$this->_messageManager->addError(__('your custom message')); //set false if you not want to add product to cart $observer->getRequest()->setParam('product', false); return $this;
but if i do that i get a console error 500 with an error: jQuery.parseJSON requires a valid JSON string.
And the add button to cart button stays on adding...
How can i block the product from adding to the cart but the button also refreshes?