Question

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.

Was it helpful?

Solution

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();
        }
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top