我通过将Opencart的订单发送到我的CRM来编写模块。但在这种情况下我通过post.add设置事件但是不行,因为当客户刷新他们的购物车时,我的订单仍然在CRM中添加,因此我有相同的订单。我决定设置post.order.history.add事件,但在这种情况下,我有504网关超时。在这种情况下我能做些什么? 请注意,我的CRM和购买相同的VPS。
这是我的模块:
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 by 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 as $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);
}
}