This commit is contained in:
Akolzin Dmitry 2019-01-18 09:52:08 +03:00
parent ee36226b31
commit ed5de5186e
9 changed files with 101 additions and 29 deletions

View File

@ -26,7 +26,7 @@ before_script:
- composer install
- composer setup
- bin/robo project:deploy
- (php -S localhost:8000 -t www &) 2> /dev/null > /dev/null
- (php -S localhost:8000 -t www &) 2> /dev/null > /dev/null(php -S localhost:8000 -t www &) 2> /dev/null > /dev/null
- sleep 2
script:

View File

@ -1,3 +1,6 @@
## v.3.2.1
* Изменена логика передачи данных по заказам и клиентам. Контактные данные по доставке передаются в карточку заказа, контактные данные плательщика в карточку клиента.
## v.3.2.0
* Добавлена выгрузка картинок для категорий в ICML
* Добавлена настройка для выбора валюты, в которой будет выгружаться цена в ICML

View File

@ -1 +1 @@
3.2.0
3.2.1

View File

@ -777,6 +777,11 @@ class ModelExtensionRetailcrmHistoryV45 extends ModelExtensionRetailcrmHistory
foreach ($customers as $customer) {
$customer_id = $customer['externalId'];
$customerData = $this->model_customer_customer->getCustomer($customer_id);
if (!$customerData) {
continue;
}
$customerData['password'] = false;
$customerData['firstname'] = $customer['firstName'];

View File

@ -90,6 +90,37 @@ class ModelExtensionRetailcrmOrder extends Model {
unset($customers);
}
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'],
'createdAt' => $order_data['date_added'],
'address' => array(
'countryIso' => $order_data['payment_iso_code_2'],
'index' => $order_data['payment_postcode'],
'city' => $order_data['payment_city'],
'region' => $order_data['payment_zone'],
'text' => $order_data['payment_address_1'] . ' ' . $order_data['payment_address_2']
)
);
if (!empty($order_data['telephone'])) {
$new_customer['phones'] = array(
array(
'number' => $order_data['telephone']
)
);
}
$res = $retailcrmApiClient->customersCreate($new_customer);
if ($res->isSuccessful() && isset($res['id'])) {
$order['customer']['id'] = $res['id'];
}
}
self::$lastRepsonse = $retailcrmApiClient->ordersCreate($order);
return $order;
@ -152,8 +183,8 @@ class ModelExtensionRetailcrmOrder extends Model {
}
$order['externalId'] = $order_data['order_id'];
$order['firstName'] = $order_data['firstname'];
$order['lastName'] = $order_data['lastname'];
$order['firstName'] = $order_data['shipping_firstname'];
$order['lastName'] = $order_data['shipping_lastname'];
$order['phone'] = $order_data['telephone'];
$order['customerComment'] = $order_data['comment'];

View File

@ -48,7 +48,6 @@ class ControllerExtensionModuleRetailcrm extends Controller {
}
}
if (!isset($data['fromApi'])) {
$this->load->model('setting/setting');
$status = $this->model_setting_setting->getSetting($moduleTitle);
@ -59,12 +58,11 @@ class ControllerExtensionModuleRetailcrm extends Controller {
if (file_exists(DIR_APPLICATION . 'model/extension/retailcrm/custom/order.php')) {
$this->load->model('extension/retailcrm/custom/order');
$order = $this->model_extension_retailcrm_custom_order->processOrder($data);
$this->model_extension_retailcrm_custom_order->sendToCrm($order, $this->retailcrmApiClient);
$this->model_extension_retailcrm_custom_order->sendToCrm($order, $data, $this->retailcrmApiClient);
} else {
$this->load->model('extension/retailcrm/order');
$order = $this->model_extension_retailcrm_order->processOrder($data);
$this->model_extension_retailcrm_order->sendToCrm($order, $this->retailcrmApiClient);
}
$this->model_extension_retailcrm_order->sendToCrm($order, $data, $this->retailcrmApiClient);
}
}

View File

@ -18,12 +18,13 @@ class ModelExtensionRetailcrmOrder extends Model {
*
* @param array $order
* @param \RetailcrmProxy $retailcrmApiClient
* @param array $data
* @param bool $create (default = true)
*
* @return mixed
*/
public function sendToCrm($order, $retailcrmApiClient, $create = true) {
if (isset($this->request->post['fromApi']) || $retailcrmApiClient === false) {
public function sendToCrm($order, $retailcrmApiClient, $data, $create = true) {
if ($retailcrmApiClient === false) {
return false;
}
@ -35,6 +36,37 @@ 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'],
'createdAt' => $data['date_added'],
'address' => array(
'countryIso' => $data['payment_iso_code_2'],
'index' => $data['payment_postcode'],
'city' => $data['payment_city'],
'region' => $data['payment_zone'],
'text' => $data['payment_address_1'] . ' ' . $data['payment_address_2']
)
);
if (!empty($data['telephone'])) {
$new_customer['phones'] = array(
array(
'number' => $data['telephone']
)
);
}
$res = $retailcrmApiClient->customersCreate($new_customer);
if ($res->isSuccessful() && isset($res['id'])) {
$order['customer']['id'] = $res['id'];
}
}
if ($create) {
$retailcrmApiClient->ordersCreate($order);
} else {
@ -98,8 +130,8 @@ class ModelExtensionRetailcrmOrder extends Model {
}
}
if (!empty($order_data['payment_iso_code_2'])) {
$order['countryIso'] = $order_data['payment_iso_code_2'];
if (!empty($order_data['shipping_iso_code_2'])) {
$order['countryIso'] = $order_data['shipping_iso_code_2'];
}
if (isset($this->settings[$this->moduleTitle . '_order_number'])
@ -109,8 +141,8 @@ class ModelExtensionRetailcrmOrder extends Model {
}
$order['externalId'] = $order_id;
$order['firstName'] = $order_data['firstname'];
$order['lastName'] = $order_data['lastname'];
$order['firstName'] = $order_data['shipping_firstname'];
$order['lastName'] = $order_data['shipping_lastname'];
$order['phone'] = $order_data['telephone'];
$order['customerComment'] = $order_data['comment'];

View File

@ -166,6 +166,7 @@ class ModelRetailcrmOrderAdminTest extends OpenCartTest
);
$this->apiClientMock->expects($this->any())->method('ordersCreate')->willReturn($response);
$this->apiClientMock->expects($this->any())->method('customersCreate')->willReturn($response);
$orderSend = $this->orderModel->uploadOrder($order, $this->apiClientMock);
$this->assertArrayHasKey('status', $orderSend);
@ -181,7 +182,7 @@ class ModelRetailcrmOrderAdminTest extends OpenCartTest
$this->assertContains('#', $orderSend['items'][0]['offer']['externalId']);
$this->assertArrayHasKey('payments', $orderSend);
$this->assertArrayHasKey('customerComment', $orderSend);
$this->assertArrayNotHasKey('customer', $orderSend);
$this->assertArrayHasKey('customer', $orderSend);
$this->assertNotEmpty($orderSend['payments']);
}
}

View File

@ -23,7 +23,8 @@ class ModelRetailcrmOrderCatalogTest extends OpenCartTest
'ordersEdit',
'ordersGet',
'ordersPaymentEdit',
'customersList'
'customersList',
'customersCreate'
))
->getMock();
@ -65,7 +66,7 @@ class ModelRetailcrmOrderCatalogTest extends OpenCartTest
}
$orderProcess = $this->orderModel->processOrder($order);
$orderSend = $this->orderModel->sendToCrm($orderProcess, $this->apiClientMock);
$orderSend = $this->orderModel->sendToCrm($orderProcess, $this->apiClientMock, $order);
$this->assertArrayHasKey('status', $orderSend);
$this->assertEquals('new', $orderSend['status']);
@ -135,8 +136,9 @@ class ModelRetailcrmOrderCatalogTest extends OpenCartTest
$this->apiClientMock->expects($this->any())->method('ordersEdit')->willReturn($orderEditResponse);
$this->apiClientMock->expects($this->any())->method('ordersGet')->willReturn($ordersGetResponse);
$this->apiClientMock->expects($this->any())->method('customersCreate')->willReturn($orderEditResponse);
$orderProcess = $this->orderModel->processOrder($order);
$orderSend = $this->orderModel->sendToCrm($orderProcess, $this->apiClientMock, false);
$orderSend = $this->orderModel->sendToCrm($orderProcess, $this->apiClientMock, $order, false);
$this->assertArrayHasKey('status', $orderSend);
$this->assertEquals('new', $orderSend['status']);