2015-09-14 151 views
1

由於我想設置單件產品的運費,因此我擴展了Magento 1.9的flatrate carrier型號,建議爲here設置產品的運輸成本,修復Magento中的可配置產品

當我在購物車中添加可配置產品時,運輸成本是雙倍。 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 ; 

回答

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

希望這有助於!

+0

謝謝!我也檢查getAllItems();和getAllVisibleItems();這裏:http://stackoverflow.com/questions/3042905/difference-between-two-commands-of-fetching-shopping-cart-items-in-magento – Dariodor