【问题标题】:Is there a way in magento to set shipping method based on items in order?Magento 有没有办法根据订单中的物品设置运输方式?
【发布时间】:2015-12-30 01:33:20
【问题描述】:

magento 中是否有设置,如果订单包含某些商品,则默认选择送货方式?

【问题讨论】:

    标签: magento shipping fedex ups usps


    【解决方案1】:

    据我所知,Magento 没有设置,但您可以通过扩展 Mage_Sales_Model_Quote_Address 方法来实现:requestShippingRates。

    在您的 etc/config.xml 文件中:

    
    <global>
        <models>
            <modulename>
                <class>Package_Modulename_Model</class>
            </modulename>
            <sales>
                <rewrite>
                    <quote_address>Package_Modulename_Model_Sales_Quote_Address</quote_address>
                </rewrite>
            </sales>
        </models>
    </global>
    

    在您的 Package_Modulename_Model_Sales_Quote_Address 类中,复制方法:

    公共函数 requestShippingRates(Mage_Sales_Model_Quote_Item_Abstract $item = null) 在里面,查找以下代码:

    
    $found = false;
    if ($result) {
        $shippingRates = $result->getAllRates();
        //Add your code here:
    
        //Get all of the cart items.
        $_cartItems = $request->getAllItems();
    
        //Check if the cart contains items with specific shipping method:
        //Note that you need to implement the _getItemsShippingMethod yourself.
        $_shippingMethod = $this->_getItemsShippingMethod($_cartItems);
    
        foreach ($shippingRates as $shippingRate) {
            //Skip all other methods.
            if ($shippingRate->getCarrier() != $_shippingMethod) {
                continue;
            }
    

    【讨论】:

    • 唯一的答案,所以我检查了它。
    猜你喜欢
    • 1970-01-01
    • 2015-12-22
    • 1970-01-01
    • 1970-01-01
    • 2016-10-14
    • 1970-01-01
    • 1970-01-01
    • 2013-02-21
    • 2010-10-30
    相关资源
    最近更新 更多