/**
  * Set order NetEven
  * @param $param
  */
 public function setOrderNetEven($params)
 {
     if (!self::$send_order_state_to_neteven) {
         return;
     }
     if ($res = Db::getInstance()->getRow('SELECT * FROM `' . _DB_PREFIX_ . 'orders_gateway` WHERE `id_order` = ' . (int) $params['id_order'])) {
         $status = '';
         $track = '';
         $date_now = date('Y-m-d H:i:s');
         if ($params['newOrderStatus']->id == (int) Configuration::get('PS_OS_PREPARATION')) {
             $status = 'Confirmed';
         }
         if ($params['newOrderStatus']->id == (int) Configuration::get('PS_OS_CANCELED')) {
             $status = 'Canceled';
         }
         if ($params['newOrderStatus']->id == (int) Configuration::get('PS_OS_DELIVERED')) {
             $res_order = Db::getInstance()->getRow('SELECT `shipping_number` FROM `' . _DB_PREFIX_ . 'orders` WHERE `id_order` = ' . (int) $params['id_order']);
             $status = 'Shipped';
             $track = $res_order['shipping_number'];
         }
         if ($params['newOrderStatus']->id == (int) Configuration::get('PS_OS_REFUND')) {
             $status = 'Refunded';
         }
         if ($status != '') {
             $order1 = array('OrderID' => $res['id_order_neteven'], 'Status' => $status);
             if (!empty($track)) {
                 $order1['TrackingNumber'] = $track;
             }
             $params_web = array('orders' => array($order1));
             try {
                 $response = $this->_client->PostOrders($params_web);
                 $order_status = $response->PostOrdersResult->MarketPlaceOrderStatusResponse;
             } catch (Exception $e) {
                 Toolbox::manageError($e, 'Update order statu in neteven');
                 $order_status = NULL;
             }
             if ($this->getValue('send_request_to_mail')) {
                 $this->sendDebugMail($this->getValue('mail_list_alert'), self::getL('Debug - Control request') . ' setOrderNetEven', $this->_client->__getLastRequest(), true);
             }
             if (!isset($order_status->StatusResponse) || isset($order_status->StatusResponse) && $order_status->StatusResponse != 'Updated' || is_null($order_status)) {
                 $complement = !is_array($order_status->StatusResponse) ? $order_status->StatusResponse : '';
                 $complement .= is_array($order_status->StatusResponse) ? '<pre>' . print_r($order_status->StatusResponse, true) . '</pre>' : '';
                 if ($this->getValue('send_request_to_mail')) {
                     $this->sendDebugMail($this->getValue('mail_list_alert'), self::getL('Fail for update order state'), self::getL('Order Id') . ' (' . (int) $params['id_order'] . '). ' . self::getL('NetEven response') . ' : ' . $complement);
                 }
             }
             if (!empty($order_status) && !is_null($order_status)) {
                 Toolbox::addLogLine(self::getL('Update order state') . ' ' . $status . ' ' . self::getL('NetEven Order Id') . ' ' . $res['id_order_neteven'] . ' ' . self::getL('Order Id') . ' ' . $res['id_order'] . ' - ' . $order_status->StatusResponse . '');
             }
             if (!Db::getInstance()->Execute('INSERT INTO `' . _DB_PREFIX_ . 'orders_gateway_order_state` (`id_order`, `id_order_state`, `date_add`, `date_upd`) VALUES (' . (int) $res['id_order'] . ', ' . (int) $params['newOrderStatus']->id . ', "' . pSQL($date_now) . '", "' . pSQL($date_now) . '")')) {
                 Toolbox::addLogLine(self::getL('Failed for save export NetEven order state Id') . ' ' . (int) $res['id_order']);
             } else {
                 Toolbox::addLogLine(self::getL('Save export of NetEven order state Id') . ' ' . (int) $res['id_order']);
             }
         }
     }
     Toolbox::writeLog();
 }
 /**
  * Envoie des produits a NetEven.
  * @param $t_retour
  * @return mixed
  */
 private function addProductInNetEven($neteven_products)
 {
     if (count($neteven_products) == 0) {
         if ($this->getValue('debug')) {
             Toolbox::displayDebugMessage(self::getL('No product to send !'));
         }
         return;
     }
     try {
         Toolbox::addLogLine(self::getL('Number of product send to NetEven') . ' ' . count($neteven_products));
         $params = array('items' => $neteven_products);
         $response = $this->_client->PostItems($params);
         $itemsStatus = $response->PostItemsResult->InventoryItemStatusResponse;
         if ($this->getValue('debug')) {
             Toolbox::displayDebugMessage(self::getL('Sends data to NetEven'));
         }
     } catch (Exception $e) {
         if ($this->getValue('debug')) {
             Toolbox::displayDebugMessage(self::getL('Failed to send data to Neteven'));
         }
         $erreur = '<pre>Last request:\\n' . $this->_client->__getLastRequest() . '</pre>\\n';
         Toolbox::manageError($e, 'add product nombre => ' . count($neteven_products) . ' ' . $erreur);
         $response = '';
         $itemsStatus = '';
     }
     if ($this->getValue('send_request_to_mail')) {
         $this->sendDebugMail($this->getValue('mail_list_alert'), self::getL('Debug - Control request') . ' addProductInNetEven', $this->_client->__getLastRequest(), true);
     }
     if ($response != '' && $itemsStatus != '') {
         if (is_array($response->PostItemsResult->InventoryItemStatusResponse)) {
             foreach ($response->PostItemsResult->InventoryItemStatusResponse as $rep) {
                 Toolbox::addLogLine($rep->ItemCode . ' ' . $rep->StatusResponse);
                 if ($this->getValue('debug')) {
                     Toolbox::displayDebugMessage(self::getL('Add product') . ' : ' . $rep->ItemCode . ' ' . $rep->StatusResponse);
                 }
             }
         } else {
             Toolbox::addLogLine($response->PostItemsResult->InventoryItemStatusResponse->ItemCode . ' ' . $response->PostItemsResult->InventoryItemStatusResponse->StatusResponse);
             if ($this->getValue('debug')) {
                 Toolbox::displayDebugMessage(self::getL('Add product') . ' : ' . $response->PostItemsResult->InventoryItemStatusResponse->ItemCode . ' ' . $response->PostItemsResult->InventoryItemStatusResponse->StatusResponse);
             }
         }
     }
     Toolbox::writeLog();
     Configuration::updateValue('neteven_date_export_product', date('Y-m-d H:i:s'));
 }
예제 #3
0
 public static function manageError($e, $type_error)
 {
     Toolbox::writeLog(true, $type_error . " => " . $e);
 }