0
votes

There are a few threads on here explaining how to get a product attribute in the cart or checkout. However, I just can't get it to work.

In the cart I can see the product attribute, but not in the checkout.

From what I've read, the checkout doesnt know about the product, so I need to load it. This would explain why Im not seeing it.

I've tried a lot of things, but I either don't get my shipping step to load in the cart, or it just doesn't display.

Any help would be great! Here is my code in a custom shipping module.

$cart = Mage::getSingleton('checkout/session');

//Order value by category
$gold = 0;

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

    $itemPrice = $item->getPrice();
    $qty = $item->getQty();
    $metalType = Mage::getModel('catalog/product')->load($item->getProduct()->getId())->getAttributeText('metal');

    if ($metalType == "Gold") {
        //Apply some business logic
        $gold = $itemPrice * $qty;
    }
}

Magento get cart single item price incl. tax

Magento Product Attribute Get Value

1
Have you tried ->getMetal()?scrowler
->getMetal() breaks the site.user123976

1 Answers

1
votes

In the afterLoad of the Mage_Sales_Model_Resource_Quote_Item_Collection object, a method is called to _assignProducts to each quote item. This method loads a product collection using the following code:

$productCollection = Mage::getModel('catalog/product')->getCollection()
    ->setStoreId($this->getStoreId())
    ->addIdFilter($this->_productIds)
    ->addAttributeToSelect(Mage::getSingleton('sales/quote_config')->getProductAttributes())
    ->addOptionsToResult()
    ->addStoreFilter()
    ->addUrlRewrite()
    ->addTierPriceData();

If you add the product attribute to the config.xml of your new module in the following way, it should be added as an attribute to be selected in the product collection.

<sales>
    <quote>
        <item>
            <product_attributes>
                  <metal/>
            </product_attributes>
        </item>
    </quote>
</sales>