Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save evgv/f23b9679befd3311ed6aa02d58a60d82 to your computer and use it in GitHub Desktop.
Save evgv/f23b9679befd3311ed6aa02d58a60d82 to your computer and use it in GitHub Desktop.
Magento. Get product options from quote item

Get product options from quote item

  
    /* @var $quote Mage_Sales_Model_Quote */
    $quote = Mage::getSingleton('checkout/session')->getQuote()
    
    $items = $quote->getAllVisibleItems();
    
    $orderedItemsOptions = array();
    
    /* @var $item Mage_Sales_Model_Quote_Item */
    foreach ($items as $item) {

        $itemOptions = array();
        $options     = $item->getProduct()->getTypeInstance(true)->getOrderOptions($item->getProduct());
        
        if ($options) {
            if (isset($options['options']) && !empty($options['options'])) {
                $itemOptions = array_merge($itemOptions, $options['options']);
            }
            if (isset($options['additional_options']) && !empty($options['additional_options'])) {
                $itemOptions = array_merge($itemOptions, $options['additional_options']);
            }
            if (isset($options['attributes_info']) && !empty($options['attributes_info'])) {
                $itemOptions = array_merge($itemOptions, $options['attributes_info']);
            }
        }
        
        //it will return array for all items with key itemId and value array of all item ordered options
        $orderedItemsOptions[$item->getId()] = itemOptions; 
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment