1

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 :

  1. Magento/Bundle/Model/Product/Price.php
  2. 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!!

2
  • Did you mean a Plugin or a Preference? Can you put the code that you use to declare your Preference/Plugin and the class where you override this method? – cnbandicoot Sep 8 '20 at 7:07
  • @cnbandicoot I mean Preference. Please find the updated question – Siranjeevi K S Sep 9 '20 at 4:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.