I am working on Magento 2 and having issue with price.
I want to customise the product price. I did it via plugin and it's working fine on product page and list page.
As we are using a plugin, it is not overriding the price in collection with custom price. Due to this price filter is also not working according to updated product price. As we are using price slider-Min - Max price is also not correct.
I have debugged a lot and here is my findings
Min-max price is calculating from product collection by using following methods.
$productCollection->getMinPrice();
$productCollection->getMaxPrice();
Product collections we are getting on product list page is not including the customised price. I think, if we set customised price to product collection then price thing will work fine.
Here is plugin which I am using to customise price.
1.etc/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Catalog\Pricing\Price\RegularPrice">
<plugin name="product_price_change"
type="Namespace\Modulename\Plugin\Updateprice"
sortOrder="1"/>
</type>
</config>
2.Plugin/Updateprice.php
<?php
namespace Namespace\Modulename\Plugin;
class Updateprice
{
public function afterGetValue(\Magento\Catalog\Pricing\Price\RegularPrice $subject, $result) {
return $result + $myCustomPriceCharges;
}
}
Any suggestion would be appreciated. Thanks