Fix order fees total

This commit is contained in:
Alex P 2022-06-17 09:41:05 +03:00
parent 04aba8ceb1
commit af15246a96
3 changed files with 42 additions and 4 deletions

View file

@ -142,7 +142,7 @@ class AmountFactory {
$total = new Money( $total_value, $currency );
$item_total = new Money(
(float) $order->get_subtotal(),
(float) $order->get_subtotal() + (float) $order->get_total_fees(),
$currency
);
$shipping = new Money(

View file

@ -133,10 +133,13 @@ class AmountFactoryTest extends TestCase
$order
->shouldReceive('get_total')
->andReturn(100);
->andReturn(10);
$order
->shouldReceive('get_subtotal')
->andReturn(6);
$order
->shouldReceive('get_total_fees')
->andReturn(4);
$order
->shouldReceive('get_currency')
->andReturn($this->currency);
@ -155,9 +158,9 @@ class AmountFactoryTest extends TestCase
$result = $this->testee->from_wc_order($order);
$this->assertEquals((float) 3, $result->breakdown()->discount()->value());
$this->assertEquals((float) 6, $result->breakdown()->item_total()->value());
$this->assertEquals((float) 10, $result->breakdown()->item_total()->value());
$this->assertEquals((float) 1, $result->breakdown()->shipping()->value());
$this->assertEquals((float) 100, $result->value());
$this->assertEquals((float) 10, $result->value());
$this->assertEquals((float) 2, $result->breakdown()->tax_total()->value());
$this->assertEquals($this->currency, $result->breakdown()->discount()->currency_code());
$this->assertEquals($this->currency, $result->breakdown()->item_total()->currency_code());
@ -195,6 +198,9 @@ class AmountFactoryTest extends TestCase
$order
->shouldReceive('get_subtotal')
->andReturn(6);
$order
->shouldReceive('get_total_fees')
->andReturn(0);
$order
->shouldReceive('get_currency')
->andReturn($this->currency);

View file

@ -6,6 +6,7 @@ namespace WooCommerce\PayPalCommerce\Tests\E2e\Order;
use Exception;
use WC_Coupon;
use WC_Order;
use WC_Order_Item_Fee;
use WC_Order_Item_Product;
use WC_Order_Item_Shipping;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
@ -79,6 +80,17 @@ class PurchaseUnitTest extends TestCase
$wcOrder->add_item($shipping);
}
foreach ($data['fees'] ?? [] as $ind => $feeData) {
$fee = new WC_Order_Item_Fee();
$fee->set_name("Test fee $ind");
$fee->set_amount((string) $feeData['amount']);
$fee->set_total((string) $feeData['amount']);
$fee->set_tax_class('');
$fee->set_tax_status('taxable');
$wcOrder->add_item($fee);
}
$wcOrder->calculate_totals();
$wcOrder->save();
@ -213,6 +225,26 @@ class PurchaseUnitTest extends TestCase
],
]),
];
yield [
[
'items' => [
['price' => 5.99, 'quantity' => 1],
],
'billing' => ['city' => 'city1'],
'fees' => [
['amount' => 2.89],
['amount' => 7.13],
]
],
self::adaptAmountFormat([
'value' => 17.39,
'breakdown' => [
'item_total' => 16.01,
'tax_total' => 1.38,
'shipping' => 0.0,
],
]),
];
}
private static function adaptAmountFormat(array $data, string $currency = null): array {