【问题标题】:Magento 2 Matrix rate Checkout Issue (Carrier with such method not found:matrixrate_5334)Magento 2 矩阵费率结帐问题(未找到使用这种方法的运营商:matrixrate_5334)
【发布时间】:2020-05-13 21:47:50
【问题描述】:

我到处寻找解决方案,目前没有任何结果。当客户付款并尝试处理订单时,我们面临运输方式问题,我们有一个错误“找不到这种方式的承运人:matrixrate_5334”并且运输方式消失,需要删除并再次创建购物车才能查看这些运输方式。

PHP 7.0 Magento 版本 2.2.1 Webshopp Matrixrates 最新版本 https://docs.shipperhq.com/troubleshooting-matrixrates/

有人可以帮忙吗?

Pop up issue on the website

【问题讨论】:

    标签: php mysql plugins magento2 shipping


    【解决方案1】:

    我注意到由于结帐会话报价 $this->getShippingMethod() 在计算运费时未正确设置/为空而发生此错误。

    magento/codepool/vendor/magento/module-quote/Model/Quote/Address.php
    public function requestShippingRates(AbstractItem $item = null)
    Line 1080: if ($this->getShippingMethod() == $rate->getCode()) {
    

    错误:

    {"message":"Carrier with such method not found: %1, %2","parameters":["matrixrate","matrixrate_2"]}
    

    解决方案:

    我可以通过覆盖 \WebShopApps\MatrixRate\Model\Carrier\Matrixrate collectRates() 方法并在结帐报价送货地址中设置送货方式来解决它。

    // set quote shipping method
    $shippingMethod = $method->getCarrier().'_'.$method->getMethod();
    $this->checkoutSession->getQuote()->getShippingAddress()->setShippingMethod($shippingMethod);
    

    =============================================

    Vendor/MatrixRate/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">
        <preference for="WebShopApps\MatrixRate\Model\Carrier\Matrixrate" type="Vendor\MatrixRate\Model\Carrier\Matrixrate"/>
    </config>
    

    覆盖Vendor\MatrixRate\Model\Carrier\Matrixrate.php

    \Magento\Checkout\Model\Session $checkoutSession 注入__construct

    public function collectRates(RateRequest $request)
        {
            if (!$this->getConfigFlag('active')) {
                return false;
            }
    
            // exclude Virtual products price from Package value if pre-configured
            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;
                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()) {
                        $freeShipping = is_numeric($item->getFreeShipping()) ? $item->getFreeShipping() : 0;
                        $freeQty += $item->getQty() - $freeShipping;
                        $freePackageValue += $item->getBaseRowTotal();
                    }
                }
                $oldValue = $request->getPackageValue();
                $request->setPackageValue($oldValue - $freePackageValue);
            }
    
            if (!$request->getConditionMRName()) {
                $conditionName = $this->getConfigData('condition_name');
                $request->setConditionMRName($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();
            $zipRange = $this->getConfigData('zip_range');
            $rateArray = $this->getRate($request, $zipRange);
    
            $request->setPackageWeight($oldWeight);
            $request->setPackageQty($oldQty);
    
            $foundRates = false;
    
            foreach ($rateArray as $rate) {
                if (!empty($rate) && $rate['price'] >= 0) {
                    /** @var \Magento\Quote\Model\Quote\Address\RateResult\Method $method */
                    $method = $this->resultMethodFactory->create();
    
                    $method->setCarrier('matrixrate');
                    $method->setCarrierTitle($this->getConfigData('title'));
    
                    $method->setMethod('matrixrate_' . $rate['pk']);
                    $method->setMethodTitle(__($rate['shipping_method']));
    
                    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);
                    $foundRates = true; // have found some valid rates
    
                    // set quote shipping method
                    $shippingMethod = $method->getCarrier().'_'.$method->getMethod();
                    $this->checkoutSession->getQuote()->getShippingAddress()->setShippingMethod($shippingMethod);
                }
            }
    
            if (!$foundRates) {
                /** @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;
        }
    

    仅供参考 - 可能的 M2 核心问题:

    干杯!

    【讨论】:

      猜你喜欢
      • 2014-09-23
      • 2011-09-28
      • 2014-06-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-11
      相关资源
      最近更新 更多