0

For certain reason, i have to prevent the users to add the product into the cart.

here is the event in config.xml

<events>
    <controller_action_predispatch_checkout_cart_add>
        <observers>
            <abc_findp>
                <type>model</type>
                <class>Abc_Findp_Model_Observer</class>
                <method>searchStock</method>
            </abc_findp>
        </observers>
    </controller_action_predispatch_checkout_cart_add>
</events>

Observer:

public function searchStock($observer) {

    //how to prevent a product be added to a cart?
    Mage::getSingleton('core/session')->addNotice('This product can't be added to shopping cart.');



} 

Or i need to use checkout_cart_product_add_after event, to remove the quote item after added into a cart?

Thanks.!

2
  • just remove cart button simple Jan 28, 2017 at 6:30
  • Or set as out of stock.
    – ProxiBlue
    Jan 28, 2017 at 6:42

1 Answer 1

2

this is so funny method to solve the problem.

change to use checkout_cart_product_add_after and use in observer method

public function removeMessage ($observer) {
    $observer->_getSession()->getMessages(true);
}

this will prevent the product to be added into the cart and avoid the success message

1
  • Sometimes I don't have the method _getSession in the observer. Sep 26, 2017 at 0:19

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.