cancel
Showing results for 
Search instead for 
Did you mean: 

Mage 1.9 how to see if product with X config options already in cart?

Mage 1.9 how to see if product with X config options already in cart?

Hi guys I have a configurable product and one of the configurable options has two options. e.g,

 

colour 

    - red

    - blue

 

If customer has added with both options already (the product with both options already in the cart) then when he/she try add again, it won't add it and they will be taken to the checkout page.

 

So far I have this code:

 

     $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
  $result2 = array();
  // Load the configured product options
  $options = $item->getProduct()->getTypeInstance(true)->getOrderOptions($item->getProduct());
  // Check for options
  if ($options)
  {
    if (!empty($options['attributes_info']))
    {
      $result2 = array_merge($options['attributes_info'], $result2);
    }
  }
  $finalResult = array_merge($finalResult, $result2);
}
// Now you have the final array of all configured options
Zend_Debug::dump($finalResult); die;

I know this will loop through all the items in the cart. Bit lost how to now do the check bit.