1

I am trying to change my order item custom options after order placed but it overwrite exitsting data and set only value that i did set previously. https://www.screencast.com/t/Y99dQ1D4 My code.

foreach ($orderIds as $key => $value) {
       $orderModel = Mage::getModel('sales/order')->load($value);
       $orderItem = $orderModel->getAllItems();
       foreach ($orderItem as $item) {
        if($item->getId()==17447){
           $option = $item->getProductOptions();
          $info = $intoByRequest['info_buyRequest']['additional_options']['item_shippinggroup'];
          $info = 'group1';
          $item->setProductOptions(serialize($info))
       }
    }

can anyone please guide me how i would change one array element and save the item.

2
  • Did you check with save in your code like $item->setProductOptions(serialize($info))->save(); Commented Jan 31, 2017 at 12:55
  • yes dear i did but it save only set value :(
    – MageLerner
    Commented Jan 31, 2017 at 13:05

1 Answer 1

2

Try below code:

foreach ($orderIds as $key => $value) {
   $orderModel = Mage::getModel('sales/order')->load($value);
   $orderItem = $orderModel->getAllItems();
   foreach ($orderItem as $item) {
        if($item->getId()==17447){
          $option = $item->getProductOptions();
          $option['info_buyRequest']['additional_options']['item_shippinggroup'] = 'group1';
          $item->setProductOptions($option)->save();
        }
    }
}
5
  • It overwrite all other option and save like this s:106:"a:1:{s:15:"info_buyRequest";a:1:{s:18:"additional_options";a:1:{s:18:"item_shippinggroup";s:6:"group1";}}}";
    – MageLerner
    Commented Jan 31, 2017 at 13:44
  • @MageLerner, Updated code, there was no need of unserializing the data. Commented Jan 31, 2017 at 13:53
  • it works but it convert all serialize string to non converted string unserialize.com/s/204479a4-13d1-ba28-ebc1-0000152774b4 It should look like this unserialize.com/s/6da87b87-d151-da09-dad3-000079f1dd24
    – MageLerner
    Commented Jan 31, 2017 at 13:57
  • 3
    Please make edit this line $item->setProductOptions(serialize($option))->save(); to $item->setProductOptions($option)->save();
    – MageLerner
    Commented Feb 1, 2017 at 5:07
  • @JaiminSutariya Works for me! Commented Sep 22, 2017 at 9:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.