Skip to content

Minicart QTY & Total not updated, after remove item programmatically from RequisitionListManagement Plugin

Created the following plugin of RequisitionList list:

<type name="MagentoRequisitionListModelRequisitionListManagement">

After add item to Requisition-list, require to remove one item from quote, based on condition, but with the remove item process facing issue during the merge quote, after removed particular item programmatically, minicart QTY count & total not updated.
enter image description here

Tried following ways to remove quote item:

 1) $this->cart->removeItem($itemId)->save(); => With this item not
 removed, after refresh cart page 2 / 3 times, item will remove and
 minicart updated.
 
 2) $this->cartItemRepository->deleteById($quoteId, $itemId); => With
 this item not removed, after refresh cart page 2 / 3 times, item will
 remove and minicart updated.
 
 3) $quoteItem = $this->quoteItem->load($itemId);
                 $quoteItem->delete();
     => With this item remove properly, but minicart total & qty not updated.
 
 
 public function afterPlaceItemsInCart(MagentoRequisitionListModelRequisitionListManagement $subject, $result)
    {
      $quote = $this->_checkoutSession->getQuote();
      $productSku = 'XYZ'; //Fetched dynamically
       foreach ($quote->getAllItems() as $item) {
            $product = $this->productRepository->get($itemSku);
            $finalPrice = $product->getFinalPrice();
            $totalFinalPrice += $finalPrice * $item->getQty();
            if ($itemSku === $productSku) {
                $isExist = 1;
            }
        }
    //Quote item remove process, based on condition
    if ($totalFinalPrice > 150 && $isExist) {
     $itemId = 10; // Fetched dynamically 
     $quoteItem = $this->quoteItem->load($itemId);
     $quoteItem->delete();
    }
    $quote->collectTotals()->save();

   return $result;
  }

NOTE: section reload not working, even after page refresh QTY & total not updated

Tried:

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

This issue is happen only during merge / replace process from Req. list.

Thanks in advance.