I have work on the task in which I need to handle quote item, here I have use two event
checkout_cart_add_product_complete
checkout_cart_update_item_complete
here it work fine, But when I have change Quantity directly in mini cart then my Logic was not work. For this I am find some event which work for me. If You have any solution this Pleas Provide Me
my code is
<event name="checkout_cart_add_product_complete">
<observer name="customprice" instance="Ns\Module\Observer\CustomPrice" />
</event>
<event name="checkout_cart_update_item_complete">
<observer name="custompriceupdate" instance="Ns\Module\Observer\CustomPrice" />
</event>
<event name="sales_quote_item_qty_set_after">
<observer name="custompriceupdateqty" instance="Ns\Module\Observer\CustomPrice" />
</event>
and observer is
public function execute(\Magento\Framework\Event\Observer $observer)
{
$cart = $this->cart;
$quote = $cart->getQuote();
$items = $cart->getQuote()->getAllItems();
$basetotal = 0;
foreach ($items as $itemforprice) {
$total = $this->processItem($itemforprice);
$basetotal += $total;
}
$quote->setSubtotal($basetotal);
$quote->setGrandTotal($basetotal);
$quote->setBaseSubtotal($basetotal);
$quote->setBaseGrandTotal($basetotal);
$quote->setSubtotalWithDiscount($basetotal);
$quote->setBaseSubtotalWithDiscount($basetotal);
$quote->save();
}
private function processItem($itemforprice)
{
$myprice = 100;
$total = $myprice * $qty;
$itemforprice->setCustomPrice($myprice);
$itemforprice->setOriginalCustomPrice($myprice);
$itemforprice->setBasePrice($myprice);
$itemforprice->setPrice($myprice);
$itemforprice->setRowTotal($total);
$itemforprice->setBaseRowTotal($total);
$itemforprice->setRowTotalInclTax($total);
$itemforprice->setBaseRowTotalInclTax($total);
$itemforprice->save();
return $total;
}