Let’s initiate a discussion!!
Step 1: First you need to add di.xml in the following path:
app/code/Magemonkey/PriceAdjustment/etc/frontend
Now add the below code:
1 2 3 4 |
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <preference for="Magento\Tax\Observer\UpdateProductOptionsObserver" type="Magemonkey\PriceAdjustment\Observer\UpdateProductOptionsObserver" /> </config> |
Step 2: Next, you need to add module.xml file in the following path:
app/code/Magemonkey/PriceAdjustment/etc
Add the below code:
1 2 3 4 5 6 7 8 |
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd"> <module name="Magemonkey_PriceAdjustment" setup_version="1.0.0"> <sequence> <module name="Magento_Tax"/> </sequence> </module> </config> |
Step 3: Now you need to add registration.php file in the following path:
app/code/Magemonkey/PriceAdjustment
Add the below code:
1 2 3 4 5 6 |
<?php \Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE, 'Magemonkey_PriceAdjustment', __DIR__ ); |
Step 4: Lastly, you need to add the UpdateProductOptionsObserver.php file in the following path:
app/code/Magemonkey/PriceAdjustment/Observer
And add the below code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
<?php namespace Magemonkey\PriceAdjustment\Observer; use Magento\Framework\Event\ObserverInterface; class UpdateProductOptionsObserver extends \Magento\Tax\Observer\UpdateProductOptionsObserver { /** * Tax data * * @var \Magento\Tax\Helper\Data */ protected $taxData; /** * @var \Magento\Framework\Registry */ protected $registry; /** * @param \Magento\Tax\Helper\Data $taxData * @param \Magento\Framework\Registry $registry */ public function __construct( \Magento\Tax\Helper\Data $taxData, \Magento\Framework\Registry $registry ) { $this->taxData = $taxData; $this->registry = $registry; } /** * Change default JavaScript templates for options rendering * * @param \Magento\Framework\Event\Observer $observer * @return $this */ public function execute(\Magento\Framework\Event\Observer $observer) { $response = $observer->getEvent()->getResponseObject(); $options = $response->getAdditionalOptions(); $_product = $this->registry->registry('current_product'); if (!$_product) { return $this; } $algorithm = $this->taxData->getCalculationAlgorithm(); $options['calculationAlgorithm'] = $algorithm; // prepare correct template for options render if ($this->taxData->displayBothPrices()) { $options['optionTemplate'] = sprintf( '<%%= data.label %%>' . '<%% if (data.finalPrice.value) { %%>' . ' +<%%= data.basePrice.formatted %%> (%1$s <%%= data.finalPrice.formatted %%>)' . '<%% } %%>', __('Incl. tax:') ); } elseif ($this->taxData->priceIncludesTax() && $this->taxData->displayPriceExcludingTax()) { $options['optionTemplate'] = sprintf( '<%%= data.label %%>' . '<%% if (data.basePrice.value) { %%>' . ' +<%%= data.basePrice.formatted %%>' . '<%% } %%>' ); } $response->setAdditionalOptions($options); return $this; } } |
The search box is the most underrated functionality that is...
Managing and customizing Magento site can be a daunting task,...
Having an in-house eCommerce developer is very costly, and it...
Have you wonder why your conversions are less compare to...
According to a research, around 68% of eCommerce stores are...
Let our Magento expert connect to discuss your requirement.
We offer Magento
certified developers.
Our Magento clientele
is 500+.
We sign NDA for the
security of your projects.
We’ve performed 100+
Magento migration projects.
Free quotation
on your project.
Three months warranty on
code developed by us.