diff --git a/CHANGELOG.md b/CHANGELOG.md index a116c4b..d873233 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## v.3.1.1 +* Добавлено создание клиента при ручной выгрузке заказа из админки + ## v.3.1.0 * Переработан дизайн шаблона twig * Добавлена настройка передачи номера заказа в retailCRM diff --git a/VERSION b/VERSION index a0cd9f0..50e47c8 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.1.0 \ No newline at end of file +3.1.1 \ No newline at end of file diff --git a/src/upload/admin/model/extension/retailcrm/customer.php b/src/upload/admin/model/extension/retailcrm/customer.php index 7a8f7ae..1702e9a 100644 --- a/src/upload/admin/model/extension/retailcrm/customer.php +++ b/src/upload/admin/model/extension/retailcrm/customer.php @@ -65,6 +65,27 @@ class ModelExtensionRetailcrmCustomer extends Model { return $customerToCrm; } + /** + * Create customer + * + * @param array $customer + * @param \RetailcrmProxy $retailcrmApiClient + * + * @return mixed + */ + public function sendToCrm($customer, $retailcrmApiClient) + { + if ($retailcrmApiClient === false || empty($customer)) { + return false; + } + + $customerToCrm = $this->process($customer); + + $retailcrmApiClient->customersCreate($customerToCrm); + + return $customerToCrm; + } + /** * Process customer * diff --git a/src/upload/admin/model/extension/retailcrm/order.php b/src/upload/admin/model/extension/retailcrm/order.php index 4f147aa..b870b97 100644 --- a/src/upload/admin/model/extension/retailcrm/order.php +++ b/src/upload/admin/model/extension/retailcrm/order.php @@ -64,24 +64,31 @@ class ModelExtensionRetailcrmOrder extends Model { return false; } - $customers = $retailcrmApiClient->customersList( - array( - 'name' => $order_data['telephone'], - 'email' => $order_data['email'] - ), - 1, - 100 - ); - $order = $this->process($order_data); - if ($customers) { - foreach ($customers['customers'] as $customer) { - $order['customer']['id'] = $customer['id']; - } - } + if (isset($order['customer']['externalId'])) { + $this->load->model('extension/retailcrm/customer'); + $this->load->model('customer/customer'); + $customer = $this->model_customer_customer->getCustomer($order['customer']['externalId']); + $this->model_extension_retailcrm_customer->sendToCrm($customer, $retailcrmApiClient); + } else { + $customers = $retailcrmApiClient->customersList( + array( + 'name' => $order_data['telephone'], + 'email' => $order_data['email'] + ), + 1, + 100 + ); - unset($customers); + if ($customers) { + foreach ($customers['customers'] as $customer) { + $order['customer']['id'] = $customer['id']; + } + } + + unset($customers); + } self::$lastRepsonse = $retailcrmApiClient->ordersCreate($order); diff --git a/tests/admin/ModelRetailcrmOrderAdminTest.php b/tests/admin/ModelRetailcrmOrderAdminTest.php index 155c4b8..3ed8d70 100644 --- a/tests/admin/ModelRetailcrmOrderAdminTest.php +++ b/tests/admin/ModelRetailcrmOrderAdminTest.php @@ -23,7 +23,8 @@ class ModelRetailcrmOrderAdminTest extends OpenCartTest 'ordersUpload', 'customersList', 'ordersCreate', - 'ordersPaymentCreate' + 'ordersPaymentCreate', + 'customersCreate' )) ->getMock();