- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2017
02:39 AM
07-27-2017
02:39 AM
Magento 2 - custom price can not add to subtotal and grand total after add to cart
I want to add custom price for bundle products after adding to cart. I have used "checkout_cart_product_add_after" observer to do so. But it is adding custom price to product price, not in sub total and grand total.
Following is my 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 for add to 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() as $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 anyone who can help me? Price is not adding to subtotal and
grand total.
Following is the cart item, subtotal and grand total.
1 REPLY 1
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2017
05:49 AM
08-17-2017
05:49 AM
Re: Magento 2 - custom price can not add to subtotal and grand total after add to cart
Please check this post from stackoverflow
https://magento.stackexchange.com/questions/92774/how-to-add-fee-to-order-totals-in-magento2
Suman Kar(suman.jis@gmail.com) Magento Certified Developer Plus Skype: sumanphptech Problem solved? Please give 'Kudos' and accept 'Answer as Solution'.