diff --git a/CHANGELOG.md b/CHANGELOG.md index adb15c5..df4aeb7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## v.3.2.2 +* Убрана генерация externalId покупателя при заказе без регистрации на сайте. + ## v.3.2.1 * Изменена логика передачи данных по заказам и клиентам. Контактные данные по доставке передаются в карточку заказа, контактные данные плательщика в карточку клиента. diff --git a/VERSION b/VERSION index e4604e3..be94e6f 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.2.1 +3.2.2 diff --git a/src/upload/admin/model/extension/retailcrm/order.php b/src/upload/admin/model/extension/retailcrm/order.php index 4a3cd83..1046d6d 100644 --- a/src/upload/admin/model/extension/retailcrm/order.php +++ b/src/upload/admin/model/extension/retailcrm/order.php @@ -48,7 +48,7 @@ class ModelExtensionRetailcrmOrder extends Model { /** * Send one order by id - * + * * @param array $order_data * @param \RetailcrmProxy $retailcrmApiClient * @@ -92,7 +92,6 @@ class ModelExtensionRetailcrmOrder extends Model { if (!isset($order['customer']['externalId']) && !isset($order['customer']['id'])) { $new_customer = array( - 'externalId' => uniqid(), 'firstName' => $order_data['firstname'], 'lastName' => $order_data['lastname'], 'email' => $order_data['email'], @@ -128,9 +127,9 @@ class ModelExtensionRetailcrmOrder extends Model { /** * Process order - * + * * @param array $order_data - * + * * @return array $order */ private function process($order_data) { diff --git a/src/upload/catalog/model/extension/retailcrm/order.php b/src/upload/catalog/model/extension/retailcrm/order.php index fd79533..9991a86 100644 --- a/src/upload/catalog/model/extension/retailcrm/order.php +++ b/src/upload/catalog/model/extension/retailcrm/order.php @@ -38,7 +38,6 @@ class ModelExtensionRetailcrmOrder extends Model { if (!isset($order['customer']['externalId']) && !isset($order['customer']['id'])) { $new_customer = array( - 'externalId' => uniqid(), 'firstName' => $data['firstname'], 'lastName' => $data['lastname'], 'email' => $data['email'], @@ -227,7 +226,7 @@ class ModelExtensionRetailcrmOrder extends Model { 'value' => $option['value'] ); } - + if (!in_array($option['type'], $offerOptions)) continue; foreach($productOptions as $productOption) { if($productOption['product_option_id'] = $option['product_option_id']) { diff --git a/tests/admin/ModelRetailcrmOrderAdminTest.php b/tests/admin/ModelRetailcrmOrderAdminTest.php index e789866..6603d92 100644 --- a/tests/admin/ModelRetailcrmOrderAdminTest.php +++ b/tests/admin/ModelRetailcrmOrderAdminTest.php @@ -183,6 +183,8 @@ class ModelRetailcrmOrderAdminTest extends OpenCartTest $this->assertArrayHasKey('payments', $orderSend); $this->assertArrayHasKey('customerComment', $orderSend); $this->assertArrayHasKey('customer', $orderSend); + $this->assertArrayNotHasKey('externalId', $orderSend['customer']); + $this->assertArrayHasKey('id', $orderSend['customer']); $this->assertNotEmpty($orderSend['payments']); } } diff --git a/tests/catalog/ModelRetailcrmOrderCatalogTest.php b/tests/catalog/ModelRetailcrmOrderCatalogTest.php index c9786fc..0bc7122 100644 --- a/tests/catalog/ModelRetailcrmOrderCatalogTest.php +++ b/tests/catalog/ModelRetailcrmOrderCatalogTest.php @@ -163,6 +163,56 @@ class ModelRetailcrmOrderCatalogTest extends OpenCartTest $this->assertArrayHasKey('customerComment', $orderSend); } + public function testOrderCreateWithoutCustomerTest() + { + $order_id = self::ORDER_ID; + $orderCheckoutModel = $this->loadModel('checkout/order'); + $orderAccountModel = $this->loadModel('account/order'); + $order = $orderCheckoutModel->getOrder($order_id); + $order['products'] = $orderAccountModel->getOrderProducts($order_id); + $order['totals'] = $orderAccountModel->getOrderTotals($order_id); + + foreach($order['products'] as $key => $product) { + $order['products'][$key]['option'] = $orderAccountModel->getOrderOptions($product['order_id'], $product['order_product_id']); + } + + $responseCustomerCreate = new \RetailcrmApiResponse( + 201, + json_encode( + array( + 'success' => true, + 'id' => 1 + ) + ) + ); + + $responseCustomerList = new \RetailcrmApiResponse( + 201, + json_encode( + array( + 'success' => true, + "pagination"=> [ + "limit"=>20, + "totalCount"=> 0, + "currentPage"=> 1, + "totalPageCount"=> 0 + ], + "customers"=> [] + ) + ) + ); + + $this->apiClientMock->expects($this->any())->method('customersList')->willReturn($responseCustomerList); + $this->apiClientMock->expects($this->any())->method('customersCreate')->willReturn($responseCustomerCreate); + $orderProcess = $this->orderModel->processOrder($order); + $orderSend = $this->orderModel->sendToCrm($orderProcess, $this->apiClientMock, $order); + + $this->assertArrayHasKey('customer', $orderSend); + $this->assertArrayNotHasKey('externalId', $orderSend['customer']); + $this->assertArrayHasKey('id', $orderSend['customer']); + $this->assertEquals(1, $orderSend['customer']['id']); + } + protected function setSetting($code, $data, $store_id = 0) { $this->db->query("DELETE FROM `" . DB_PREFIX . "setting` WHERE store_id = '" . (int)$store_id . "' AND `code` = '" . $this->db->escape($code) . "'");