if (!is_object($order)) {
     $logger->write('Can not find order: ' . $order_no);
 } else {
     $item = $order->getItemFromSalesPartnerItemReferenceNo($external_item_id);
     if (!is_object($item)) {
         $logger->write('Can not find item: ' . $external_item_id);
     } else {
         $logger->write('Current status: ' . $item->status);
         $status_update_valid = false;
         if ($item->status != $new_status) {
             if ($new_status == OrderItem::STATUS_CANCEL) {
                 if (OrderItem::isStatusOpen($item->status) && !OrderItem::isStatusCancelConfirmed($item->status)) {
                     $status_update_valid = true;
                 }
             } elseif ($new_status == OrderItem::STATUS_SENT_TO_CUSTOMER) {
                 if ((OrderItem::isStatusOpen($item->status) || OrderItem::isStatusCancel($item->status)) && !OrderItem::isStatusReturn($item->status)) {
                     $status_update_valid = true;
                 }
             }
         }
         if ($status_update_valid) {
             $item->updateStatus($new_status, $session_userinfo['username']);
             $item_updated++;
             $logger->write('Status updated!');
         }
         if (!is_null($tracking_code) && $tracking_code != '' && $order->getTrackingCodeShipment() != $tracking_code) {
             $order->setTrackingCodeShipment($tracking_code);
             $new_tracking_code++;
         }
     }
 }