I created a preference for the method _applyOptionsPrice()
in Magento/Catalog/Model/Product/Type/Price.php
class.
The preference is working while the _applyOptionsPrice()
was called from the same class but the Price.php class was inherited by two class.
They are :
Magento/Bundle/Model/Product/Price.php
Magento/ConfigurableProduct/Model/Product/Type/Configurable/Price.php
While the _applyOptionsPrice()
was called from the above two classes my preference method didn't worked.
I declared the preference in 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">
<preference for="Magento\Catalog\Model\Product\Type\Price" type="Vendor\Module\Preference\Price" />
</config>
and this is my preference class:
<?php
namespace Vendor\Module\Preference;
use Magento\Catalog\Api\Data\ProductTierPriceExtensionFactory;
use Magento\Catalog\Api\Data\ProductTierPriceInterfaceFactory;
use Magento\CatalogRule\Model\ResourceModel\RuleFactory;
use Magento\Customer\Api\GroupManagementInterface;
use Magento\Customer\Model\Session;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Event\ManagerInterface;
use Magento\Framework\Pricing\PriceCurrencyInterface;
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
use Magento\Store\Model\StoreManagerInterface;
class Price extends \Magento\Catalog\Model\Product\Type\Price
{
public function __construct(
RuleFactory $ruleFactory,
StoreManagerInterface $storeManager,
TimezoneInterface $localeDate,
Session $customerSession,
ManagerInterface $eventManager,
PriceCurrencyInterface $priceCurrency,
GroupManagementInterface $groupManagement,
ProductTierPriceInterfaceFactory $tierPriceFactory,
ScopeConfigInterface $config,
ProductTierPriceExtensionFactory $tierPriceExtensionFactory = null
)
{
parent::__construct(
$ruleFactory,
$storeManager,
$localeDate,
$customerSession,
$eventManager,
$priceCurrency,
$groupManagement,
$tierPriceFactory,
$config,
$tierPriceExtensionFactory
);
}
protected function _applyOptionsPrice($product, $qty, $finalPrice)
{
// Here is my custom code
}
}
"I found a same issue in plugin from this link"
Please give me a suggestion to solve this error!!