设置产品的运费,修复 Magento 中的可配置产品

Set shipping cost on the product, fix configurable products in Magento

我按照建议扩展了 Magento 1.9 的 flatrate carrier 模型 here 因为我想在单个产品上设置运费。

当我在购物车中添加可配置产品时,运费是双倍的。 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 ;

而不是这个,

$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
       { 
       }
    }

希望对您有所帮助!