2012-07-25 84 views
4

我需要使用ajax更新自定義選項值。 我想更新它像Magento:使用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(); 

任何一個可以幫助我生根粉是怎麼回事錯在這裏。 謝謝

+1

只是一個瘋狂的猜測..而不是'$ item-> save();',嘗試'$ item-> setOptions($ options) - > save();'。 。 – Kalpesh 2012-07-25 15:50:21

+2

$ item-> setOptions($ options) - > save(); Mage :: getSingleton('checkout/cart') - > save(); 爲我工作。 謝謝 – p4pravin 2012-07-26 12:56:07

+0

很高興!您能否將答案標記爲「已接受」,以便它可以幫助其他用戶? – Kalpesh 2012-07-26 13:52:47

回答

1

Pravin得到它與下面的代碼行。

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

感謝p4pravin分享。

+0

它使我的購物車價值0 – UnderGround 2013-11-15 09:58:23

2

這不可能是真實的:

(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; 
    } 
} 
+0

不更新值 – UnderGround 2013-11-15 13:10:52

相關問題