2
votes

I am trying to show the products in shopping cart in a panel which is accessible in all pages(in menu). I have accomplished it by using below

      $cartHelper = Mage::helper('checkout/cart');
      $items = $cartHelper->getCart()->getItems();

but i am struggling with showing the Custom option selected for each product. I tried using

$item->getOptionList()

but its not working for me..

Please give me a hand on this.

Thanks, Balan

2

2 Answers

6
votes

I found the answer, below code would print the custom option selected

$options = array();
if ($optionIds = $item->getOptionByCode('option_ids')) {
$options = array();
foreach (explode(',', $optionIds->getValue()) as $optionId) {
if ($option = $item->getProduct()->getOptionById($optionId)) {

$quoteItemOption = $item->getOptionByCode('option_' . $option->getId());

$group = $option->groupFactory($option->getType())
->setOption($option)
->setQuoteItemOption($quoteItemOption);

$options[] = array(
'label' => $option->getTitle(),
'value' => $group->getFormattedOptionValue($quoteItemOption->getValue()),
'print_value' => $group->getPrintableOptionValue($quoteItemOption->getValue()),
'option_id' => $option->getId(),
'option_type' => $option->getType(),
'custom_view' => $group->isCustomizedView()
);
}
}
}
if ($addOptions = $item->getOptionByCode('additional_options')) {
$options = array_merge($options, unserialize($addOptions->getValue()));
}

thanks goes to http://www.e-commercewebdesign.co.uk see this link for reference.

0
votes
$cart = Mage::getModel('checkout/cart')->getQuote();

foreach ($cart->getAllVisibleItems() as $item) {    
$options = Mage::helper('catalog/product_configuration')->getCustomOptions($item);

}