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

@ -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 {