有没有一种方法在magento设置基于订单中的项目发货方式?[已关闭]

tv6aics1  于 2023-01-17  发布在  其他
关注(0)|答案(1)|浏览(147)

**已关闭。**此问题为not about programming or software development。当前不接受答案。

此问题似乎与a specific programming problem, a software algorithm, or software tools primarily used by programmers无关。如果您认为此问题与another Stack Exchange site的主题有关,您可以留下评论,说明在何处可以回答此问题。
2天前关闭。
Improve this question
是否有一个设置(s)在magento中,如果订单包含某些项目,一个运输方式将被默认选择?

wqnecbli

wqnecbli1#

据我所知,Magento没有设置,但可以通过扩展Mage_Sales_Model_Quote_Address方法来实现:请求运费
在您的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类中,复制以下方法:

public function 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;
        }

相关问题