我需要使用 ajax 更新自定义选项值。 我正在尝试更新它,例如
$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();
任何人都可以帮我解决这里出了什么问题吗? 谢谢
最佳答案
这永远不可能是真的:
(strtolower($option->getCode()) == 'info_buyRequest')
此外,我还必须编辑特定的已保存自定义选项。我的循环如下所示:
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;
}
}
关于玛根托 :Update cart item Custom Option using ajax,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11649962/