magento 中有没有一种方法可以按顺序设置基于项目的运输方式?

Is there a way in magento to set shipping method based on items in order?

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

就我对 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_Addressclass中复制方法:

public 函数 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;
        }