Magento 1.9 – Get ‘Color’ and ‘Size’ Attributes Value of Items in Cart

configurable-productmagento-1.9product-attribute

I want to display the color and size of the configurable product in the cart. I got all the details other than the color and size values. My code is

 `$itemsVisible = Mage::getSingleton('checkout/session')->getQuote()->getAllVisibleItems();

 foreach($itemsVisible as $item) {
    $id = $item->getProductId();
    $name = $item->getName();
    $sku = $item->getSku();
    $qty = $item->getQty();
    $price = $item->getPrice();
    $size = $item->getSize(); 
    $color =  $item->getColor();`
  }

color and size return blank. How can I get these values?

Best Answer

Use following code to get attribute in cart page.

    $itemsVisible = Mage::getSingleton('checkout/session')->getQuote()->getAllVisibleItems();

     foreach($itemsVisible as $item) {
        $_product= Mage::getSingleton('catalog/product')->load($item->getProductId());

        $id = $item->getProductId();
        $name = $item->getName();
        $sku = $item->getSku();
        $qty = $item->getQty();
        $price = $item->getPrice();
        // Following code for size and color. Use attribute code in place of size and color
        $size = $_product->getResource()->getAttribute('size')->getFrontend()->getValue($_product);
        $color =  $_product->getResource()->getAttribute('color')->getFrontend()->getValue($_product);`
      } 

Hope this helps you