Magento: update custom option cart item with ajax

I need to update the value of a custom option using ajax. I try to update it as

$params = $this->getRequest()->getParams(); $itemID = $params['item']; $item = Mage::getSingleton('checkout/session')->getQuote()->getItemById($itemID); $options = $item->getOptions(); foreach ($options as $option) { if(strtolower($option->getCode()) == 'info_buyRequest') { $unserialized = unserialize($option->getValue()); $unserialized['options'][216]= 'New Value'; $option->setValue(serialize($unserialized)); } } $item->save(); 

Can someone help me deal with what is going wrong here. Thanks

+4
source share
2 answers

Pravin made him work with the lines below.

 $item->setOptions($options)->save(); Mage::getSingleton('checkout/cart')->save(); 

Thanks p4pravin for sharing.

+1
source

This can never be true:

 (strtolower($option->getCode()) == 'info_buyRequest') 

In addition, I also had to edit the specific saved user option. My loop looks like this:

 foreach ($options as $option) { switch (true) { case (strtolower($option->getCode()) == 'info_buyrequest') : $unserialized = unserialize($option->getValue()); $unserialized['options'][216] = 'NEW VALUE'; $option->setValue(serialize($unserialized)); break; case ($option->getCode() == "option_216") : $option->setValue('NEW VALUE'); break; } } 
+2
source

All Articles