我只有简单的产品,我想在"我的购物车"链接后的标题部分显示购物车的总重量。
有人能帮我解决这个问题吗?
这应该有效:
$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();
尝试
$quote = Mage::getSingleton('checkout/session')->getQuote();
$weight = $quote->getShippingAddress()->getWeight();
我把它添加到了minicart.html中,就在总价下,
<span class="label"><?php echo $this->__('Weight')?>: </span>
<?php echo $_quote = Mage::getSingleton('checkout/session')->getQuote(); echo $_weight = $_quote->getShippingAddress()->getWeight();?>
谢谢你在这里发帖!