php - Magento 2 - custom price can not add to subtotal and grand total after add to cart -
i want add custom price bundle products after adding cart. have used "checkout_cart_product_add_after" observer so. adding custom price product price, not in sub total , grand total. following code:
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:nonamespaceschemalocation="urn:magento:framework:event/etc/events.xsd"> <!-- event add cart --> <event name="checkout_cart_product_add_after"> <observer name="customprice_observer_set_price_for_item_add" instance="custom\shop\model\observer\setpriceforitem"/> </event> </config>
observer class:
namespace custom\shop\model\observer; use magento\framework\event\observer; use magento\framework\event\observerinterface; use magento\catalog\model\product\type; class setpriceforitem implements observerinterface { public function execute(observer $observer) { $item = $observer->getevent()->getquoteitem(); if ($item->getproduct()->gettypeid() == type::type_bundle) { foreach ($item->getquote()->getallitems() $bundleitems) { if ($bundleitems->getproduct()->gettypeid() == type::type_bundle) { $bundle_price = $bundleitems->getproduct()->getfinalprice(); $fee = $bundleitems->getproduct()->getbuildinfee(); $final_price = $bundle_price + $fee; $bundleitems->setcustomprice($final_price); $bundleitems->setoriginalcustomprice($final_price); } } $item->getproduct()->setissupermode(true); } return $this; } }
is there can me? price not adding subtotal , grand total.
following cart item, subtotal , grand total.
any help???
Comments
Post a Comment