I'm trying to update/override the product price using the code below.
frontend/di.xml file
<?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\Model\Product">
<plugin name="change_product" type="ABCSolutions\ProductTab\Plugin\Model\Product" sortOrder="1" />
</type>
</config>
And the Product.php file code
<?php
namespace ABCSolutions\ProductTab\Plugin\Model;
class Product
{
public function afterGetPrice(\Magento\Catalog\Model\Product $subject, $result)
{
if($subject->getSku() == 'B2BTest'){
$result += 10;
}
return $result;
}
}
It is applied when the product does not have Tier Prices as shown below. The product cost is 10 and I added 10 so it is 20.
But when configuring tier prices, Magento overrides the price to show as tier price as the final price. In this case, the above code is not working.
So, I tried to override the \Magento\Catalog\Pricing\Render\FinalPriceBox
class of wrapResult()
method. When I debug the code the calculation is already done somewhere.
So, which file should override to calculate and apply or apply custom price?
I customized the afterGetPrice
method and set the price based on the BC API call. And this is working without tier
and special
price. So which method should we override to set the custom price if tier
and special
prices are configured?
We are using this logic/setting price for only the product page, not for any other pages. So, we believe it will not cause any issues.