1
0
mirror of synced 2025-01-18 08:51:41 +03:00

Correct send and calculate discount (#159)

This commit is contained in:
Dima Uryvskiy 2020-09-28 13:42:35 +03:00 committed by GitHub
parent 155a2d5716
commit 30cd87cad9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 7 deletions

View File

@ -721,17 +721,27 @@ if ( ! class_exists( 'WC_Retailcrm_History' ) ) :
continue; continue;
} }
if (isset($product['discountTotal']) && $product['discountTotal'] > 0) {
$item->set_price($product['initialPrice'] - $product['discountTotal']);
}
foreach ($wc_order->get_items() as $order_item_id => $order_item) { foreach ($wc_order->get_items() as $order_item_id => $order_item) {
$arItemsOld[$order_item_id] = $order_item_id; $arItemsOld[$order_item_id] = $order_item_id;
} }
$wc_order->add_product( $wc_order->add_product(
$item, $item,
$product['quantity'] $product['quantity'],
array(
'subtotal' => wc_get_price_excluding_tax(
$item,
array(
'price' => $product['initialPrice'],
'qty' => $product['quantity'],)
),
'total' => wc_get_price_excluding_tax(
$item,
array(
'price' => $product['initialPrice'] - $product['discountTotal'],
'qty' => $product['quantity'],)
),
)
); );
foreach ($wc_order->get_items() as $order_item_id => $order_item) { foreach ($wc_order->get_items() as $order_item_id => $order_item) {

View File

@ -435,6 +435,9 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) :
$order_data['items'] = $order_items; $order_data['items'] = $order_items;
$order_data['discountManualAmount'] = 0;
$order_data['discountManualPercent'] = 0;
if (!$update) { if (!$update) {
$this->order_payment->is_new = true; $this->order_payment->is_new = true;
$order_data['payments'][] = $this->order_payment->build($order)->get_data(); $order_data['payments'][] = $this->order_payment->build($order)->get_data();

View File

@ -54,7 +54,7 @@ class WC_Retailcrm_History_Test extends WC_Retailcrm_Test_Case_Helper
} }
$this->assertNotEmpty($order_added->get_date_created()); $this->assertNotEmpty($order_added->get_date_created());
$this->assertEquals($order_added->get_date_created()->date('Y-m-d H:i:s'), $order['history'][0]['createdAt']); $this->assertEquals("2018-01-01 00:00:00", $order['history'][0]['createdAt']);
$this->assertNotEmpty($shipping_address['first_name']); $this->assertNotEmpty($shipping_address['first_name']);
$this->assertNotEmpty($shipping_address['last_name']); $this->assertNotEmpty($shipping_address['last_name']);
$this->assertNotEmpty($shipping_address['postcode']); $this->assertNotEmpty($shipping_address['postcode']);
@ -764,6 +764,7 @@ class WC_Retailcrm_History_Test extends WC_Retailcrm_Test_Case_Helper
array( array(
'id' => 160, 'id' => 160,
'initialPrice' => 100, 'initialPrice' => 100,
'discountTotal' => 5,
'createdAt' => '2018-01-01 00:00:00', 'createdAt' => '2018-01-01 00:00:00',
'quantity' => 1, 'quantity' => 1,
'status' => 'new', 'status' => 'new',
@ -773,6 +774,8 @@ class WC_Retailcrm_History_Test extends WC_Retailcrm_Test_Case_Helper
'value' =>"160_".$product_create_id 'value' =>"160_".$product_create_id
) )
), ),
'initialPrice' => 15,
'discountTotal' => 1,
'offer' => array( 'offer' => array(
'id' => 1, 'id' => 1,
'externalId' => $product_create_id, 'externalId' => $product_create_id,
@ -1057,6 +1060,7 @@ class WC_Retailcrm_History_Test extends WC_Retailcrm_Test_Case_Helper
array( array(
'id' => 160, 'id' => 160,
'initialPrice' => 100, 'initialPrice' => 100,
'discountTotal' => 5,
'createdAt' => '2018-01-01 00:00:00', 'createdAt' => '2018-01-01 00:00:00',
'quantity' => 1, 'quantity' => 1,
'status' => 'new', 'status' => 'new',
@ -1066,6 +1070,8 @@ class WC_Retailcrm_History_Test extends WC_Retailcrm_Test_Case_Helper
'value' =>"160_".$productId 'value' =>"160_".$productId
) )
), ),
'initialPrice' => 15,
'discountTotal' => 1,
'offer' => array( 'offer' => array(
'id' => 1, 'id' => 1,
'externalId' => $productId, 'externalId' => $productId,
@ -2198,7 +2204,7 @@ class WC_Retailcrm_History_Test extends WC_Retailcrm_Test_Case_Helper
'code' => 'base', 'code' => 'base',
), ),
'initialPrice' => 16, 'initialPrice' => 16,
'discountTotal' => 0, 'discountTotal' => 5,
'vatRate' => 'none', 'vatRate' => 'none',
'createdAt' => '2020-06-04 14:54:54', 'createdAt' => '2020-06-04 14:54:54',
'quantity' => 1, 'quantity' => 1,

View File

@ -184,6 +184,9 @@ class WC_Retailcrm_Orders_Test extends WC_Retailcrm_Test_Case_Helper
$this->assertEquals('Sormani', $order_send['lastName']); $this->assertEquals('Sormani', $order_send['lastName']);
$this->assertEquals('admin@example.org', $order_send['email']); $this->assertEquals('admin@example.org', $order_send['email']);
$this->assertEquals('US', $order_send['countryIso']); $this->assertEquals('US', $order_send['countryIso']);
$this->assertEquals(0, $order_send['discountManualAmount']);
$this->assertEquals(0, $order_send['discountManualPercent']);
if (mb_strlen($order_send['delivery']['address']['index']) === 6) { if (mb_strlen($order_send['delivery']['address']['index']) === 6) {
$this->assertEquals('123456', $order_send['delivery']['address']['index']); $this->assertEquals('123456', $order_send['delivery']['address']['index']);
} else { } else {