Now add and remove products are taking place via ajax. But when the product is out of stock I want to remove the proceed to checkout button via ajax.

Once that out of stock product has been removed from cart, proceed to checkout button should be displayed again.

public function deleteAction()
        if ($this->getRequest()->isXmlHttpRequest()) {
            $itemId = (int) $this->getRequest()->getParam('id');
            $msg = '';
            if ($itemId) {
                try {
                    $msg = $this->__('Item was removed successfully.');
                } catch (Exception $e) {
                    $msg = $this->__('Cannot remove the item.');
                    // $this->_getSession()->addError($this->__('Cannot remove the item.'));
            $layout = $this->getLayout();
            $update = $layout->getUpdate();

            $minicartHtml = $layout->getOutput();
            $cartHtml = $layout->getOutput();
            $result = array('minicartHtml' => $minicartHtml,'cartHtml' => $cartHtml,'msg' => $msg);
        } else {
  • which extension,you have using?
    – Amit Bera
    Commented Oct 17, 2015 at 14:05
  • Its custom code @Amit
    – Swetha
    Commented Oct 17, 2015 at 14:24
  • I have added my delete action kindly refer
    – Swetha
    Commented Oct 17, 2015 at 14:25

1 Answer 1


I believe "proceed to checkout" button is getting removed when you have an error in your cart items(May happen when item goes out-of-stock).

During ajax update the checkout session is not updated with the Error flag which leads to this problem. There is an Error Flag check on the cart.phtml page. You can see a code like this <?php if(!$this->hasError()): ?> <ul class="checkout-types"> ..... </ul> <?php endif; ?>

The Flag is set on Mage_CatalogInventory_Model_Stock_Item::checkQuoteItemQty() so what happens is the error flag will be updated only when you refresh the page.


You need to update the Error flag in your controller BEFORE Generating your Blocks.

//get all cart items and check for errors. $cartItems = Mage::getSingleton('checkout/cart')->getQuote()->getAllVisibleItems(); $checkoutSession = Mage::getSingleton('checkout/session'); foreach ($cartItems as $item) { if ($checkoutSession) { $baseMessages = $item->getMessage(false); if ($baseMessages) { foreach ($baseMessages as $message) { $messages[] = array( 'text' => $message, 'type' => $item->getHasError() ? 'error' : 'notice' ); } } /* @var $collection Mage_Core_Model_Message_Collection */ $collection = $checkoutSession->getQuoteItemMessages($item->getId(), true); if ($collection) { $additionalMessages = $collection->getItems(); foreach ($additionalMessages as $message) { /* @var $message Mage_Core_Model_Message_Abstract */ $messages[] = array( 'text' => $message->getCode(), 'type' => ($message->getType() == Mage_Core_Model_Message::ERROR) ? 'error' : 'notice' ); } } } } $errMsgCount = count($messages, COUNT_RECURSIVE); //update checkout/session to show checkout button if no error if(!$errMsgCount){ $checkoutSession->getQuote()->setHasError(FALSE); }

Place the above code in your controller action before generating blocks.

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.