【问题标题】:Set shipping cost on the product, fix configurable products in Magento设置产品运费,修复 Magento 中的可配置产品
【发布时间】:2015-09-14 08:17:15
【问题描述】:

我按照here 的建议扩展了 Magento 1.9 的统一运费运营商模型,因为我想为单个产品设置运费。

当我在购物车中添加可配置产品时,运费是双倍的。 Magento 在购物车中考虑了可配置的产品和简单的产品变体。 因此,当我添加可配置产品时,Magento 将可配置产品和单个产品的运费相加。

我添加了一个排除可配置产品的条件。可以吗?有没有办法只从购物车中提取单个产品?

谢谢。

Mage::getSingleton('core/session', array('name'=>'frontend'));
    $session = Mage::getSingleton('checkout/session');
    $cart_items = $session->getQuote()->getAllItems();
    $_helper = Mage::helper('catalog/output');
    $custom_ship = 0;
    foreach( $cart_items as $items ){
        // items are configurable and single products
        $cur_fproduct = Mage::getModel('catalog/product')->load($items->getProduct_id());
        if($cur_fproduct->getTypeId()=='simple') {
            $custom_ship +=($items->getQty())*($_helper->productAttribute($cur_fproduct, $cur_fproduct->getShippingWorld(), 'shipping_world'));
        }
    }

    return $custom_ship ;

【问题讨论】:

    标签: php magento magento-1.9


    【解决方案1】:

    相反,

    $cart_items = $session->getQuote()->getAllItems();
    

    使用,

     $cart_items = $session->getQuote()->getAllVisibleItems(); 
    

    或者你可以检查

    foreach( $cart_items as $items ){
            // items are configurable and single products
            if ($item->getParentItemId) // this is set for simple products of configurable
           { 
           }
        }
    

    希望这会有所帮助!

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多