2

I have added an error in the sales_quote_save_before event, if the quantity of items is more than 500.

> Mage::getSingleton('checkout/session')->addError(Mage::helper('checkout')->__('The maximum order qty is %d', 500));

The error appears in the cart, but still I can go further to the checkout and place the order. How can I disable the Proceed to Checkout button?

3 Answers 3

5

You can disable the checkout button by adding the following to the quote object (in the event your use for your observer sales_quote_save_before):

$quote->setHasError(true);
$quote->addErrorInfo(
    'error',
    'checkout',
    null,
    Mage::helper('checkout')->__('The maximum order qty is %d', 500),
    null
);

This will display the error message in the cart and remove the buttons. This solution is also used by the catalog_inventory module when a product qty is over the available qty.

0

you could create an if statement that checks the qty is below the required value. The 'Proceed to Checkout' link comes from this file.

  app/design/frontend/base/default/template/checkout/onepage/link.phtml

This question has a lot of details on checking individual product quantities in the cart. https://stackoverflow.com/questions/8296719/magento-get-the-quantity-in-cart-for-a-given-product

0

If you want something without fiddling with your core code then i think its better to observe the proceed to checkout event ( if you are using onepagechekout that will be <controller_action_predispatch_checkout_onepage_index> ) and then checking if the quantity constraints are not met then you can set the error there and use the below code to reload to cart itself

$url = Mage::getUrl('checkout/cart'); Mage::app()->getResponse()
->setRedirect($url) ->sendResponse();
3
  • ok i think that's the best solution anymore. i checked how magento handles it with the minimum amount value you can configure in the default magento settings. That's more or less static code in the controller actions. If i would like to do it like that, i would have to rewrite a lot of controllers and blocks. Thank you!
    – barannd
    Commented Aug 20, 2014 at 11:21
  • for completeness sake: It's <controller_action_predispatch_checkout_onepage_index>
    – barannd
    Commented Aug 20, 2014 at 11:33
  • Edited. I had to implement the same thing and i used <controller_action_predispatch_onepagecheckout_index> should be because i have installed a onepagecheckout plugin. I guess!
    – John
    Commented Aug 20, 2014 at 11:59

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.