Skip to content

Commit

Permalink
Merge branch '1.x' into feature/extending-page-forms
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanmitchell authored Nov 19, 2024
2 parents e3ab597 + 4635e1c commit d3b4901
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected function getDefaultHeaderActions(): array

return response()->streamDownload(function () {
echo Pdf::loadView('lunarpanel::pdf.order', [
'order' => $this->record,
'record' => $this->record,
])->stream();
}, name: "Order-{$this->record->reference}.pdf");
}),
Expand Down
6 changes: 4 additions & 2 deletions packages/admin/src/Filament/Resources/ProductResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,8 @@ public static function getNameTableColumn(): Tables\Columns\Column
->attributeData()
->limitedTooltip()
->limit(50)
->label(__('lunarpanel::product.table.name.label'));
->label(__('lunarpanel::product.table.name.label'))
->searchable();
}

public static function getSkuTableColumn(): Tables\Columns\Column
Expand All @@ -323,7 +324,8 @@ public static function getSkuTableColumn(): Tables\Columns\Column
})
->listWithLineBreaks()
->limitList(1)
->toggleable();
->toggleable()
->searchable();
}

public static function getDefaultRelations(): array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function form(Form $form): Form
ignoreRecord: true,
modifyRuleUsing: function (Unique $rule, callable $get) {
return $rule
->where('element_type', static::$model)
->where('element_type', (new static::$model)->getMorphClass())
->where('language_id', $get('language_id'));
}
)
Expand Down
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
35 changes: 24 additions & 11 deletions tests/core/Unit/DiscountTypes/AmountOffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,16 @@
expect($lastLine->discountTotal->value)->toEqual(333);
});

test('can apply percentage discount', function () {
test('can apply percentage discount', function (
string $coupon,
float $percentage,
int $discountTotalForOne,
int $taxTotalForOne,
int $totalForOne,
int $discountTotalForTwo,
int $taxTotalForTwo,
int $totalForTwo
) {
$customerGroup = CustomerGroup::getDefault();

$channel = Channel::getDefault();
Expand All @@ -794,7 +803,7 @@
$cart = Cart::factory()->create([
'channel_id' => $channel->id,
'currency_id' => $currency->id,
'coupon_code' => '10PERCENTOFF',
'coupon_code' => $coupon,
]);

$purchasable = ProductVariant::factory()->create();
Expand All @@ -816,9 +825,9 @@
$discount = Discount::factory()->create([
'type' => AmountOff::class,
'name' => 'Test Coupon',
'coupon' => '10PERCENTOFF',
'coupon' => $coupon,
'data' => [
'percentage' => 10,
'percentage' => $percentage,
'fixed_value' => false,
],
]);
Expand All @@ -843,9 +852,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($discountTotalForOne);
expect($cart->taxTotal->value)->toEqual($taxTotalForOne);
expect($cart->total->value)->toEqual($totalForOne);

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

Expand All @@ -857,10 +866,14 @@

$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($discountTotalForTwo);
expect($cart->taxTotal->value)->toEqual($taxTotalForTwo);
expect($cart->total->value)->toEqual($totalForTwo);
})->with([
'10% Discount' => ['10PERCENTOFF', 10, 100, 180, 1080, 200, 360, 2160],
'10.25% Discount' => ['10PT25PERCENTOFF', 10.25, 103, 179, 1076, 205, 359, 2154],
'10.5% Discount' => ['10PT5PERCENTOFF', 10.5, 105, 179, 1074, 210, 358, 2148],
]);

test('can only same discount to line once', function () {
$customerGroup = CustomerGroup::getDefault();
Expand Down

0 comments on commit d3b4901

Please sign in to comment.