首页 文章

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

提问于
浏览
1

我按照建议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 ;

1 回答

  • 0

    相反,

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

    希望这可以帮助!

相关问题