1

Get cart visible products with custom options. I have done with out custom options.

    $cart = Mage::getModel('checkout/cart')->getQuote();
           //$cart->getAllItems() //for all cart items
                foreach ($cart->getAllVisibleItems() as $item) {            
                    $productName = $item->getProduct()->getName();
                    $productPrice = $item->getProduct()->getPrice();                  
                    /*
                    //OR
                    echo 'ID: ' . $item->getProductId() . '<br />';
                    echo 'Name: ' . $item->getName() . '<br />';
                    echo 'Sku: ' . $item->getSku() . '<br />';
                    echo 'Quantity: ' . $item->getQty() . '<br />';
                    echo 'Price: ' . $item->getPrice() . '<br />';
                    */
                   //get custom options        
                }

How can get custom options from this

    $productOptions = $item->getProduct()
              ->getTypeInstance(true)
              ->getOrderOptions($item->getProduct());
2

Try this below code

<?php
$cart = Mage::getModel('checkout/cart')->getQuote();
foreach ($cart->getAllVisibleItems() as $item) { 
  $options = Mage::helper('catalog/product_configuration')->getCustomOptions($item);
   print_r($options);

}
?>

OR

<?php
$product = $item->getProduct();
$options = array();
$optionIds = $item->getOptionByCode('option_ids');
if ($optionIds) {
    $options = array();
    foreach (explode(',', $optionIds->getValue()) as $optionId) {
        $option = $product->getOptionById($optionId);
        if ($option) {
            $itemOption = $item->getOptionByCode('option_' . $option->getId());
            $group = $option->groupFactory($option->getType())
                ->setOption($option)
                ->setConfigurationItem($item)
                ->setConfigurationItemOption($itemOption);

            if ('file' == $option->getType()) {
                $downloadParams = $item->getFileDownloadParams();
                if ($downloadParams) {
                    $url = $downloadParams->getUrl();
                    if ($url) {
                        $group->setCustomOptionDownloadUrl($url);
                    }
                    $urlParams = $downloadParams->getUrlParams();
                    if ($urlParams) {
                        $group->setCustomOptionUrlParams($urlParams);
                    }
                }
            }

            $options[] = array(
                'label' => $option->getTitle(),
                'value' => $group->getFormattedOptionValue($itemOption->getValue()),
                'print_value' => $group->getPrintableOptionValue($itemOption->getValue()),
                'option_id' => $option->getId(),
                'option_type' => $option->getType(),
                'custom_view' => $group->isCustomizedView()
            );
        }
    }
}

$addOptions = $item->getOptionByCode('additional_options');
if ($addOptions) {
    $options = array_merge($options, unserialize($addOptions->getValue()));
}
print_r($options);
?>
0

Maybe something like this:

        $quote = $this->_getSession()->getQuote();
        foreach($quote->getAllVisibleItems() as $item){
            foreach($item->getBuyRequest()->getOptions() as $code => $option){
                /* Do something interesting */
            }
        }
0

This should work:

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

foreach ($itemsCollection as $item) {
    $customOptions = $item->getProduct()
                          ->getTypeInstance(true)
                          ->getOrderOptions($item->getProduct());

    //var_dump($customOptions);    
    foreach ($customOptions['options'] as $option) {
        echo $option['label'] . ': ' . $option['value'] . '<br />';
    }
}

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.