diff --git a/CHANGELOG.md b/CHANGELOG.md index 115a90f..2aba642 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## v.3.3.0 * Добавена настройка записи истории изменения заказов в Opencart * Устранен баг с вызовом события редактирования заказа при выгрузке истории изменений из retailCRM +* Добавлена передача типа цены при создании и редактировании заказа ## v.3.2.4 * Добавлена возможность передачи акционных цен для нескольких групп пользователей diff --git a/src/upload/catalog/model/extension/retailcrm/order.php b/src/upload/catalog/model/extension/retailcrm/order.php index 9991a86..c844c9b 100644 --- a/src/upload/catalog/model/extension/retailcrm/order.php +++ b/src/upload/catalog/model/extension/retailcrm/order.php @@ -92,6 +92,8 @@ class ModelExtensionRetailcrmOrder extends Model { 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']; @@ -255,8 +257,24 @@ class ModelExtensionRetailcrmOrder extends Model { ), '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'], diff --git a/src/upload/catalog/model/extension/retailcrm/product.php b/src/upload/catalog/model/extension/retailcrm/product.php new file mode 100644 index 0000000..f638064 --- /dev/null +++ b/src/upload/catalog/model/extension/retailcrm/product.php @@ -0,0 +1,10 @@ +db->query("SELECT * FROM " . DB_PREFIX . "product_special WHERE product_id = '" . (int)$product_id . "' ORDER BY priority, price"); + + return $query->rows; + } +} \ No newline at end of file diff --git a/tests/catalog/ModelRetailcrmOrderCatalogTest.php b/tests/catalog/ModelRetailcrmOrderCatalogTest.php index 0bc7122..4c72025 100644 --- a/tests/catalog/ModelRetailcrmOrderCatalogTest.php +++ b/tests/catalog/ModelRetailcrmOrderCatalogTest.php @@ -43,7 +43,10 @@ class ModelRetailcrmOrderCatalogTest extends OpenCartTest ), $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' ) ); } @@ -88,6 +91,12 @@ class ModelRetailcrmOrderCatalogTest extends OpenCartTest $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']); @@ -160,6 +169,12 @@ class ModelRetailcrmOrderCatalogTest extends OpenCartTest $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); } @@ -211,6 +226,10 @@ class ModelRetailcrmOrderCatalogTest extends OpenCartTest $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) { diff --git a/tests/opencart_sample_data.sql b/tests/opencart_sample_data.sql index c3c3057..bcb8974 100644 --- a/tests/opencart_sample_data.sql +++ b/tests/opencart_sample_data.sql @@ -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`; \ No newline at end of file