Skip to content

Commit

Permalink
Merge pull request #127 from iyzoer/master
Browse files Browse the repository at this point in the history
v3.2.1
  • Loading branch information
gwinn authored Jan 18, 2019
2 parents ee36226 + c273831 commit db80810
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ deploy:
on:
php: 7.1
branch: master
condition: "$DEPLOY = true"
condition: "$DEPLOY = true"
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## v.3.2.1
* Изменена логика передачи данных по заказам и клиентам. Контактные данные по доставке передаются в карточку заказа, контактные данные плательщика в карточку клиента.

## v.3.2.0
* Добавлена выгрузка картинок для категорий в ICML
* Добавлена настройка для выбора валюты, в которой будет выгружаться цена в ICML
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.2.0
3.2.1
5 changes: 5 additions & 0 deletions src/upload/admin/model/extension/retailcrm/history/v4_5.php
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,11 @@ protected function updateCustomers($customers)
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'];
Expand Down
35 changes: 33 additions & 2 deletions src/upload/admin/model/extension/retailcrm/order.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,37 @@ public function uploadOrder($order_data, $retailcrmApiClient)
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;
Expand Down Expand Up @@ -152,8 +183,8 @@ private function process($order_data) {
}

$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'];

Expand Down
28 changes: 13 additions & 15 deletions src/upload/catalog/controller/extension/module/retailcrm.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,21 @@ public function order_create($trigger, $data, $order_id = null) {
}
}

if (!isset($data['fromApi'])) {
$this->load->model('setting/setting');
$status = $this->model_setting_setting->getSetting($moduleTitle);
$this->load->model('setting/setting');
$status = $this->model_setting_setting->getSetting($moduleTitle);

if (isset($data['order_status_id']) && $data['order_status_id'] > 0) {
$data['order_status'] = $status[$moduleTitle . '_status'][$data['order_status_id']];
}
if (isset($data['order_status_id']) && $data['order_status_id'] > 0) {
$data['order_status'] = $status[$moduleTitle . '_status'][$data['order_status_id']];
}

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);
} else {
$this->load->model('extension/retailcrm/order');
$order = $this->model_extension_retailcrm_order->processOrder($data);
$this->model_extension_retailcrm_order->sendToCrm($order, $this->retailcrmApiClient);
}
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, $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, $data, $this->retailcrmApiClient);
}
}

Expand Down
44 changes: 38 additions & 6 deletions src/upload/catalog/model/extension/retailcrm/order.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ public function __construct($registry) {
*
* @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;
}

Expand All @@ -35,6 +36,37 @@ public function sendToCrm($order, $retailcrmApiClient, $create = true) {
}
}

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 {
Expand Down Expand Up @@ -98,8 +130,8 @@ public function processOrder($order_data, $create = true) {
}
}

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'])
Expand All @@ -109,8 +141,8 @@ public function processOrder($order_data, $create = true) {
}

$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'];

Expand Down
3 changes: 2 additions & 1 deletion tests/admin/ModelRetailcrmOrderAdminTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ public function testUploadWithoutCustomerTest()
);

$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);
Expand All @@ -181,7 +182,7 @@ public function testUploadWithoutCustomerTest()
$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']);
}
}
8 changes: 5 additions & 3 deletions tests/catalog/ModelRetailcrmOrderCatalogTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public function setUp()
'ordersEdit',
'ordersGet',
'ordersPaymentEdit',
'customersList'
'customersList',
'customersCreate'
))
->getMock();

Expand Down Expand Up @@ -65,7 +66,7 @@ public function testCreateOrderWithCustomer()
}

$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']);
Expand Down Expand Up @@ -135,8 +136,9 @@ public function testEditOrderWithCustomer()

$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']);
Expand Down

0 comments on commit db80810

Please sign in to comment.