0
votes

In Magento,I have functionality where, a product has multiple colors, user can select quantity and color for product on product view page, where a product has different colors,

I need to show selected color on a cart page. I tried following code.

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

but it returns all color values for a product on cart page, instead of selected value for cart page.

any ideas?

1
You have to convert each such product to configurable product (magentocommerce.com/knowledge-base/entry/…)hindmost

1 Answers

1
votes

There are 2 main options for a product to have multiple colors:

  1. Configurable products:
    If you are using configurable products then you can get you color attribute like this:

    <?php $product = Mage::getModel('catalog/product')->loadByAttribute('sku', $_item->getSku(), array('color_attribute')); echo $product->getColorAttribute(); ?></code>
    

    Replace 'color_attribute' and getColorAttribute with your attribute name.

  2. Custom options:
    In this case use:

    <?php print_r($_item->getProduct()->getTypeInstance(true)->getOrderOptions($_item->getProduct())); ?>
    

    And look for the options you need to display.