Magento – Disable checkout button in cart

checkoutmagento-1.8quote

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?

Best Answer

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.