From 0ba96c5633cf087bf9156fd7a05c916d31fe82e8 Mon Sep 17 00:00:00 2001 From: Akolzin Dmitry Date: Thu, 27 Sep 2018 17:23:49 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B4=D0=B0=D1=87=D0=B0?= =?UTF-8?q?=20=D0=B2=D0=BD=D0=B5=D1=88=D0=BD=D0=B5=D0=B3=D0=BE=20=D0=BA?= =?UTF-8?q?=D0=BE=D0=B4=D0=B0=20=D0=BA=D0=BB=D0=B8=D0=B5=D0=BD=D1=82=D0=B0?= =?UTF-8?q?=20=D0=BF=D1=80=D0=B8=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B8=20=D0=B7=D0=B0=D0=BA=D0=B0=D0=B7=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 4 ++++ catalog/model/retailcrm/order.php | 34 +++++++++++++++++-------------- 2 files changed, 23 insertions(+), 15 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6f167b1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.env +bin/ +vendor/ +www/ \ No newline at end of file diff --git a/catalog/model/retailcrm/order.php b/catalog/model/retailcrm/order.php index 72fda12..28af383 100644 --- a/catalog/model/retailcrm/order.php +++ b/catalog/model/retailcrm/order.php @@ -4,12 +4,12 @@ class ModelRetailcrmOrder extends Model { public function sendToCrm($order_data, $order_id) { - if(isset($this->request->post['fromApi'])) return; + if (isset($this->request->post['fromApi'])) return; $this->load->model('setting/setting'); $settings = $this->model_setting_setting->getSetting('retailcrm'); - if(!empty($settings['retailcrm_url']) && !empty($settings['retailcrm_apikey'])) { + if (!empty($settings['retailcrm_url']) && !empty($settings['retailcrm_apikey'])) { $this->load->model('catalog/product'); require_once DIR_SYSTEM . 'library/retailcrm/bootstrap.php'; @@ -22,22 +22,26 @@ class ModelRetailcrmOrder extends Model { $order = array(); - $customers = $this->retailcrm->customersList( - array( - 'name' => $order_data['telephone'], - 'email' => $order_data['email'] - ), - 1, - 100 - ); + if ($order_data['customer_id']) { + $order['customer']['externalId'] = $order_data['customer_id']; + } else { + $customers = $this->retailcrm->customersList( + array( + 'name' => $order_data['telephone'], + 'email' => $order_data['email'] + ), + 1, + 100 + ); - if($customers) { - foreach ($customers['customers'] as $customer) { - $order['customer']['id'] = $customer['id']; + if ($customers) { + foreach ($customers['customers'] as $customer) { + $order['customer']['id'] = $customer['id']; + } } - } - unset($customers); + unset($customers); + } $order['externalId'] = $order_id; $order['firstName'] = $order_data['firstname'];