Skip to content

Commit

Permalink
Merge pull request #146 from sergeygw1990/master
Browse files Browse the repository at this point in the history
v3.3.0
  • Loading branch information
gwinn authored Mar 21, 2019
2 parents c057540 + 3d9b517 commit 702c18d
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## v.3.3.0
* Добавена настройка записи истории изменения заказов в Opencart
* Устранен баг с вызовом события редактирования заказа при выгрузке истории изменений из retailCRM
* Добавлена передача типа цены при создании и редактировании заказа

## v.3.2.4
* Добавлена возможность передачи акционных цен для нескольких групп пользователей
Expand Down
20 changes: 19 additions & 1 deletion src/upload/catalog/model/extension/retailcrm/order.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ public function sendToCrm($order, $retailcrmApiClient, $data, $create = true) {
public function processOrder($order_data, $create = true) {
$this->load->model('setting/setting');
$this->load->model('catalog/product');
$this->load->model('account/customer');
$this->load->model('extension/retailcrm/product');
$this->settings = $this->model_setting_setting->getSetting($this->moduleTitle);
$order_id = $order_data['order_id'];

Expand Down Expand Up @@ -255,8 +257,24 @@ public function processOrder($order_data, $create = true) {
),
'productName' => $product['name'],
'initialPrice' => $product['price'],
'quantity' => $product['quantity'],
'quantity' => $product['quantity']
);

$specials = $this->model_extension_retailcrm_product->getProductSpecials($product['product_id']);

if (!empty($specials)) {
$customer = $this->model_account_customer->getCustomer($order_data['customer_id']);

foreach ($specials as $special) {
if (isset($customer['customer_group_id'])) {
if ($special['customer_group_id'] == $customer['customer_group_id']) {
if ($this->settings[$this->moduleTitle . '_special_' . $customer['customer_group_id']]) {
$item['priceType']['code'] = $this->settings[$this->moduleTitle . '_special_' . $customer['customer_group_id']];
}
}
}
}
}
} else {
$item = array(
'productName' => $product['name'],
Expand Down
10 changes: 10 additions & 0 deletions src/upload/catalog/model/extension/retailcrm/product.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

class ModelExtensionRetailcrmProduct extends Model
{
public function getProductSpecials($product_id) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_special WHERE product_id = '" . (int)$product_id . "' ORDER BY priority, price");

return $query->rows;
}
}
21 changes: 20 additions & 1 deletion tests/catalog/ModelRetailcrmOrderCatalogTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ public function setUp()
),
$this->retailcrm->getModuleTitle() . '_payment' => array(
'cod' => 'cod'
)
),
$this->retailcrm->getModuleTitle() . '_special_1' => 'special1',
$this->retailcrm->getModuleTitle() . '_special_2' => 'special2',
$this->retailcrm->getModuleTitle() . '_special_3' => 'special3'
)
);
}
Expand Down Expand Up @@ -88,6 +91,12 @@ public function testCreateOrderWithCustomer()
$this->assertEquals('Rostov-na-Donu', $orderSend['delivery']['address']['region']);
$this->assertEquals('111111', $orderSend['delivery']['address']['index']);
$this->assertArrayHasKey('items', $orderSend);

foreach($orderSend['items'] as $item) {
$this->assertArrayHasKey('priceType', $item);
$this->assertEquals('special1', $item['priceType']['code']);
}

$this->assertArrayHasKey('customerComment', $orderSend);
$this->assertArrayHasKey('customer', $orderSend);
$this->assertArrayHasKey('externalId', $orderSend['customer']);
Expand Down Expand Up @@ -160,6 +169,12 @@ public function testEditOrderWithCustomer()
$this->assertEquals('Rostov-na-Donu', $orderSend['delivery']['address']['region']);
$this->assertEquals('111111', $orderSend['delivery']['address']['index']);
$this->assertArrayHasKey('items', $orderSend);

foreach($orderSend['items'] as $item) {
$this->assertArrayHasKey('priceType', $item);
$this->assertEquals('special1', $item['priceType']['code']);
}

$this->assertArrayHasKey('customerComment', $orderSend);
}

Expand Down Expand Up @@ -211,6 +226,10 @@ public function testOrderCreateWithoutCustomerTest()
$this->assertArrayNotHasKey('externalId', $orderSend['customer']);
$this->assertArrayHasKey('id', $orderSend['customer']);
$this->assertEquals(1, $orderSend['customer']['id']);

foreach($orderSend['items'] as $item) {
$this->assertArrayNotHasKey('priceType', $item);
}
}

protected function setSetting($code, $data, $store_id = 0) {
Expand Down
1 change: 1 addition & 0 deletions tests/opencart_sample_data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@ INSERT INTO `oc_order_total` (`order_total_id`, `order_id`, `code`, `title`, `va
INSERT INTO `oc_order_total` (`order_total_id`, `order_id`, `code`, `title`, `value`, `sort_order`) VALUES ('163', '1', 'total', 'Total', '106.0000', '9');
INSERT INTO `oc_order_total` (`order_total_id`, `order_id`, `code`, `title`, `value`, `sort_order`) VALUES ('166', '2', 'total', 'Total', '85.0000', '9');
INSERT INTO `oc_product_special` (`product_id`, `customer_group_id`, `priority`, `price`,`date_start`, `date_end`) values ('42', '2', '1', '110.000', CURDATE(), ADDDATE(CURDATE(),INTERVAL 10 DAY));
INSERT INTO `oc_product_special` (`product_id`, `customer_group_id`, `priority`, `price`,`date_start`, `date_end`) values ('40', '1', '1', '50.000', CURDATE(), ADDDATE(CURDATE(),INTERVAL 10 DAY));

TRUNCATE TABLE `oc_order_voucher`;

0 comments on commit 702c18d

Please sign in to comment.