Skip to content

Commit

Permalink
Fix an issue where the AmountOff percentage is cast to an int, even t…
Browse files Browse the repository at this point in the history
…hough it could contain a decimal value (lunarphp#2003)
  • Loading branch information
tim committed Oct 25, 2024
1 parent 5266054 commit d31f42e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/DiscountTypes/AmountOff.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ protected function getEligibleLines(Cart $cart): \Illuminate\Support\Collection
/**
* Apply the percentage to the cart line.
*/
private function applyPercentage(int $value, Cart $cart): Cart
private function applyPercentage(float $value, Cart $cart): Cart
{
$lines = $this->getEligibleLines($cart);

Expand Down
18 changes: 9 additions & 9 deletions tests/core/Unit/DiscountTypes/AmountOffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@
$cart = Cart::factory()->create([
'channel_id' => $channel->id,
'currency_id' => $currency->id,
'coupon_code' => '10PERCENTOFF',
'coupon_code' => '10PT5PERCENTOFF',
]);

$purchasable = ProductVariant::factory()->create();
Expand All @@ -816,9 +816,9 @@
$discount = Discount::factory()->create([
'type' => AmountOff::class,
'name' => 'Test Coupon',
'coupon' => '10PERCENTOFF',
'coupon' => '10PT5PERCENTOFF',
'data' => [
'percentage' => 10,
'percentage' => 10.5,
'fixed_value' => false,
],
]);
Expand All @@ -843,9 +843,9 @@

$cart = $cart->calculate();

expect($cart->discountTotal->value)->toEqual(100);
expect($cart->taxTotal->value)->toEqual(180);
expect($cart->total->value)->toEqual(1080);
expect($cart->discountTotal->value)->toEqual(105);
expect($cart->taxTotal->value)->toEqual(179);
expect($cart->total->value)->toEqual(1074);

$cart->lines()->delete();

Expand All @@ -857,9 +857,9 @@

$cart = $cart->refresh()->calculate();

expect($cart->discountTotal->value)->toEqual(200);
expect($cart->taxTotal->value)->toEqual(360);
expect($cart->total->value)->toEqual(2160);
expect($cart->discountTotal->value)->toEqual(210);
expect($cart->taxTotal->value)->toEqual(358);
expect($cart->total->value)->toEqual(2148);
});

test('can only same discount to line once', function () {
Expand Down

0 comments on commit d31f42e

Please sign in to comment.