From 85f47c198449a6fd4f46c81e6abf46b5dce671cc Mon Sep 17 00:00:00 2001 From: Daniel Weiser Date: Wed, 16 Sep 2020 10:22:43 +0300 Subject: [PATCH 1/2] closes #170; Add voucher cost to discount --- .../lib/service/RetailcrmOrderConverter.php | 4 + tests/system/lib/service/OrderManagerTest.php | 131 ++++++++++++------ 2 files changed, 90 insertions(+), 45 deletions(-) diff --git a/src/upload/system/library/retailcrm/lib/service/RetailcrmOrderConverter.php b/src/upload/system/library/retailcrm/lib/service/RetailcrmOrderConverter.php index 68d203c..35e09d1 100644 --- a/src/upload/system/library/retailcrm/lib/service/RetailcrmOrderConverter.php +++ b/src/upload/system/library/retailcrm/lib/service/RetailcrmOrderConverter.php @@ -85,6 +85,10 @@ class RetailcrmOrderConverter { $discount += abs($this->getTotal('reward')); } + if (!empty($this->getTotal('voucher'))) { + $discount += abs($this->getTotal('voucher')); + } + if ($discount > 0) { $this->data['discountManualAmount'] = $discount; } diff --git a/tests/system/lib/service/OrderManagerTest.php b/tests/system/lib/service/OrderManagerTest.php index 9063755..dd809b9 100644 --- a/tests/system/lib/service/OrderManagerTest.php +++ b/tests/system/lib/service/OrderManagerTest.php @@ -15,18 +15,7 @@ class OrderManagerTest extends TestCase { $proxy->expects($this->once())->method('ordersCreate'); - $customer_manager = new \retailcrm\service\CustomerManager( - $proxy, - \retailcrm\factory\CustomerConverterFactory::create(static::$registry) - ); - - $converter = \retailcrm\factory\OrderConverterFactory::create(static::$registry); - $corporate_customer = new \retailcrm\service\CorporateCustomer( - $proxy, new \retailcrm\repository\CustomerRepository(static::$registry) - ); - $settings_manager = new \retailcrm\service\SettingsManager(static::$registry); - - $order_manager = new \retailcrm\service\OrderManager($proxy, $customer_manager, $converter, $corporate_customer, $settings_manager); + $order_manager = $this->getOrderManager($proxy); $orderCheckoutModel = $this->loadModel('checkout/order'); $orderAccountModel = $this->loadModel('account/order'); @@ -76,17 +65,7 @@ class OrderManagerTest extends TestCase { ) )); - $customer_manager = new \retailcrm\service\CustomerManager( - $proxy, - \retailcrm\factory\CustomerConverterFactory::create(static::$registry) - ); - - $converter = \retailcrm\factory\OrderConverterFactory::create(static::$registry); - $corporate_customer = new \retailcrm\service\CorporateCustomer( - $proxy, new \retailcrm\repository\CustomerRepository(static::$registry) - ); - $settings_manager = new \retailcrm\service\SettingsManager(static::$registry); - $order_manager = new \retailcrm\service\OrderManager($proxy, $customer_manager, $converter, $corporate_customer, $settings_manager); + $order_manager = $this->getOrderManager($proxy); $orderCheckoutModel = $this->loadModel('checkout/order'); $orderAccountModel = $this->loadModel('account/order'); @@ -143,17 +122,7 @@ class OrderManagerTest extends TestCase { ) )); - $customer_manager = new \retailcrm\service\CustomerManager( - $proxy, - \retailcrm\factory\CustomerConverterFactory::create(static::$registry) - ); - - $converter = \retailcrm\factory\OrderConverterFactory::create(static::$registry); - $corporate_customer = new \retailcrm\service\CorporateCustomer( - $proxy, new \retailcrm\repository\CustomerRepository(static::$registry) - ); - $settings_manager = new \retailcrm\service\SettingsManager(static::$registry); - $order_manager = new \retailcrm\service\OrderManager($proxy, $customer_manager, $converter, $corporate_customer, $settings_manager); + $order_manager = $this->getOrderManager($proxy); $orderCheckoutModel = $this->loadModel('checkout/order'); $orderAccountModel = $this->loadModel('account/order'); @@ -203,17 +172,7 @@ class OrderManagerTest extends TestCase { $proxy->expects($this->once())->method('ordersGet')->willReturn($ordersGetResponse); $proxy->expects($this->once())->method('ordersPaymentEdit'); - $customer_manager = new \retailcrm\service\CustomerManager( - $proxy, - \retailcrm\factory\CustomerConverterFactory::create(static::$registry) - ); - - $converter = \retailcrm\factory\OrderConverterFactory::create(static::$registry); - $settings_manager = new \retailcrm\service\SettingsManager(static::$registry); - $corporate_customer = new \retailcrm\service\CorporateCustomer( - $proxy, new \retailcrm\repository\CustomerRepository(static::$registry) - ); - $order_manager = new \retailcrm\service\OrderManager($proxy, $customer_manager, $converter, $corporate_customer, $settings_manager); + $order_manager = $this->getOrderManager($proxy); $orderCheckoutModel = $this->loadModel('checkout/order'); $orderAccountModel = $this->loadModel('account/order'); @@ -233,6 +192,50 @@ class OrderManagerTest extends TestCase { $order_manager->editOrder($order, $products, $totals); } + public function testPrepareOrderTotals() { + $proxy = $this->getMockBuilder(\RetailcrmProxy::class) + ->disableOriginalConstructor() + ->getMock(); + + $order_manager = $this->getOrderManager($proxy); + + $orderCheckoutModel = $this->loadModel('checkout/order'); + $orderAccountModel = $this->loadModel('account/order'); + $order_id = self::ORDER_WITH_CUST_ID; + $order = $orderCheckoutModel->getOrder($order_id); + $products = $orderAccountModel->getOrderProducts($order_id); + $totals = $this->getOrderTotals($order_id); + + foreach ($products as $key => $product) { + $productOptions = $orderAccountModel->getOrderOptions($order_id, $product['order_product_id']); + + if (!empty($productOptions)) { + $products[$key]['option'] = $productOptions; + } + } + + $data = $order_manager->prepareOrder($order, $products, $totals); + + $this->assertEquals(15, $data['discountManualAmount']); + $this->assertEquals(115, $data['payments'][0]['amount']); + } + + private function getOrderManager($proxy) + { + $customer_manager = new \retailcrm\service\CustomerManager( + $proxy, + \retailcrm\factory\CustomerConverterFactory::create(static::$registry) + ); + + $converter = \retailcrm\factory\OrderConverterFactory::create(static::$registry); + $corporate_customer = new \retailcrm\service\CorporateCustomer( + $proxy, new \retailcrm\repository\CustomerRepository(static::$registry) + ); + $settings_manager = new \retailcrm\service\SettingsManager(static::$registry); + + return new \retailcrm\service\OrderManager($proxy, $customer_manager, $converter, $corporate_customer, $settings_manager); + } + private function getOrder($id) { return array( @@ -247,4 +250,42 @@ class OrderManagerTest extends TestCase { ) ); } + + private function getOrderTotals($id) + { + return array( + array( + "order_total_id" => "1", + "order_id" => $id, + "code" => "total", + "title" => "Total", + "value" => "115", + "sort_order" => "9", + ), + array( + "order_total_id" => "2", + "order_id" => $id, + "code" => "sub_total", + "title" => "Sum", + "value" => "110", + "sort_order" => "1", + ), + array( + "order_total_id" => "3", + "order_id" => $id, + "code" => "voucher", + "title" => "Voucher", + "value" => "15", + "sort_order" => "9", + ), + array( + "order_total_id" => "4", + "order_id" => $id, + "code" => "shipping", + "title" => "Flat Shipping Rate", + "value" => "5", + "sort_order" => "3", + ), + ); + } } From 2dbb56897e881058876ed2a3d757b2089ed808e0 Mon Sep 17 00:00:00 2001 From: Daniel Weiser Date: Wed, 16 Sep 2020 14:24:31 +0300 Subject: [PATCH 2/2] Upgrade version --- CHANGELOG.md | 3 +++ VERSION | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a7f6f5a..16a5ece 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## v.4.1.2 +* Добавлен учет стоимости подарочного сертификата при формировании заказа и передаче его в retailCRM + ## v.4.1.1 * Обновлена механика обработки адресов покупателей diff --git a/VERSION b/VERSION index 627a3f4..4d0dcda 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.1.1 +4.1.2