显示magento标题中购物车的总重量

时间:2011-07-01 14:03:56

标签: magento

我只有简单的产品,我想在“我的购物车”链接后的标题部分显示购物车的总重量。

有人可以帮我解决这个问题吗?

3 个答案:

答案 0 :(得分:10)

这应该有效:

$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();

答案 1 :(得分:8)

尝试

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

答案 2 :(得分:0)

我将此添加到minicart.phtml中,只是在总价格下,

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

感谢您的帖子!