php - How to handle "504 gateway timeout" in Opencart module -


i wrote module send opencart's orders crm. in case set event post.add not ok because when client refresh shopping cart, order still adding in crm , reason i've got duplicate same order. decided set post.order.history.add event in case i've got 504 gateway timeout. can in situation? note, crm , shop on same vps.

this module:

public function check_phone($number) {     //bla bla bla     $retunr $number; }  public function on_order_add($order_id) {     $this->load->model('checkout/order');     $value = $this->model_checkout_order->getorder($order_id);      //prepare loggin     $url_login = "*********/login/enter/";     $login = array();     $login["username"] = "username";     $login["password"] = "password";     $login["remember"] = "on";     $login["act"] = "act";     //login     $curl = curl_init($url_login);     curl_setopt($curl, curlopt_post, true);     curl_setopt($curl, curlopt_postfields, http_build_query($login));     curl_setopt($curl, curlopt_returntransfer, 1);     curl_setopt($curl, curlopt_followlocation, 1);     curl_setopt($curl, curlopt_cookiejar, "cookie.txt");     curl_setopt($curl, curlopt_cookiefile, "cookie.txt"); //saved cookies     curl_setopt($curl, curlopt_useragent,          'mozilla/5.0 (windows nt 6.1; rv:11.0) gecko/20100101 firefox/11.0');     $response = (curl_exec($curl));     curl_close($curl);      //prepare order     $orders = array();     $order_id = $order_id;     $url = "******/orders/api/";       $orders["act"] = "add_packaging_order";     //order     $orders["id_user_add"] = 21; //system default     $orders["date_calendar"] = date("y-m-d");     $orders["timepicker"] = date("h:i:s");      if ($value["payment_code"] == "cod" || $value["payment_code"] == "cheque")         $orders["inlineradiooptions"] = "cash"; // НАЛ ИЛИ БЕЗНАЛ     else         $orders["inlineradiooptions"] = "cashless";      if (stristr($value["email"], 'localhost') !== false)         $value["email"] = " Не указано\n";       $orders["status"] = 1;     //order_end      //auto     if ($value["shipping_code"] == "flat.flat") {         $orders["show_next_auto"] = "on";         $orders["autoname"] = "Для доставки упаковки за 99грн";         $orders["summary_auto"] = 1;         $orders["price_auto_agree"] = 0;     }     if ($value["shipping_code"] == "free.free") {         $orders["show_next_auto"] = "on";         $orders["autoname"] = "Для бесплатной доставки упаковки";         $orders["summary_auto"] = 1;         $orders["price_auto_agree"] = 0;     }     //end auto       //start clients     $orders["name_clients[]"] = $value["lastname"] . " " . $value["firstname"];     $orders["sendsms"] = 0;     $orders["signature"] = "=======";     $orders["number_order"] = $order_id;     $orders["phones[]"] = $this->check_phone($value["telephone"]);       //end clients     $custom_fields = "";     //address     if (isset($value["custom_field"]))         $custom_data = ($value["custom_field"]);     if (isset($custom_data[17]))         $orders["company_name"] = $custom_data[17];      if (isset($custom_data[4]))         $orders["addres[]"] = $custom_data[4];     else         if (isset($custom_data[8]) || isset($custom_data[9]) || isset($custom_data[12])) {             $orders["addres[]"] = $custom_data[8] . ", " . $custom_data[9] . "  склад№" . $custom_data[12];         } else             $orders["addres[]"] = "Не указан";      if (isset($custom_data[18]))         $custom_fields .= "\nЕГРПОУ:" . $custom_data[18] . "\n";     if (isset($custom_data[19]))         $custom_fields .= "\nНомер свидетельства плательщика НДС :" . $custom_data[19] .             "\n";     $orders["addres_counter"] = "2";     if (isset($custom_data[16]))         if ($custom_data[16] == 26)             $custom_fields .= "\nЮридическое лицо\n";         else             $custom_fields .= "\Физическое лицо\n";     ///end address      $orders["commentary_total_order"] .= "Номер заказа в магазине№" . $order_id . "\n " .         $value["comment"] . "\n " . "email:" . $value["email"] . "\n Оплата: " . $value["payment_method"] .         "\n Доставка: " . $value["shipping_method"]; // КОММЕНТАРИИ      //default     $addr_query_string = "&num_build[]=&num_office_flat[]=";       //product      $this->load->model('account/order');     $products = $this->model_account_order->getorderproducts($order_id);     $orders["show_next_pack"] = "on";      $q = "";     foreach ($products $value => $key) {         $q .= "&pack[]=" . urlencode($key["name"] . " (" . $key["sku"] . ")");         $q .= "&num_pack[]=" . urlencode($key["quantity"]);         $q .= "&unit[]=" . urlencode("1");         $q .= "&price_pack[]=" . urlencode($key["price"]);      }       $curl = curl_init($url);     curl_setopt($curl, curlopt_post, true);     curl_setopt($curl, curlopt_postfields, http_build_query($orders).$q.$addr_query_string);     curl_setopt($curl, curlopt_returntransfer, 1);     curl_setopt($curl, curlopt_followlocation, 1);     curl_setopt($curl, curlopt_cookiejar, "cookie.txt");     curl_setopt($curl, curlopt_cookiefile, "cookie.txt"); //saved cookies     curl_setopt($curl, curlopt_useragent,'mozilla/5.0 (windows nt 6.1; rv:11.0) gecko/20100101 firefox/11.0');     $response = (curl_exec($curl));       curl_close($curl);   } 

}


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -