Magento 2, Magento Development, Customization, Extension Development and Integration, Optimization, SEO and Responsive Design

Magento 2, Magento Development, Customization, Extension Development and Integration, Optimization, SEO and Responsive Design

Get Custom Options in Checkout/cart page Programmatically Magento

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
Zend_Debug::dump($finalResult);


 

Copyright @ 2017 HKBlog.