I have a function that removes all of a product from the cart.

public function removeFromCartByProductIdAction()
    $productIdToRemove = $this->getRequest()->getParam('productIdToRemove');
    $cartHelper = Mage::helper('checkout/cart');
    $items = $cartHelper->getCart()->getItems();
    foreach ($items as $item) {
        if ($item->getProduct()->getId() == $productIdToRemove) {
            $itemId = $item->getItemId();

If I had 4 of the product in the cart, it will remove all 4 from the cart. But the function getSummaryCount provided by Magento Mage/Checkout/Block/Cart/Minicart.php will return 3. This persists until I visit the cart page, after which it will return the correct amount of 0.

I use the result of getSummaryCount to preview how many items are in the cart on my cart icon. How can I ensure it gets the correct summary count after I run my function?

1 Answer 1


I did not find the root cause, but was able to fix it with a workaround by going into my theme, finding the mini_cart.phtml file, and making this change.

<?php $_cartQty = $this->getSummaryCount() ?>
<?php $_items = $this->getRecentItems(); ?>  


<?php $_items = $this->getRecentItems(); ?>  
<?php $_cartQty = count($_items); ?>

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.