Magento 2:免费送货时隐藏其他送货方式


11

我向客户收取统一的运费,对于超过一定金额的订单,我也提供免费送货。目前,符合免费送货条件的客户也将显示所示的付费送货选项,这可能会使某些客户感到困惑。有谁知道免费送货方式可用时是否可以隐藏其他送货方式?

Answers:


6

我有同样的问题。

删除“免费送货”配置,因为您不需要它(您已经有了“购物车价格规则”)。

当您的客户符合免费送货的条件时,它将基于“固定费率”而不是“免费送货”中的情况发生。


6

当实际基于购物车小计启用免费送货时,编写一个插件以禁用统一费率送货方法。

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\OfflineShipping\Model\Carrier\Flatrate">
        <plugin name="disable-flatrate" type="Vendor\ModuleName\Model\Carrier\Flatrate" sortOrder="1" />
    </type>
</config>

编写一个Model类来处理子总体验证。

<?php
namespace Vendor\ModuleName\Model\Carrier;

class Flatrate
{

    const XML_PATH_FREE_SHIPPING_SUBTOTAL = "carriers/freeshipping/free_shipping_subtotal";

    /**
     * @var \Magento\Checkout\Model\Session
     */
    protected $_checkoutSession;

    /**
     * @var \Magento\Framework\App\Config\ScopeConfigInterface
     */
    protected $_scopeConfig;

    public function __construct(
        \Magento\Checkout\Model\Session $checkoutSession,
        \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
        \Magento\Store\Model\StoreManagerInterface $storeManager
    ) {
        $this->_storeManager = $storeManager;
        $this->_checkoutSession = $checkoutSession;
        $this->_scopeConfig = $scopeConfig;
    }

    public function afterCollectRates(\Magento\OfflineShipping\Model\Carrier\Flatrate $flatRate, $result)
    {
        $scopeId = $this->_storeManager->getStore()->getId();

        $storeScope = \Magento\Store\Model\ScopeInterface::SCOPE_STORES;

        // Get MOA value from system configuration.
        $freeShippingSubTotal = $this->_scopeConfig->getValue(self::XML_PATH_FREE_SHIPPING_SUBTOTAL, $storeScope, $scopeId);

        // Get cart subtotal from checkout session.
        $baseSubTotal = $this->_checkoutSession->getQuote()->getBaseSubtotal();

        // Validate subtoal should be empty or Zero.
        if(!empty($baseSubTotal) && !empty($freeShippingSubTotal)) {

            if($baseSubTotal >= $freeShippingSubTotal) {
                return false;
            }
        }

        return $result;
    }
}

1
嗨@maniprakash我需要创建di.xml的地方吗?
Nagaraju K

2
Romba Nandri工作正常。
Nagaraju K '18 -10-30

1
如何根据商品/购物车商品属性隐藏送货方式?
Nagaraju K


1

作为对@Nagaraju的回应,希望能帮助任何人。

可以在您拥有的任何模块中创建di.xml,或者如果您不知道如何以及在何处创建di.xml:

app / code / My_Vendor / MyModule / etc / di.xml- >在这里放置@maniprakash的代码

那么您应该在以下位置创建类:

app / code / My_Vendor / MyModule / Model / Flaterate- >并粘贴@maniprakash的类代码

只需记住在di.xml上的type标记中更改路径

<plugin name="disable-flatrate" type="Vendor\ModuleName\Model\Carrier\Flatrate" sortOrder="1" />

路径必须与Model类所在的位置匹配。在我的例子中应该是

<plugin name="disable-flatrate" type="My_Vendor\MyModule\Model\Flatrate" sortOrder="1" />

就是这样!希望能帮助到你!感谢@manipakrash,它对我有帮助!=)


0

隐藏结帐时免费送货

供应商/magento/Magento_Checkout/template/shipping-address/shipping-method-item.html

<!-- ko if: method.carrier_code !== 'freeshipping' -->
<tr class="row"
click="element.selectShippingMethod">
<td class="col col-method">
    <input type="radio"
           class="radio"
           ifnot="method.error_message"
           ko-checked="element.isSelected"
           ko-value="method.carrier_code + '_' + method.method_code"
           attr="'aria-labelledby': 'label_method_' + method.method_code + '_' + method.carrier_code + ' ' + 'label_carrier_' + method.method_code + '_' + method.carrier_code,
                'checked': element.rates().length == 1 || element.isSelected" />
    <span class="label"></span>
</td>
<td class="col col-price">
    <each args="element.getRegion('price')" render="" />
</td>
<td class="col col-carrier"
    attr="'id': 'label_carrier_' + method.method_code + '_' + method.carrier_code"
    text="method.carrier_title" />


0

等/ di.xml

<type name="Magento\Quote\Model\ShippingMethodManagement">
    <plugin name="vendor_module_plugin_model_quote_shipping_method_management" type="Vendor\Module\Plugin\Model\ShippingMethodManagement"  disabled="false"/>
</type>

插件/模型/ShippingMethodManagement.php

public function afterEstimateByAddress($shippingMethodManagement, $output)
{
    return $this->filterOutput($output);
}

public function afterEstimateByExtendedAddress($shippingMethodManagement, $output)
{
    return $this->filterOutput($output);
}

public function afterEstimateByAddressId($shippingMethodManagement, $output)
{
    return $this->filterOutput($output);
}

private function filterOutput($output)
{
    $free = [];
    foreach ($output as $shippingMethod) {
        if ($shippingMethod->getCarrierCode() == 'freeshipping' && $shippingMethod->getMethodCode() == 'freeshipping') {
            $free[] = $shippingMethod;
        }
    }

    if ($free) {
        return $free;
    }
    return $output;
}
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.