Magento: Get Custom Options & Configurable Product’s Options on Shopping Cart

This article shows how you can get custom options values and configurable options values in shopping cart page in Magento 1.x.

We use the checkout session quote collection for this purpose.

Here’s the full code:


// Get visible items collection in shopping cart
$itemsCollection = Mage::getSingleton('checkout/session')
                        ->getQuote()
                        ->getAllVisibleItems();

foreach ($itemsCollection as $item) {
    // Get options array 
    // which includes custom options and configurable options
    $allOptions = $item->getProduct()
                          ->getTypeInstance(true)
                          ->getOrderOptions($item->getProduct());

    // Print the array
    var_dump($allOptions);    
}

Get Custom Options Only

Here’s the code to get custom options only from the entire options array:


// Get visible items collection in shopping cart
$itemsCollection = Mage::getSingleton('checkout/session')
                        ->getQuote()
                        ->getAllVisibleItems();

foreach ($itemsCollection as $item) {
    // Get options array 
    // which includes custom options and configurable options
    $allOptions = $item->getProduct()
                          ->getTypeInstance(true)
                          ->getOrderOptions($item->getProduct());

    //var_dump($allOptions);    

    // Get custom options array 
    // and print each option's label and value
    $customOptions = $allOptions['options'];
    foreach ($customOptions as $option) {
        echo $option['label'] . ': ' . $option['value'] . '<br />';
    }
}

Get Configurable Product’s Options Only

Here’s the code to get configurable product’s options only from the entire options array:


// Get visible items collection in shopping cart
$itemsCollection = Mage::getSingleton('checkout/session')
                        ->getQuote()
                        ->getAllVisibleItems();

foreach ($itemsCollection as $item) {
    // Get options array 
    // which includes custom options and configurable options
    $allOptions = $item->getProduct()
                          ->getTypeInstance(true)
                          ->getOrderOptions($item->getProduct());

    //var_dump($allOptions);  
   
    // Get configurable product's options array 
    // and print each option's label and value
    $configurableOptions = $allOptions['attributes_info'];
    foreach ($configurableOptions as $option) {
        echo $option['label'] . ': ' . $option['value'] . '<br />';
    }
}

Hope this helps. Thanks.