Oğuz Çelikdemir
Oğuz Çelikdemir

Reputation: 4980

Display total weight of cart in the magento header

I have only simple products that I want to show total weight of cart in the header section after the "My Cart" link.

Could anybody help me to resolve this issue?

Upvotes: 0

Views: 10662

Answers (3)

Mukesh Chapagain
Mukesh Chapagain

Reputation: 25996

This should work:

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

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

echo $weight;

A better way:

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

Upvotes: 11

Stevens
Stevens

Reputation: 31

I added this to the minicart.phtml just under Total price,

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

Thanks for the post here!

Upvotes: 0

MagePal Extensions
MagePal Extensions

Reputation: 17656

Try

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

Upvotes: 8

Related Questions