1

Magento2 I am programmatiacally removing cart items.

$quoteItems = $this->checkoutSession->getQuote()->getItemsCollection();
            foreach($quoteItems as $item)
            {
                $cart->removeItem($item->getId())->save(); 
            }

My issue is mini cart counter is not getting updated

It just gets reduced by 1. Lets say if I have 3 items it will get reduced by 1 & change to 2.

I have already tried

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Customer:etc/sections.xsd">
    <action name="inquiry/index/save">
        <section name="cart"/>
    </action>
</config>

And this

var sections = ['cart'];
customerData.reload(sections, true);
8

1 Answer 1

3

Try this code

$quoteItems = $this->checkoutSession->getQuote()->getItemsCollection();
    foreach($quoteItems as $item)
    {
        $cart->removeItem($item->getId()); 
    }

    $cart->save();
    
    //or use this 
    //$cart->save()->getQuote()->collectTotals()
0

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.