我已经到处搜索以找到没有任何结果的解决方案。当客户付款并尝试处理订单时,我们面临着运输方法的问题,我们遇到一个错误“找不到使用这种方法的运输公司:matrixrate_5334”,并且运输方法消失了,需要再次移除并创建购物车才能查看这些运输方法。
Php 7.0 Magento 2.2.1版 Webshopp Matrixrates最新版本 https://docs.shipperhq.com/troubleshooting-matrixrates/
有人可以帮忙吗?
我已经到处搜索以找到没有任何结果的解决方案。当客户付款并尝试处理订单时,我们面临着运输方法的问题,我们遇到一个错误“找不到使用这种方法的运输公司:matrixrate_5334”,并且运输方法消失了,需要再次移除并创建购物车才能查看这些运输方法。
Php 7.0 Magento 2.2.1版 Webshopp Matrixrates最新版本 https://docs.shipperhq.com/troubleshooting-matrixrates/
有人可以帮忙吗?
我注意到,由于在计算运费时,结帐会话报价$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核心问题:
干杯!