Magento – Get the Chosen Configuration / Options of the Products in the Cart

A Magento client of mine wanted to be able to change the calls to action on the cart and checkout pages based on the product configuration that the customers have selected for purchase. The following bit of code loops through the products in the Magento shopping basket and gets the chosen custom options and / or configuration.

// Load the session
$session = Mage::getSingleton(‘checkout/session’);
// Array to hold the final result
$finalResult = array();
// Loop through all items in the cart
foreach ($session->getQuote()->getAllItems() as $item)
// Array to hold the item’s options
$result = array();
// Load the configured product options
$options = $item->getProduct()->getTypeInstance(true)->getOrderOptions($item->getProduct());
// Check for options
if ($options)
if (isset($options[‘options’]))
$result = array_merge($result, $options[‘options’]);
if (isset($options[‘additional_options’]))
$result = array_merge($result, $options[‘additional_options’]);
if (!empty($options[‘attributes_info’]))
$result = array_merge($options[‘attributes_info’], $result);
$finalResult = array_merge($finalResult, $result);
// Now you have the final array of all configured options

Source: the function – getOrderOptions() found in the file – app/code/core/Mage/Bundle/Block/Adminhtml/Sales/Order/View/Items/Renderer.php

The options will be stored in the keys ‘label’ and ‘value’ in the resulting array.


9 responses to “Magento – Get the Chosen Configuration / Options of the Products in the Cart”

  1. Amazing, thank you. I was looking for this solution for, what seemed like, an age.

    1. You are welcome!

      1. Thanks for this. i have 1 question if my product name is same then how can I get the unique ID for that product so I can edit that product with all custom options

  2. Thanks for this

    1. You are welcome

  3. Great ! You made me save a lot of time !

    1. Glad to be of help :)

  4. I was just looking for this. Wuld you maybe also know how to get also option ID, not only Label?

  5. getting an error “Fatal error: Call to a member function getTypeInstance() on a non-object in …” when using the above code in sendNewOrderEmail() func in app/code/core/mage/sales/model/order.php.
    Any thoughts why?