Correct send and calculate discount (#159)
This commit is contained in:
parent
155a2d5716
commit
30cd87cad9
@ -721,17 +721,27 @@ if ( ! class_exists( 'WC_Retailcrm_History' ) ) :
|
||||
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) {
|
||||
$arItemsOld[$order_item_id] = $order_item_id;
|
||||
}
|
||||
|
||||
$wc_order->add_product(
|
||||
$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) {
|
||||
|
@ -435,6 +435,9 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) :
|
||||
|
||||
$order_data['items'] = $order_items;
|
||||
|
||||
$order_data['discountManualAmount'] = 0;
|
||||
$order_data['discountManualPercent'] = 0;
|
||||
|
||||
if (!$update) {
|
||||
$this->order_payment->is_new = true;
|
||||
$order_data['payments'][] = $this->order_payment->build($order)->get_data();
|
||||
|
@ -54,7 +54,7 @@ class WC_Retailcrm_History_Test extends WC_Retailcrm_Test_Case_Helper
|
||||
}
|
||||
|
||||
$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['last_name']);
|
||||
$this->assertNotEmpty($shipping_address['postcode']);
|
||||
@ -764,6 +764,7 @@ class WC_Retailcrm_History_Test extends WC_Retailcrm_Test_Case_Helper
|
||||
array(
|
||||
'id' => 160,
|
||||
'initialPrice' => 100,
|
||||
'discountTotal' => 5,
|
||||
'createdAt' => '2018-01-01 00:00:00',
|
||||
'quantity' => 1,
|
||||
'status' => 'new',
|
||||
@ -773,6 +774,8 @@ class WC_Retailcrm_History_Test extends WC_Retailcrm_Test_Case_Helper
|
||||
'value' =>"160_".$product_create_id
|
||||
)
|
||||
),
|
||||
'initialPrice' => 15,
|
||||
'discountTotal' => 1,
|
||||
'offer' => array(
|
||||
'id' => 1,
|
||||
'externalId' => $product_create_id,
|
||||
@ -1057,6 +1060,7 @@ class WC_Retailcrm_History_Test extends WC_Retailcrm_Test_Case_Helper
|
||||
array(
|
||||
'id' => 160,
|
||||
'initialPrice' => 100,
|
||||
'discountTotal' => 5,
|
||||
'createdAt' => '2018-01-01 00:00:00',
|
||||
'quantity' => 1,
|
||||
'status' => 'new',
|
||||
@ -1066,6 +1070,8 @@ class WC_Retailcrm_History_Test extends WC_Retailcrm_Test_Case_Helper
|
||||
'value' =>"160_".$productId
|
||||
)
|
||||
),
|
||||
'initialPrice' => 15,
|
||||
'discountTotal' => 1,
|
||||
'offer' => array(
|
||||
'id' => 1,
|
||||
'externalId' => $productId,
|
||||
@ -2198,7 +2204,7 @@ class WC_Retailcrm_History_Test extends WC_Retailcrm_Test_Case_Helper
|
||||
'code' => 'base',
|
||||
),
|
||||
'initialPrice' => 16,
|
||||
'discountTotal' => 0,
|
||||
'discountTotal' => 5,
|
||||
'vatRate' => 'none',
|
||||
'createdAt' => '2020-06-04 14:54:54',
|
||||
'quantity' => 1,
|
||||
|
@ -184,6 +184,9 @@ class WC_Retailcrm_Orders_Test extends WC_Retailcrm_Test_Case_Helper
|
||||
$this->assertEquals('Sormani', $order_send['lastName']);
|
||||
$this->assertEquals('admin@example.org', $order_send['email']);
|
||||
$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) {
|
||||
$this->assertEquals('123456', $order_send['delivery']['address']['index']);
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user