3

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?

5

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

| improve this answer | |
  • Hi Rohit, I got the value "No" for color and size. And when I change $itemsVisible = Mage::getSingleton('checkout/session')->getQuote()->getAllVisibleItems(); to $itemsVisible = Mage::getSingleton('checkout/session')->getQuote()->getAllItems(); it will show all the items in configurable product other than the main item. – Shafeeque S Mar 3 '16 at 7:26
  • in getAttribute() function use your attribute code – Rohit Kundale Mar 3 '16 at 7:29
  • @RohitKundale can i get help magento.stackexchange.com/q/292929/57334 – zus Oct 18 '19 at 4:39
0

Try this code :

 <?php
 $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();
 $_product = Mage::getSingleton('catalog/product')->load($_item->getProductId());
  $_product->getSize();
  $_product->getColor();

}
| improve this answer | |
0

try this:

$itemsVisible = Mage::getSingleton('checkout/session')->getQuote()->getAllVisibleItems();
 foreach($itemsVisible as $item) {
     $product = $item->getProduct();
     $attrs  = $product->getTypeInstance(true)->getConfigurableAttributesAsArray($product);
    foreach($attrs as $attr) {
        if(0 == strcmp("color", $attr['attribute_code'])) {
            $options    = $attr['values'];
            foreach($options as $option) {
                print "{$option['store_label']}<br />";
            }
        }
        if(0 == strcmp("size", $attr['attribute_code'])) {
            $options    = $attr['values'];
            foreach($options as $option) {
                print "{$option['store_label']}<br />";
            }
        }
    }
}

OR

$itemsVisible = Mage::getSingleton('checkout/session')->getQuote()->getAllVisibleItems();
 foreach($itemsVisible as $item) {
     $product = $item->getProduct();
     $attributes = $product->getTypeInstance(true)->getSelectedAttributesInfo($product);
     foreach($attributes as $attr) {
        if(0 == strcmp("color", $attr['attribute_code'])) {
            $options    = $attr['values'];
            foreach($options as $option) {
                print "{$option['store_label']}<br />";
            }
        }
        if(0 == strcmp("size", $attr['attribute_code'])) {
            $options    = $attr['values'];
            foreach($options as $option) {
                print "{$option['store_label']}<br />";
            }
        }
    }
}
| 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.