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.!

  • just remove cart button simple – Gopal Patel Jan 28 '17 at 6:30
  • Or set as out of stock. – ProxiBlue Jan 28 '17 at 6:42
1

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

  • Sometimes I don't have the method _getSession in the observer. – Ricardo Martins Sep 26 '17 at 0:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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