I was trying to define some exceptions, and one of them is about the volume of the product. I've got width-length-height attributes in the products. And i was trying to get the total of these 3 attributes of all the products at my cart.

So i was trying things like this:

$cart = Mage::getModel('checkout/cart')->getQuote();
        $totalV= 0;

        foreach ($cart->getAllItems() as $item) {

        $prod_W = $item->getAttributeText('dp_width');
        $prod_H = $item->getAttributeText('dp_height');
        $prod_L = $item->getAttributeText('dp_length');
        $totalV += $prod_H + $prod_L +$prod_W;


        <input type = "hidden" class = "onestepcheckout-vol-prod" value = "<?php echo $totalV;?>
               " >

I tries to using $item->getProduct()->getAttributeText('X'); but it gives me an error.

How could i get these values ?

  • try the $item->getData('dp_width'); – saravanavelu Jun 18 '15 at 9:42
  • What error are you getting? – Mufaddal Jun 18 '15 at 9:48

Load product in foreach is a bad idea, though working.

Better way:

in config.xml



|improve this answer|||||
  • And then i could get the attribute as $item->getAttributeText('dp_width'); – ntzz Jun 18 '15 at 9:57
  • Yes, exactly, this is the correct variant! – Neklo.com Jun 18 '15 at 10:04
  • This is actual process +1 vote – Amit Bera Jun 18 '15 at 10:10
  • and for getting try $item->getProduct()->getAttributeText('dp_width'); – Amit Bera Jun 18 '15 at 10:11
  • Before making it, and cleaning cache, i make a try and gives me this error: Call to a member function getSource() on a non-object in /home/XXX/public_html/app/code/core/Mage/Catalog/Model/Product.php – ntzz Jun 18 '15 at 10:34

you can try this:




I have Using product Resource model

|improve this answer|||||
  • Dont run, i think it´s because this values are not printed on frontend, so it returns 0. – ntzz Jun 18 '15 at 10:52

$item donot have all the attributes information in quote, so the above code will not work.

instead you can try the below code

$product = Mage::getModel('catalog/product')->load($item->getProductId());

|improve this answer|||||
  • As you say, i try like you, But at the end, it gives me the same error as i say at final: Call to a member function getSource() on a non-object – ntzz Jun 18 '15 at 9:46

Load Product in foreach

$product = Mage::getModel('catalog/product')->load($item->getProduct()->getId());

you can able to get Product attributes like this

|improve this answer|||||
  • The same error as i say to the other mate down Call to a member function getSource() on a non-object – ntzz Jun 18 '15 at 9:48
  • 'Show in Product Listing' needed to be set to yes in the attribute editor in admin – Mufaddal Jun 18 '15 at 9:54
  • cannot do this . – ntzz Jun 18 '15 at 10:13

Try this

<?php $_item = $this->getItem()?>
<?php $_product= Mage::getSingleton('catalog/product')->load($_item->getProductId()) ?>
<?php echo $_product->getResource()->getAttribute('attribute_code')->getFrontend()->getValue($_product); ?>
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.