Skip to content

Commit 240fb56

Browse files
authored
Merge branch '1.x' into patch-2
2 parents 60c11ff + 4635e1c commit 240fb56

28 files changed

+64
-52
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<p align="center"><a href="https://lunarphp.io/" target="_blank"><picture><source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/lunarphp/art/main/lunar-logo-dark.svg"><img alt="Lunar" width="200" src="https://raw.githubusercontent.com/lunarphp/art/main/lunar-logo.svg"></picture></a></p>
22

33
> [!CAUTION]
4-
> Version 1.x is currently in alpha release. We recommend this version for new projects, however, it is not feature-complete and therefore may not be deemed production-ready.
4+
> Version 1.x is currently in beta release. We recommend this version for new projects, however, it is not feature-complete and therefore may not be deemed production-ready.
55
66

77
[Lunar](https://lunarphp.io) is a set of Laravel packages that bring functionality akin to Shopify and other e-commerce platforms to

docs/admin/overview.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Introduction
22

3-
::: danger Alpha Release
3+
::: danger Beta Release
44
Although many Lunar sites have been launched using v1.x, you may not consider this version production-ready for your own
5-
use and should exercise the same amount of caution as you would with any software in an alpha state. 🚀
5+
use and should exercise the same amount of caution as you would with any software in an beta state. 🚀
66
:::
77

88
Lunar's admin panel is powered by Filament v3. It allows you to easily extend the admin panel to suit your project.

docs/core/installation.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Installation
22

3-
::: danger Alpha Release
3+
::: danger Beta Release
44
Although many Lunar sites have been launched using v1.x, you may not consider this version production-ready for your own
5-
use and should exercise the same amount of caution as you would with any software in an alpha state. 🚀
5+
use and should exercise the same amount of caution as you would with any software in an beta state. 🚀
66
:::
77

88
## Requirements
@@ -20,7 +20,7 @@ use and should exercise the same amount of caution as you would with any softwar
2020
### Composer Require Package
2121

2222
```sh
23-
composer require lunarphp/lunar:"^1.0.0-alpha" -W
23+
composer require lunarphp/lunar:"^1.0.0-beta" -W
2424
```
2525

2626
::: tip

docs/core/overview.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Welcome to Lunar!
22

3-
::: danger Alpha Release
4-
Although many Lunar sites have been launched using v1.x, you may not consider this version production-ready for your own
5-
use and should exercise the same amount of caution as you would with any software in an alpha state. 🚀
3+
::: danger Beta Release
4+
Although many Lunar sites have been launched using v1.x, you may not consider this version production-ready for your own
5+
use and should exercise the same amount of caution as you would with any software in an beta state. 🚀
66
:::
77

88
We are delighted you are considering Lunar for your project. We've spent a lot of time developing this package to bring headless e-commerce functionality to Laravel.

docs/core/reference/carts.md

-9
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,6 @@ foreach ($cart->shippingBreakdown->items as $shippingBreakdown) {
129129
}
130130

131131

132-
foreach ($cart->discountBreakdown as $discountBreakdown) {
133-
$discountBreakdown->discount_id
134-
foreach ($discountBreakdown->lines as $discountLine) {
135-
$discountLine->quantity
136-
$discountLine->line
137-
}
138-
$discountBreakdown->total->value
139-
}
140-
141132
foreach ($cart->discountBreakdown as $discountBreakdown) {
142133
$discountBreakdown->discount_id
143134
foreach ($discountBreakdown->lines as $discountLine) {

packages/admin/src/Filament/Resources/CustomerResource/RelationManagers/OrdersRelationManager.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Filament\Tables;
66
use Filament\Tables\Table;
77
use Lunar\Admin\Filament\Resources\OrderResource;
8+
use Lunar\Admin\Filament\Resources\OrderResource\Pages\ManageOrder;
89
use Lunar\Admin\Support\RelationManagers\BaseRelationManager;
910
use Lunar\Models\Order;
1011

@@ -18,7 +19,7 @@ public function getDefaultTable(Table $table): Table
1819
OrderResource::getTableColumns()
1920
)->actions([
2021
Tables\Actions\Action::make('viewOrder')
21-
->url(fn (Order $record): string => route('filament.lunar.resources.orders.order', $record)),
22+
->url(fn (Order $record): string => ManageOrder::getUrl(['record' => $record])),
2223
]);
2324
}
2425
}

packages/admin/src/Filament/Resources/OrderResource/Pages/EditOrder.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ protected function getDefaultHeaderActions(): array
4444

4545
return response()->streamDownload(function () {
4646
echo Pdf::loadView('lunarpanel::pdf.order', [
47-
'order' => $this->record,
47+
'record' => $this->record,
4848
])->stream();
4949
}, name: "Order-{$this->record->reference}.pdf");
5050
}),

packages/admin/src/Filament/Resources/ProductResource.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,8 @@ public static function getNameTableColumn(): Tables\Columns\Column
300300
->attributeData()
301301
->limitedTooltip()
302302
->limit(50)
303-
->label(__('lunarpanel::product.table.name.label'));
303+
->label(__('lunarpanel::product.table.name.label'))
304+
->searchable();
304305
}
305306

306307
public static function getSkuTableColumn(): Tables\Columns\Column
@@ -323,7 +324,8 @@ public static function getSkuTableColumn(): Tables\Columns\Column
323324
})
324325
->listWithLineBreaks()
325326
->limitList(1)
326-
->toggleable();
327+
->toggleable()
328+
->searchable();
327329
}
328330

329331
public static function getDefaultRelations(): array

packages/admin/src/Filament/Resources/ProductResource/Pages/ListProducts.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ protected function getDefaultHeaderActions(): array
2727
static::createActionFormInputs()
2828
)->using(
2929
fn (array $data, string $model) => static::createRecord($data, $model)
30-
)->successRedirectUrl(fn (Model $record): string => route('filament.lunar.resources.products.edit', [
30+
)->successRedirectUrl(fn (Model $record): string => ProductResource::getUrl('edit', [
3131
'record' => $record,
3232
])),
3333
];

packages/admin/src/Support/Forms/Components/Attributes.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ protected function setUp(): void
8686
}
8787

8888
foreach ($state as $key => $value) {
89-
if (! $value instanceof \Lunar\Base\Fieldtype) {
89+
if (! $value instanceof \Lunar\Base\FieldType) {
9090
continue;
9191
}
9292

packages/admin/src/Support/Resources/Pages/ManageUrlsRelatedRecords.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function form(Form $form): Form
5555
ignoreRecord: true,
5656
modifyRuleUsing: function (Unique $rule, callable $get) {
5757
return $rule
58-
->where('element_type', static::$model)
58+
->where('element_type', (new static::$model)->getMorphClass())
5959
->where('language_id', $get('language_id'));
6060
}
6161
)

packages/core/database/state/EnsureMediaCollectionsAreRenamed.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ protected function shouldRun()
3535
protected function getOutdatedMediaQuery()
3636
{
3737
return DB::table(app(config('media-library.media_model'))->getTable())
38-
->whereIn('model_type', [Product::class, Collection::class, Brand::class])
38+
->whereIn('model_type', [Product::morphName(), Collection::morphName(), Brand::morphName()])
3939
->where('collection_name', 'products');
4040
}
4141
}

packages/core/src/DiscountTypes/AbstractDiscountType.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ protected function checkDiscountConditions(Cart $cart): bool
6464

6565
$validCoupon = $cartCoupon ? ($cartCoupon === $conditionCoupon) : blank($conditionCoupon);
6666

67-
$minSpend = ($data['min_prices'][$cart->currency->code] ?? 0) / $cart->currency->factor;
67+
$minSpend = (int) ($data['min_prices'][$cart->currency->code] ?? 0) / (int) $cart->currency->factor;
6868
$minSpend = (int) bcmul($minSpend, $cart->currency->factor);
6969

7070
$lines = $this->getEligibleLines($cart);

packages/core/src/DiscountTypes/AmountOff.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ protected function getEligibleLines(Cart $cart): \Illuminate\Support\Collection
224224
/**
225225
* Apply the percentage to the cart line.
226226
*/
227-
private function applyPercentage(int $value, Cart $cart): Cart
227+
private function applyPercentage(float $value, Cart $cart): Cart
228228
{
229229
$lines = $this->getEligibleLines($cart);
230230

packages/core/src/LunarServiceProvider.php

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ class LunarServiceProvider extends ServiceProvider
9595
'cart',
9696
'cart_session',
9797
'database',
98+
'discounts',
9899
'media',
99100
'orders',
100101
'payments',

packages/core/src/Observers/OrderLineObserver.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,12 @@ public function creating(OrderLine $orderLine)
3232
*/
3333
public function updating(OrderLine $orderLine)
3434
{
35-
if (! in_array(Purchasable::class, class_implements($orderLine->purchasable_type, true))) {
36-
throw new NonPurchasableItemException($orderLine->purchasable_type);
35+
$purchasableModel = class_exists($orderLine->purchasable_type) ?
36+
$orderLine->purchasable_type :
37+
Relation::getMorphedModel($orderLine->purchasable_type);
38+
39+
if (! $purchasableModel || ! in_array(Purchasable::class, class_implements($purchasableModel, true))) {
40+
throw new NonPurchasableItemException($purchasableModel);
3741
}
3842
}
3943
}

packages/core/src/Pipelines/Cart/ApplyDiscounts.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ final class ApplyDiscounts
1111
/**
1212
* Called just before cart totals are calculated.
1313
*
14-
* @return void
14+
* @return mixed
1515
*/
1616
public function handle(Cart $cart, Closure $next)
1717
{

packages/core/src/Pipelines/Cart/ApplyShipping.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ final class ApplyShipping
1414
/**
1515
* Called just before cart totals are calculated.
1616
*
17-
* @return void
17+
* @return mixed
1818
*/
1919
public function handle(Cart $cart, Closure $next)
2020
{

packages/core/src/Pipelines/Cart/Calculate.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Calculate
1111
/**
1212
* Called just before cart totals are calculated.
1313
*
14-
* @return void
14+
* @return mixed
1515
*/
1616
public function handle(Cart $cart, Closure $next)
1717
{

packages/core/src/Pipelines/Cart/CalculateLines.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class CalculateLines
1212
/**
1313
* Called just before cart totals are calculated.
1414
*
15-
* @return void
15+
* @return mixed
1616
*/
1717
public function handle(Cart $cart, Closure $next)
1818
{

packages/core/src/Pipelines/Cart/CalculateTax.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class CalculateTax
1515
/**
1616
* Called just before cart totals are calculated.
1717
*
18-
* @return void
18+
* @return mixed
1919
*/
2020
public function handle(Cart $cart, Closure $next)
2121
{

packages/core/src/Pipelines/Order/Creation/CleanUpOrderLines.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
class CleanUpOrderLines
99
{
1010
/**
11-
* @return Closure
11+
* @return mixed
1212
*/
1313
public function handle(Order $order, Closure $next)
1414
{

packages/core/src/Pipelines/Order/Creation/CreateOrderAddresses.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
class CreateOrderAddresses
1010
{
1111
/**
12-
* @return Closure
12+
* @return mixed
1313
*/
1414
public function handle(Order $order, Closure $next)
1515
{

packages/core/src/Pipelines/Order/Creation/CreateOrderLines.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
class CreateOrderLines
1010
{
1111
/**
12-
* @return Closure
12+
* @return mixed
1313
*/
1414
public function handle(Order $order, Closure $next)
1515
{

packages/core/src/Pipelines/Order/Creation/CreateShippingLine.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
class CreateShippingLine
1111
{
1212
/**
13-
* @return Closure
13+
* @return mixed
1414
*/
1515
public function handle(Order $order, Closure $next)
1616
{

packages/core/src/Pipelines/Order/Creation/FillOrderFromCart.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
class FillOrderFromCart
1111
{
1212
/**
13-
* @return Closure
13+
* @return mixed
1414
*/
1515
public function handle(Order $order, Closure $next)
1616
{

packages/core/src/Pipelines/Order/Creation/MapDiscountBreakdown.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
class MapDiscountBreakdown
99
{
1010
/**
11-
* @return Closure
11+
* @return mixed
1212
*/
1313
public function handle(Order $order, Closure $next)
1414
{

tests/core/Unit/DiscountTypes/AmountOffTest.php

+24-11
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,16 @@
784784
expect($lastLine->discountTotal->value)->toEqual(333);
785785
});
786786

787-
test('can apply percentage discount', function () {
787+
test('can apply percentage discount', function (
788+
string $coupon,
789+
float $percentage,
790+
int $discountTotalForOne,
791+
int $taxTotalForOne,
792+
int $totalForOne,
793+
int $discountTotalForTwo,
794+
int $taxTotalForTwo,
795+
int $totalForTwo
796+
) {
788797
$customerGroup = CustomerGroup::getDefault();
789798

790799
$channel = Channel::getDefault();
@@ -794,7 +803,7 @@
794803
$cart = Cart::factory()->create([
795804
'channel_id' => $channel->id,
796805
'currency_id' => $currency->id,
797-
'coupon_code' => '10PERCENTOFF',
806+
'coupon_code' => $coupon,
798807
]);
799808

800809
$purchasable = ProductVariant::factory()->create();
@@ -816,9 +825,9 @@
816825
$discount = Discount::factory()->create([
817826
'type' => AmountOff::class,
818827
'name' => 'Test Coupon',
819-
'coupon' => '10PERCENTOFF',
828+
'coupon' => $coupon,
820829
'data' => [
821-
'percentage' => 10,
830+
'percentage' => $percentage,
822831
'fixed_value' => false,
823832
],
824833
]);
@@ -843,9 +852,9 @@
843852

844853
$cart = $cart->calculate();
845854

846-
expect($cart->discountTotal->value)->toEqual(100);
847-
expect($cart->taxTotal->value)->toEqual(180);
848-
expect($cart->total->value)->toEqual(1080);
855+
expect($cart->discountTotal->value)->toEqual($discountTotalForOne);
856+
expect($cart->taxTotal->value)->toEqual($taxTotalForOne);
857+
expect($cart->total->value)->toEqual($totalForOne);
849858

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

@@ -857,10 +866,14 @@
857866

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

860-
expect($cart->discountTotal->value)->toEqual(200);
861-
expect($cart->taxTotal->value)->toEqual(360);
862-
expect($cart->total->value)->toEqual(2160);
863-
});
869+
expect($cart->discountTotal->value)->toEqual($discountTotalForTwo);
870+
expect($cart->taxTotal->value)->toEqual($taxTotalForTwo);
871+
expect($cart->total->value)->toEqual($totalForTwo);
872+
})->with([
873+
'10% Discount' => ['10PERCENTOFF', 10, 100, 180, 1080, 200, 360, 2160],
874+
'10.25% Discount' => ['10PT25PERCENTOFF', 10.25, 103, 179, 1076, 205, 359, 2154],
875+
'10.5% Discount' => ['10PT5PERCENTOFF', 10.5, 105, 179, 1074, 210, 358, 2148],
876+
]);
864877

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

0 commit comments

Comments
 (0)