I want to show selected bundle options price in the summary block at right. By default, it only shows the selected option from the bundle product. Thanks.
Magento – Magento2: Show price on bundle option summary
bundled-productmagento2
Related Solutions
Magento has default feature of Bundle product price to show on the listing and product view page. It should be shown the min price on the listing page like, Starting at $5 or as low as $5, and on the product page, the user can see the full price as there is the bundle.
So finally I was able to achieve this, first we need a events.xml
For my requirement I needed this event observer for both frontend and adminhtml so the events.xml
was create at app/code/Foo/CustomPrice/etc/events.xml
.
<?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="foo_customprice_observer_set_price_for_item_add" instance="Foo\CustomPrice\Model\Observer\SetPriceForItem"/>
</event>
<!-- Event for update add to cart -->
<event name="checkout_cart_product_update_after">
<observer name="foo_customprice_observer_set_price_for_item_update" instance="Foo\CustomPrice\Model\Observer\SetPriceForItem"/>
</event>
</config>
After that need a observer at app/code/Foo/CustomPrice/Model/Observer/SetPriceForItem.php
<?php
namespace Foo\CustomPrice\Model\Observer;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\Catalog\Model\Product\Type;
class SetPriceForItem implements ObserverInterface
{
/**
* Add Special Price on add to cart.
*
* @param Observer $observer
* @return SetPriceForItem
*
*/
public function execute(Observer $observer)
{
/** @var $item \Magento\Quote\Model\Quote\Item */
$item = $observer->getEvent()->getQuoteItem();
if ($item->getProduct()->getTypeId() == Type::TYPE_BUNDLE) {
foreach ($item->getQuote()->getAllItems() as $bundleitems) {
/** @var $bundleitems\Magento\Quote\Model\Quote\Item */
//Skip the bundle product
if ($bundleitems->getProduct()->getTypeId() == Type::TYPE_BUNDLE) {
continue;
}
$bundleitems->setCustomPrice(1.00);
$bundleitems->setOriginalCustomPrice(1.00);
$bundleitems->getProduct()->setIsSuperMode(true);
}
$item->getProduct()->setIsSuperMode(true);
}
return $this;
}//end execute()
}
Best Answer
Able to add total summary for individual item selected on bundle product summary. Also, added currency symbol before price. Here is the solution https://github.com/magento/magento2/issues/7374#issuecomment-259978358