Magento 1.9 – Get Attributes of Products in Cart at OneStepCheckout

attributesmagento-1.9products

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;?>
               " >
        </input>

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

How could i get these values ?

Best Answer

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

Better way:

in config.xml

<global>
    <sales>
        <quote>
            <item>
                <product_attributes>
                    <dp_width/>
                    <dp_height/>
                    <dp_length/>
                </product_attributes>
            </item>
        </quote>
    </sales>
</global>

And...

$item->getProduct()->getAttributeText('dp_width');