2011-07-01 52 views

回答

11

這應該工作:

$items = Mage::getSingleton('checkout/session')->getQuote()->getAllItems(); 

$weight = 0; 
foreach($items as $item) { 
    $weight += ($item->getWeight() * $item->getQty()) ; 
} 

echo $weight; 

一個更好的辦法:

$weight = Mage::getSingleton('checkout/session') 
       ->getQuote() 
       ->getShippingAddress() 
       ->getWeight(); 
+0

謝謝@chapagain,我會試着讓你知道結果。 –

+0

如果您將多個相同的產品放入購物車,則上面給我的代碼不起作用。它始終顯示一種產品重量,而不是乘以產品數量。我該如何解決這個問題? –

+0

編輯答案。現在它應該適用於單個產品的多個數量。如果這確實起作用,請回復。 –

8

嘗試

$quote = Mage::getSingleton('checkout/session')->getQuote(); 
$weight = $quote->getShippingAddress()->getWeight(); 
+2

這應該是被接受的答案。 – Eric

+0

即使沒有shipping_address也可以使用 –

0

我已將此添加到minicart.phtml不到總價格,

<span class="label"><?php echo $this->__('Weight')?>: </span> 
<?php echo $_quote = Mage::getSingleton('checkout/session')->getQuote(); echo $_weight = $_quote->getShippingAddress()->getWeight();?> 

感謝這裏的帖子!

相關問題