Пример #1
0
 /**
  * import orders
  * @return boolean
  */
 public function importOrders()
 {
     $this->users = load_users();
     $this->products_i18n = load_products_i18n();
     if (isset($this->xml->СписокРасходныеНакладные)) {
         $statuses = array();
         foreach ($this->xml->СписокРасходныеНакладные as $status) {
             if ($status->IDЗаказПокупателя . '') {
                 $statuses[$status->IDЗаказПокупателя . ''] = array('id' => $status->ID . '', 'code' => $status->Номер . '', 'date' => strtotime($status->Дата . ''));
             }
         }
     }
     foreach ($this->xml->СписокЗаказыПокупателя as $order) {
         $data = array();
         $data['date_created'] = strtotime($order->Дата . '');
         $data['user_deliver_to'] = $order->Адрес . '';
         $data['user_phone'] = $order->КонтактныйТелефон . '';
         $data['paid'] = (int) $order->ПризнакПередоплаты;
         $data['external_id'] = $order->ID . '';
         $data['code'] = $order->Номер . '';
         $data['delivery_date'] = strtotime($order->СрокДоставки . '');
         $data['partner_external_id'] = $order->IDОрганизация . '';
         $data['status'] = 1;
         if ($statuses[$data['external_id']]) {
             $data['status'] = 2;
             $data['invoice_external_id'] = $statuses[$data['external_id']]['id'];
             $data['invoice_code'] = $statuses[$data['external_id']]['code'];
             $data['invoice_date'] = $statuses[$data['external_id']]['date'];
         }
         $user = is_user($order->IDКонтрагент, $this->users);
         if ($user) {
             $userInfo = $this->ci->db->where('id', $user['id'])->get('users')->row_array();
             $data['user_id'] = $user['id'];
             $data['user_full_name'] = $userInfo['username'];
             $data['user_email'] = $userInfo['email'];
         } else {
             return;
         }
         $order_exist = is_order($data['external_id'], $this->orders);
         if ((string) $order->IDWeb) {
             $data['id'] = (string) $order->IDWeb . '' ? (string) $order->IDWeb . '' : $order_exist['id'];
             foreach ($this->xml->СписокРасходныеНакладные as $status) {
                 if ((string) $status->IDЗаказПокупателя == $order->ID) {
                     $this->updateOrder($status, $data);
                     //                        var_dumps($status);
                     break;
                 }
             }
             //                $this->updateOrder($order, $data);
         } else {
             $this->insertOrder($order, $data);
         }
     }
     $this->insertData($this->orders_table);
     $this->updateData($this->orders_table, 'id');
     $inserted_orders = load_orders();
     foreach ($inserted_orders as $value) {
         foreach ($this->insert_order_products as $key => $order_product) {
             if ($order_product['external_order_id'] == $value['external_id'] && $order_product['external_order_id'] != NULL) {
                 $this->insert_order_products[$key]['order_id'] = $value['id'];
                 unset($this->insert_order_products[$key]['external_order_id']);
             }
         }
     }
     $this->insert = $this->insert_order_products;
     $this->insertData($this->orders_products_table);
     $this->updateData($this->orders_table, 'id');
     $this->update = $this->update_order_products;
     $this->updateData($this->orders_products_table, 'id');
 }
Пример #2
0
 /**
  * import orders
  * @return boolean
  */
 public function importOrders()
 {
     $this->users = load_users();
     $this->products_i18n = load_products_i18n();
     foreach ($this->xml->СписокЗаказыПокупателя as $order) {
         $data = array();
         $data['date_created'] = strtotime($order->Дата . '');
         $data['user_deliver_to'] = $order->Адрес . '';
         $data['user_phone'] = $order->КонтактныйТелефон . '';
         $data['paid'] = (int) $order->ПризнакПередоплаты;
         $data['external_id'] = $order->ID . '';
         $data['partner_external_id'] = $order->IDОрганизация . '';
         $user = is_user($order->IDКонтрагент, $this->users);
         if ($user) {
             $data['user_id'] = $user['id'];
         } else {
             return false;
         }
         if (!is_order($order->ID, $this->orders)) {
             $this->insertOrder($order, $data);
         } else {
             $this->updateOrder($order, $data);
         }
     }
     $this->insertData($this->orders_table);
     $inserted_orders = load_orders();
     foreach ($inserted_orders as $value) {
         foreach ($this->insert_order_products as $key => $order_product) {
             if ($order_product['external_order_id'] == $value['external_id']) {
                 $this->insert_order_products[$key]['order_id'] = $value['id'];
                 unset($this->insert_order_products[$key]['external_order_id']);
             }
         }
     }
     $this->insert = $this->insert_order_products;
     $this->insertData($this->orders_products_table);
     $this->updateData($this->orders_table, 'external_id');
     $this->update = $this->update_order_products;
     $this->updateData($this->orders_products_table, 'external_id');
 }