closes #170; Add voucher cost to discount

This commit is contained in:
Daniel Weiser 2020-09-16 10:22:43 +03:00
parent 2dbccd8a02
commit 85f47c1984
2 changed files with 90 additions and 45 deletions

View File

@ -85,6 +85,10 @@ class RetailcrmOrderConverter {
$discount += abs($this->getTotal('reward')); $discount += abs($this->getTotal('reward'));
} }
if (!empty($this->getTotal('voucher'))) {
$discount += abs($this->getTotal('voucher'));
}
if ($discount > 0) { if ($discount > 0) {
$this->data['discountManualAmount'] = $discount; $this->data['discountManualAmount'] = $discount;
} }

View File

@ -15,18 +15,7 @@ class OrderManagerTest extends TestCase {
$proxy->expects($this->once())->method('ordersCreate'); $proxy->expects($this->once())->method('ordersCreate');
$customer_manager = new \retailcrm\service\CustomerManager( $order_manager = $this->getOrderManager($proxy);
$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);
$orderCheckoutModel = $this->loadModel('checkout/order'); $orderCheckoutModel = $this->loadModel('checkout/order');
$orderAccountModel = $this->loadModel('account/order'); $orderAccountModel = $this->loadModel('account/order');
@ -76,17 +65,7 @@ class OrderManagerTest extends TestCase {
) )
)); ));
$customer_manager = new \retailcrm\service\CustomerManager( $order_manager = $this->getOrderManager($proxy);
$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);
$orderCheckoutModel = $this->loadModel('checkout/order'); $orderCheckoutModel = $this->loadModel('checkout/order');
$orderAccountModel = $this->loadModel('account/order'); $orderAccountModel = $this->loadModel('account/order');
@ -143,17 +122,7 @@ class OrderManagerTest extends TestCase {
) )
)); ));
$customer_manager = new \retailcrm\service\CustomerManager( $order_manager = $this->getOrderManager($proxy);
$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);
$orderCheckoutModel = $this->loadModel('checkout/order'); $orderCheckoutModel = $this->loadModel('checkout/order');
$orderAccountModel = $this->loadModel('account/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('ordersGet')->willReturn($ordersGetResponse);
$proxy->expects($this->once())->method('ordersPaymentEdit'); $proxy->expects($this->once())->method('ordersPaymentEdit');
$customer_manager = new \retailcrm\service\CustomerManager( $order_manager = $this->getOrderManager($proxy);
$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);
$orderCheckoutModel = $this->loadModel('checkout/order'); $orderCheckoutModel = $this->loadModel('checkout/order');
$orderAccountModel = $this->loadModel('account/order'); $orderAccountModel = $this->loadModel('account/order');
@ -233,6 +192,50 @@ class OrderManagerTest extends TestCase {
$order_manager->editOrder($order, $products, $totals); $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) private function getOrder($id)
{ {
return array( 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",
),
);
}
} }