1

I see my mini cart not updating its items when I delete an item from the cart programmatically.

but the cart updating perfectly as per my requirement only after I added a new item into cart or any cart event-triggered non programmatically.

0

1 Answer 1

2

You can fix this issue by creating a file app\code\Vendor\Extension\etc\frontend\section.xml using following code inside your extension folder.

<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Customer:etc/sections.xsd"> <action name="extension/controller/action"> <section name="cart"/> </action> </config> 

In this action parameter name, you have to pass the full action (For ex. checkout/cart/add ) in which cart is updated. It means you programmatically delete or add a product to cart to the shopping cart.

Also, you can add below code in your observer to refresh the quote for the customer.

$quote = $this->quoteRepository->get($quoteId); $quote->setCustomerId($customer->getId()); // Whatever you want to update $this->quoteRepository->save($quote); 

Reference: how to refresh mini cart programmatically in magento2

Hope it helps!!!

4
  • "You have to pass the full action (Forex. checkout/cart/add ) "I don't understand this point. which path i have to place here? Commented Sep 21, 2019 at 10:41
  • This is for controller action. Commented Sep 21, 2019 at 11:32
  • Have you tried it @SanjunDev? Commented Sep 26, 2019 at 11:00
  • 1
    No! it is just hold. anyway it seems to be work. Commented Sep 26, 2019 at 11:19

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.