Magento 2 переопределяет табличную модель


У меня есть переопределенный класс модуля magento 2 tablerate. Ниже приведен файл переопределения Custom/Shipping/Model/Carrier/Tablerate.php

namespace Custom\Shipping\Model\Carrier;

use Magento\Quote\Model\Quote\Address\RateRequest;

class Tablerate extends \Magento\OfflineShipping\Model\Carrier\Tablerate
{
    public function collectRates(RateRequest $request)
    {
        if (!$this->getConfigFlag('active')) {
            return false;
        }
        if (!$this->getConfigFlag('include_virtual_price') && $request->getAllItems()) {
            foreach ($request->getAllItems() as $item) {
                if ($item->getParentItem()) {
                    continue;
                }
                if ($item->getHasChildren() && $item->isShipSeparately()) {
                    foreach ($item->getChildren() as $child) {
                        if ($child->getProduct()->isVirtual()) {
                            $request->setPackageValue($request->getPackageValue() - $child->getBaseRowTotal());
                        }
                    }
                } elseif ($item->getProduct()->isVirtual()) {
                    $request->setPackageValue($request->getPackageValue() - $item->getBaseRowTotal());
                }
            }
        }
        // Free shipping by qty
        $freeQty = 0;
        if ($request->getAllItems()) {
            $freePackageValue = 0;
            $customItemPrice = 0;
            $cartHasItems = false;
            $total=[];
            // exclude Virtual products price from Package value if pre-configured
            $i=0;
            foreach ($request->getAllItems() as $item) {
                if ($item->getProduct()->isVirtual() || $item->getParentItem()) {
                    continue;
                }
                $itemPrice = 0;
                $myItemPrice = 0;
                $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
                $product = $objectManager->create('Magento\Catalog\Model\Product')->load($item->getProductId());
                $total = $this->compareWeight($product, $total, $i, $item);
                $i++;
                if ($item->getHasChildren() && $item->isShipSeparately()) {
                    foreach ($item->getChildren() as $child) {
                        if ($child->getFreeShipping() && !$child->getProduct()->isVirtual()) {
                            $freeShipping = is_numeric($child->getFreeShipping()) ? $child->getFreeShipping() : 0;
                            $freeQty += $item->getQty() * ($child->getQty() - $freeShipping);
                        }
                    }
                } elseif ($item->getFreeShipping()) {
                    $freeShipping = is_numeric($item->getFreeShipping()) ? $item->getFreeShipping() : 0;
                    $freeQty += $item->getQty() - $freeShipping;
                    $freePackageValue += $item->getBaseRowTotal();
                }
            }
            $oldValue = $request->getPackageValue();
            $request->setPackageValue($oldValue - $freePackageValue);
        }
        if (!$request->getConditionName()) {
            $conditionName = $this->getConfigData('condition_name');
            $request->setConditionName($conditionName ? $conditionName : $this->_defaultConditionName);
        }
        // Package weight and qty free shipping
        $weight=$total;
        $oldWeight = $request->getPackageWeight();
        $oldQty = $request->getPackageQty();
        $rate_price=0;
        list($result, $rate) = $this->getFinalRateShip($request, $total, $oldQty, $freeQty, $rate_price);
        $oldWeight = $request->getPackageWeight();
        $oldQty = $request->getPackageQty();
        $request->setPackageWeight($request->getFreeMethodWeight());
        $request->setPackageQty($oldQty - $freeQty);
        /** @var \Magento\Shipping\Model\Rate\Result $result */
        $request->setPackageWeight($oldWeight);
        $request->setPackageQty($oldQty);
        if (!empty($rate) && $rate['price'] >= 0) {
            /** @var \Magento\Quote\Model\Quote\Address\RateResult\Method $method */
            $method = $this->_resultMethodFactory->create();
            $method->setCarrier('tablerate');
            $method->setCarrierTitle($this->getConfigData('title'));
            $method->setMethod('bestway');
            $method->setMethodTitle($this->getConfigData('name'));
            if ($request->getFreeShipping() === true || $request->getPackageQty() == $freeQty) {
                $shippingPrice = 0;
            } else {
                $shippingPrice = $this->getFinalPriceWithHandlingFee($rate['price']);
            }
            $method->setPrice($shippingPrice);
            $method->setCost($rate['cost']);
            $result->append($method);
        } else {
            /** @var \Magento\Quote\Model\Quote\Address\RateResult\Error $error */
            $error = $this->_rateErrorFactory->create(
                [
                    'data' => [
                        'carrier' => $this->_code,
                        'carrier_title' => $this->getConfigData('title'),
                        'error_message' => $this->getConfigData('specificerrmsg'),
                    ],
                ]
            );
            $result->append($error);
        }
        return $result;
    }

    /**
     * @param RateRequest $request
     * @param $total
     * @param $oldQty
     * @param $freeQty
     * @param $rate_price
     * @return array
     */
    public function getFinalRateShip(RateRequest $request, $total, $oldQty, $freeQty, $rate_price)
    {
        foreach ($total_dim as $value) {
            $request->setPackageWeight($value['w']);
            $request->setPackageQty($oldQty - $freeQty);
            $result = $this->_rateResultFactory->create();
            $rate = $this->getRate($request);
            $rate_price += $rate['price'] * $value['q'];
        }
        return [$result, $rate];
    }

    /**
     * @param $product
     * @param $total
     * @param $i
     * @param $item
     * @return mixed
     */
    public function compareWeight($product, $total, $i, $item)
    {

        $width = $product->getDimensionalWidth();
        $height = $product->getDimensionalHeight();
        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $WeightFactor= $objectManager->get('Magento\Framework\App\Config\ScopeConfigInterface')->getValue('customshipping/general/display_text');
        $ShippingStatus= $objectManager->get('Magento\Framework\App\Config\ScopeConfigInterface')->getValue('customshipping/general/enable');
        $dim = round(($width * $height) / $WeightFactor);        
        $total[$i]['w'] = $dim;
        $total[$i]['q'] = $item->getQty();
        return $total;

    }
}

Я хочу получить сведения о продукте по идентификатору и конфигурации системы без использования диспетчера объектов.

В настоящее время я использую

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
                $product = $objectManager->create('Magento\Catalog\Model\Product')->load($item->getProductId());

И

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $WeightFactor= $objectManager->get('Magento\Framework\App\Config\ScopeConfigInterface')->getValue('customshipping/general/display_text');
        $ShippingStatus= $objectManager->get('Magento\Framework\App\Config\ScopeConfigInterface')->getValue('customshipping/general/enable');

Что неверно. Когда я использую какой-либо продукт и конфигурацию системы, он всегда показывает мне ошибку в отношении конструкции.

Когда я использовал конструкция по умолчанию из класса скорости таблицы, то она всегда показывает мне ошибку аргумента 4.

Author: Pushpendra Singh, 2017-09-29

2 answers

НОВАЯ ПРОЦЕДУРА С ИСПОЛЬЗОВАНИЕМ ПЛАГИНА

Я настоятельно рекомендую использовать плагин вместо использования класса перезаписи.

Плагин наилучшим образом изменяет рейтинг перевозчика.

Мы должны создать плагин по методу collectRates(RateRequest $request) и использовать метод around в этом методе.

Класс плагина

<?php

namespace Devbera\Tablerate\Plugin\Magento\OfflineShipping\Model\Carrier;
use Magento\Framework\Exception\LocalizedException;
use Magento\Quote\Model\Quote\Address\RateRequest;

class TableratePlugin
{


    /**
     * @var \Magento\Catalog\Api\ProductRepositoryInterface
     */
    private $productRepository;

    /**
     * @var \Magento\Quote\Model\Quote\Address\RateResult\ErrorFactory
     */
    private $rateErrorFactory;

    /**
     * @var string
     */
    protected $_code = 'tablerate';
    /**
     * @var string
     */
    protected $_defaultConditionName = 'package_weight';

    /**
     * @var \Magento\Shipping\Model\Rate\ResultFactory
     */
    protected $_rateResultFactory;

    /**
     * @var \Magento\Quote\Model\Quote\Address\RateResult\MethodFactory
     */
    protected $_resultMethodFactory;
    
    public function __construct(
        \Magento\Shipping\Model\Rate\ResultFactory $rateResultFactory,
        \Magento\Quote\Model\Quote\Address\RateResult\MethodFactory $resultMethodFactory,
        \Magento\Quote\Model\Quote\Address\RateResult\ErrorFactory $rateErrorFactory,
        \Magento\Catalog\Api\ProductRepositoryInterface $productRepository       
    ){
        $this->_rateResultFactory = $rateResultFactory;
        $this->_resultMethodFactory = $resultMethodFactory;     
        $this->rateErrorFactory = $rateErrorFactory;
        $this->productRepository = $productRepository;
    }        
    public function aroundCollectRates(
        \Magento\OfflineShipping\Model\Carrier\Tablerate $subject,
        \Closure $proceed,
        RateRequest $request   
    ) {
        if (!$subject->getConfigFlag('active')) {
            return false;
        } 
        // exclude Virtual products price from Package value if pre-configured
        if (!$subject->getConfigFlag('include_virtual_price') && $request->getAllItems()) {
            foreach ($request->getAllItems() as $item) {
                if ($item->getParentItem()) {
                    continue;
                }
                if ($item->getHasChildren() && $item->isShipSeparately()) {
                    foreach ($item->getChildren() as $child) {
                        if ($child->getProduct()->isVirtual()) {
                            $request->setPackageValue($request->getPackageValue() - $child->getBaseRowTotal());
                        }
                    }
                } elseif ($item->getProduct()->isVirtual()) {
                    $request->setPackageValue($request->getPackageValue() - $item->getBaseRowTotal());
                }
            }
        } 
 
        // Free shipping by qty
        $freeQty = 0;
        $freePackageValue = 0;

        if ($request->getAllItems()) {
            foreach ($request->getAllItems() as $item) {
                if ($item->getProduct()->isVirtual() || $item->getParentItem()) {
                    continue;
                }

                if ($item->getHasChildren() && $item->isShipSeparately()) {
                    foreach ($item->getChildren() as $child) {
                        if ($child->getFreeShipping() && !$child->getProduct()->isVirtual()) {
                            $freeShipping = is_numeric($child->getFreeShipping()) ? $child->getFreeShipping() : 0;
                            $freeQty += $item->getQty() * ($child->getQty() - $freeShipping);
                        }
                    }
                } elseif ($item->getFreeShipping() || $item->getAddress()->getFreeShipping()) {
                    $freeShipping = $item->getFreeShipping() ?
                        $item->getFreeShipping() : $item->getAddress()->getFreeShipping();
                    $freeShipping = is_numeric($freeShipping) ? $freeShipping : 0;
                    $freeQty += $item->getQty() - $freeShipping;
                    $freePackageValue += $item->getBaseRowTotal();
                }
            }
            $oldValue = $request->getPackageValue();
            $request->setPackageValue($oldValue - $freePackageValue);
        }
 
        if (!$request->getConditionName()) {
            $conditionName = $subject->getConfigData('condition_name');
            $request->setConditionName($conditionName ? $conditionName : $this->_defaultConditionName);
        }

        // Package weight and qty free shipping
        $oldWeight = $request->getPackageWeight();
        $oldQty = $request->getPackageQty();

        $request->setPackageWeight($request->getFreeMethodWeight());
        $request->setPackageQty($oldQty - $freeQty);

        /** @var \Magento\Shipping\Model\Rate\Result $result */
        $result = $this->_rateResultFactory->create();
        $rate = $subject->getRate($request);

        $request->setPackageWeight($oldWeight);
        $request->setPackageQty($oldQty); 


        if (!empty($rate) && $rate['price'] >= 0) {
            if ($request->getPackageQty() == $freeQty) {
                $shippingPrice = 0;
            } else {
                $shippingPrice = $subject->getFinalPriceWithHandlingFee($rate['price']);
            }
            $method = $this->createShippingMethod($shippingPrice, $rate['cost'], $subject,$request);
            $result->append($method);
        } elseif ($request->getPackageQty() == $freeQty) {

            /**
             * Promotion rule was applied for the whole cart.
             *  In this case all other shipping methods could be omitted
             * Table rate shipping method with 0$ price must be shown if grand total is more than minimal value.
             * Free package weight has been already taken into account.
             */
            $request->setPackageValue($freePackageValue);
            $request->setPackageQty($freeQty);
            $rate = $subject->getRate($request);
            if (!empty($rate) && $rate['price'] >= 0) {
                $method = $this->createShippingMethod(0, 0, $subject,$request);
                $result->append($method);
            }
        } else {
            /** @var \Magento\Quote\Model\Quote\Address\RateResult\Error $error */
            $error = $this->rateErrorFactory->create(
                [
                    'data' => [
                        'carrier' => $this->_code,
                        'carrier_title' => $subject->getConfigData('title'),
                        'error_message' => $subject->getConfigData('specificerrmsg'),
                    ],
                ]
            );
            $result->append($error);
        }
       return $result;  
    }
    /**
     * Get the method object based on the shipping price and cost
     *
     * @param float $shippingPrice
     * @param float $cost
     * @return \Magento\Quote\Model\Quote\Address\RateResult\Method
     */
    private function createShippingMethod($shippingPrice, $cost, $subject,$request)
    {

        /** @var  \Magento\Quote\Model\Quote\Address\RateResult\Method $method */
        $method = $this->_resultMethodFactory->create();

        $method->setCarrier('tablerate');
        $method->setCarrierTitle($subject->getConfigData('title'));

        $method->setMethod('bestway');
        $method->setMethodTitle($subject->getConfigData('name'));

        $method->setPrice($shippingPrice);
        $method->setCost($cost);
        return $method;
    }    
}

СТАРАЯ ПРОЦЕДУРА

В magento2, если вы хотите переопределить класс, тогда предлагается скопировать весь код, то есть все функции , переменные из вашего класса предпочтений чтобы new class, then you need to modify in new class.

Как будто

<?php
namespace Custom\Shipping\Model\Carrier;
//namespace Magento\OfflineShipping\Model\Carrier;

use Magento\Framework\Exception\LocalizedException;
use Magento\Quote\Model\Quote\Address\RateRequest;

class Tablerate extends \Magento\Shipping\Model\Carrier\AbstractCarrier implements
    \Magento\Shipping\Model\Carrier\CarrierInterface
{
    /**
     * @var string
     */
    protected $_code = 'tablerate';

    /**
     * @var bool
     */
    protected $_isFixed = true;

    /**
     * @var string
     */
    protected $_defaultConditionName = 'package_weight';

    /**
     * @var array
     */
    protected $_conditionNames = [];

    /**
     * @var \Magento\Shipping\Model\Rate\ResultFactory
     */
    protected $_rateResultFactory;

    /**
     * @var \Magento\Quote\Model\Quote\Address\RateResult\MethodFactory
     */
    protected $_resultMethodFactory;

    /**
     * @var \Magento\OfflineShipping\Model\ResourceModel\Carrier\TablerateFactory
     */
    protected $_tablerateFactory;

    /**
     * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
     * @param \Magento\Quote\Model\Quote\Address\RateResult\ErrorFactory $rateErrorFactory
     * @param \Psr\Log\LoggerInterface $logger
     * @param \Magento\Shipping\Model\Rate\ResultFactory $rateResultFactory
     * @param \Magento\Quote\Model\Quote\Address\RateResult\MethodFactory $resultMethodFactory
     * @param \Magento\OfflineShipping\Model\ResourceModel\Carrier\TablerateFactory $tablerateFactory
     * @param array $data
     * @SuppressWarnings(PHPMD.UnusedLocalVariable)
     */
    public function __construct(
        \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
        \Magento\Quote\Model\Quote\Address\RateResult\ErrorFactory $rateErrorFactory,
        \Psr\Log\LoggerInterface $logger,
        \Magento\Shipping\Model\Rate\ResultFactory $rateResultFactory,
        \Magento\Quote\Model\Quote\Address\RateResult\MethodFactory $resultMethodFactory,
        \Magento\OfflineShipping\Model\ResourceModel\Carrier\TablerateFactory $tablerateFactory,
        array $data = []
    ) {
        $this->_rateResultFactory = $rateResultFactory;
        $this->_resultMethodFactory = $resultMethodFactory;
        $this->_tablerateFactory = $tablerateFactory;
        parent::__construct($scopeConfig, $rateErrorFactory, $logger, $data);
        foreach ($this->getCode('condition_name') as $k => $v) {
            $this->_conditionNames[] = $k;
        }
    }

    /**
     * @param RateRequest $request
     * @return \Magento\Shipping\Model\Rate\Result
     * @SuppressWarnings(PHPMD.CyclomaticComplexity)
     * @SuppressWarnings(PHPMD.NPathComplexity)
     * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
     */
   public function collectRates(RateRequest $request)
    {
        if (!$this->getConfigFlag('active')) {
            return false;
        }
        if (!$this->getConfigFlag('include_virtual_price') && $request->getAllItems()) {
            foreach ($request->getAllItems() as $item) {
                if ($item->getParentItem()) {
                    continue;
                }
                if ($item->getHasChildren() && $item->isShipSeparately()) {
                    foreach ($item->getChildren() as $child) {
                        if ($child->getProduct()->isVirtual()) {
                            $request->setPackageValue($request->getPackageValue() - $child->getBaseRowTotal());
                        }
                    }
                } elseif ($item->getProduct()->isVirtual()) {
                    $request->setPackageValue($request->getPackageValue() - $item->getBaseRowTotal());
                }
            }
        }
        // Free shipping by qty
        $freeQty = 0;
        if ($request->getAllItems()) {
            $freePackageValue = 0;
            $customItemPrice = 0;
            $cartHasItems = false;
            $total=[];
            // exclude Virtual products price from Package value if pre-configured
            $i=0;
            foreach ($request->getAllItems() as $item) {
                if ($item->getProduct()->isVirtual() || $item->getParentItem()) {
                    continue;
                }
                $itemPrice = 0;
                $myItemPrice = 0;
                $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
                $product = $objectManager->create('Magento\Catalog\Model\Product')->load($item->getProductId());
                $total = $this->compareWeight($product, $total, $i, $item);
                $i++;
                if ($item->getHasChildren() && $item->isShipSeparately()) {
                    foreach ($item->getChildren() as $child) {
                        if ($child->getFreeShipping() && !$child->getProduct()->isVirtual()) {
                            $freeShipping = is_numeric($child->getFreeShipping()) ? $child->getFreeShipping() : 0;
                            $freeQty += $item->getQty() * ($child->getQty() - $freeShipping);
                        }
                    }
                } elseif ($item->getFreeShipping()) {
                    $freeShipping = is_numeric($item->getFreeShipping()) ? $item->getFreeShipping() : 0;
                    $freeQty += $item->getQty() - $freeShipping;
                    $freePackageValue += $item->getBaseRowTotal();
                }
            }
            $oldValue = $request->getPackageValue();
            $request->setPackageValue($oldValue - $freePackageValue);
        }
        if (!$request->getConditionName()) {
            $conditionName = $this->getConfigData('condition_name');
            $request->setConditionName($conditionName ? $conditionName : $this->_defaultConditionName);
        }
        // Package weight and qty free shipping
        $weight=$total;
        $oldWeight = $request->getPackageWeight();
        $oldQty = $request->getPackageQty();
        $rate_price=0;
        list($result, $rate) = $this->getFinalRateShip($request, $total, $oldQty, $freeQty, $rate_price);
        $oldWeight = $request->getPackageWeight();
        $oldQty = $request->getPackageQty();
        $request->setPackageWeight($request->getFreeMethodWeight());
        $request->setPackageQty($oldQty - $freeQty);
        /** @var \Magento\Shipping\Model\Rate\Result $result */
        $request->setPackageWeight($oldWeight);
        $request->setPackageQty($oldQty);
        if (!empty($rate) && $rate['price'] >= 0) {
            /** @var \Magento\Quote\Model\Quote\Address\RateResult\Method $method */
            $method = $this->_resultMethodFactory->create();
            $method->setCarrier('tablerate');
            $method->setCarrierTitle($this->getConfigData('title'));
            $method->setMethod('bestway');
            $method->setMethodTitle($this->getConfigData('name'));
            if ($request->getFreeShipping() === true || $request->getPackageQty() == $freeQty) {
                $shippingPrice = 0;
            } else {
                $shippingPrice = $this->getFinalPriceWithHandlingFee($rate['price']);
            }
            $method->setPrice($shippingPrice);
            $method->setCost($rate['cost']);
            $result->append($method);
        } else {
            /** @var \Magento\Quote\Model\Quote\Address\RateResult\Error $error */
            $error = $this->_rateErrorFactory->create(
                [
                    'data' => [
                        'carrier' => $this->_code,
                        'carrier_title' => $this->getConfigData('title'),
                        'error_message' => $this->getConfigData('specificerrmsg'),
                    ],
                ]
            );
            $result->append($error);
        }
        return $result;
    }
    /**
     * @param \Magento\Quote\Model\Quote\Address\RateRequest $request
     * @return array|bool
     */
    public function getRate(\Magento\Quote\Model\Quote\Address\RateRequest $request)
    {
        return $this->_tablerateFactory->create()->getRate($request);
    }

    /**
     * @param string $type
     * @param string $code
     * @return array
     * @throws \Magento\Framework\Exception\LocalizedException
     */
    public function getCode($type, $code = '')
    {
        $codes = [
            'condition_name' => [
                'package_weight' => __('Weight vs. Destination'),
                'package_value' => __('Price vs. Destination'),
                'package_qty' => __('# of Items vs. Destination'),
            ],
            'condition_name_short' => [
                'package_weight' => __('Weight (and above)'),
                'package_value' => __('Order Subtotal (and above)'),
                'package_qty' => __('# of Items (and above)'),
            ],
        ];

        if (!isset($codes[$type])) {
            throw new LocalizedException(__('Please correct Table Rate code type: %1.', $type));
        }

        if ('' === $code) {
            return $codes[$type];
        }

        if (!isset($codes[$type][$code])) {
            throw new LocalizedException(__('Please correct Table Rate code for type %1: %2.', $type, $code));
        }

        return $codes[$type][$code];
    }

    /**
     * Get allowed shipping methods
     *
     * @return array
     */
    public function getAllowedMethods()
    {
        return ['bestway' => $this->getConfigData('name')];
    }
      public function getFinalRateShip(RateRequest $request, $total, $oldQty, $freeQty, $rate_price)
    {
        foreach ($total_dim as $value) {
            $request->setPackageWeight($value['w']);
            $request->setPackageQty($oldQty - $freeQty);
            $result = $this->_rateResultFactory->create();
            $rate = $this->getRate($request);
            $rate_price += $rate['price'] * $value['q'];
        }
        return [$result, $rate];
    }

    /**
     * @param $product
     * @param $total
     * @param $i
     * @param $item
     * @return mixed
     */
    public function compareWeight($product, $total, $i, $item)
    {

        $width = $product->getDimensionalWidth();
        $height = $product->getDimensionalHeight();
        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $WeightFactor= $objectManager->get('Magento\Framework\App\Config\ScopeConfigInterface')->getValue('customshipping/general/display_text');
        $ShippingStatus= $objectManager->get('Magento\Framework\App\Config\ScopeConfigInterface')->getValue('customshipping/general/enable');
        $dim = round(($width * $height) / $WeightFactor);        
        $total[$i]['w'] = $dim;
        $total[$i]['q'] = $item->getQty();
        return $total;

    }
}
 2
Author: Amit Bera, 2020-06-15 08:30:17

Вы можете добавить ScopeConfigInterface в конструктор, после этого вы захотите очистить var/generation:

protected $config;

public function __construct(
    \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
    \Magento\Quote\Model\Quote\Address\RateResult\ErrorFactory $rateErrorFactory,
    \Psr\Log\LoggerInterface $logger,
    \Magento\Shipping\Model\Rate\ResultFactory $rateResultFactory,
    \Magento\Quote\Model\Quote\Address\RateResult\MethodFactory $resultMethodFactory,
    \Magento\OfflineShipping\Model\ResourceModel\Carrier\TablerateFactory $tablerateFactory,
    \Magento\Framework\App\Config\ScopeConfigInterface $config,
    array $data = []
) {
    parent::__construct($scopeConfig, $rateErrorFactory, $logger,
        $rateResultFactory, $resultMethodFactory, $tablerateFactory, $data);
    $this->config = $config;
}

Теперь вы можете изменить

$objectManager->get('Magento\Framework\App\Config\ScopeConfigInterface')->getValue('config/value/path');

До

$this->config->getValue('config/value/path');

Не должно быть необходимости в:

$objectManager->create('Magento\Catalog\Model\Product')->load($item->getProductId());

Потому что $item должен быть экземпляром \Magento\Quote\Model\Quote\Address\Item, у которого есть метод getProduct.

Если по какой-то причине это не работает, вам следует добавить Magento\Catalog\Api\ProductRepositoryInterface в свой конструктор для загрузки объекта данных продукта.

 0
Author: Pmclain, 2018-12-28 14:02:48