Skip to content

Commit 20671a3

Browse files
authored
Merge branch '1.x' into fix/file-attribute-images-not-persisting-after-save
2 parents 6e79628 + bde0b21 commit 20671a3

17 files changed

Lines changed: 191 additions & 89 deletions

File tree

.github/FUNDING.yml

Lines changed: 0 additions & 3 deletions
This file was deleted.

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"filament/spatie-laravel-media-library-plugin": "^4.0",
2121
"guzzlehttp/guzzle": "^7.3",
2222
"http-interop/http-factory-guzzle": "^1.2",
23-
"kalnoy/nestedset": "^v6.0.5",
23+
"kalnoy/nestedset": "^v6.0.5|^v7.0.1",
2424
"laravel/framework": "^12.0|^13.0",
2525
"laravel/scout": "^10.13.1",
2626
"leandrocfe/filament-apex-charts": "^5.0",
@@ -40,7 +40,7 @@
4040
"typesense/typesense-php": "^4.9"
4141
},
4242
"require-dev": {
43-
"filament/upgrade": "^4.0",
43+
"filament/upgrade": "^4.0",
4444
"larastan/larastan": "^3.0",
4545
"laravel/pint": "1.29.0",
4646
"mockery/mockery": "^1.6.9",
@@ -88,7 +88,7 @@
8888
}
8989
},
9090
"extra": {
91-
"lunar": {
91+
"lunar": {
9292
"name": [
9393
"Table Rate Shipping",
9494
"Opayo Payments",
@@ -132,7 +132,7 @@
132132
},
133133
"config": {
134134
"allow-plugins": {
135-
"pestphp/pest-plugin": true,
135+
"pestphp/pest-plugin": true,
136136
"php-http/discovery": true
137137
}
138138
},

packages/admin/.github/FUNDING.yml

Lines changed: 0 additions & 3 deletions
This file was deleted.

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

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Illuminate\Validation\Rules\Unique;
1919
use Lunar\Admin\Events\ProductPricingUpdated;
2020
use Lunar\Admin\Support\RelationManagers\BaseRelationManager;
21+
use Lunar\DataTypes\Price as PriceDataType;
2122
use Lunar\Facades\DB;
2223
use Lunar\Models\Currency;
2324
use Lunar\Models\CustomerGroup;
@@ -76,14 +77,10 @@ public function getDefaultForm(Schema $schema): Schema
7677
])->columns(2),
7778

7879
Group::make([
79-
TextInput::make('price')->formatStateUsing(
80-
fn ($state) => $state?->decimal(rounding: false)
81-
)->numeric()->helperText(
80+
TextInput::make('price')->numeric()->helperText(
8281
__('lunarpanel::relationmanagers.pricing.form.price.helper_text')
8382
)->required(),
84-
TextInput::make('compare_price')->formatStateUsing(
85-
fn ($state) => $state?->decimal(rounding: false)
86-
)->label(
83+
TextInput::make('compare_price')->label(
8784
__('lunarpanel::relationmanagers.pricing.form.compare_price.label')
8885
)->helperText(
8986
__('lunarpanel::relationmanagers.pricing.form.compare_price.helper_text')
@@ -152,18 +149,31 @@ public function getDefaultTable(Table $table): Table
152149
),
153150
])
154151
->recordActions([
155-
EditAction::make()->mutateDataUsing(function (array $data): array {
156-
$currencyModel = Currency::find($data['currency_id']);
152+
EditAction::make()
153+
->mutateRecordDataUsing(fn (array $data): array => $this->unwrapPriceData($data))
154+
->mutateDataUsing(function (array $data): array {
155+
$currencyModel = Currency::find($data['currency_id']);
157156

158-
$data['min_quantity'] = 1;
159-
$data['price'] = (int) ($data['price'] * $currencyModel->factor);
160-
$data['compare_price'] = (int) ($data['compare_price'] * $currencyModel->factor);
157+
$data['min_quantity'] = 1;
158+
$data['price'] = (int) ($data['price'] * $currencyModel->factor);
159+
$data['compare_price'] = (int) ($data['compare_price'] * $currencyModel->factor);
161160

162-
return $data;
163-
})->after(
164-
fn () => ProductPricingUpdated::dispatch($this->getOwnerRecord())
165-
),
161+
return $data;
162+
})->after(
163+
fn () => ProductPricingUpdated::dispatch($this->getOwnerRecord())
164+
),
166165
DeleteAction::make(),
167166
]);
168167
}
168+
169+
protected function unwrapPriceData(array $data): array
170+
{
171+
foreach (['price', 'compare_price'] as $key) {
172+
if (($data[$key] ?? null) instanceof PriceDataType) {
173+
$data[$key] = $data[$key]->decimal(rounding: false);
174+
}
175+
}
176+
177+
return $data;
178+
}
169179
}

packages/admin/src/Support/Pages/BaseListRecords.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Lunar\Admin\Support\Pages;
44

55
use Filament\Resources\Pages\ListRecords;
6+
use Filament\Tables\Filters\TrashedFilter;
67
use Illuminate\Database\Eloquent\Builder;
78
use Lunar\Admin\Support\Concerns\CallsHooks;
89
use Lunar\Admin\Support\Pages\Concerns\ExtendsFooterWidgets;
@@ -39,21 +40,22 @@ protected function applySearchToTableQuery(Builder $query): Builder
3940
$scoutEnabled &&
4041
$isScoutSearchable
4142
) {
42-
$ids = collect(static::getModel()::search($search)->take(100)->keys())->map(
43-
fn ($result) => str_replace(static::getModel().'::', '', $result)
44-
);
43+
$trashedFilter = collect($this->getTable()->getFilters())
44+
->firstWhere(fn ($filter) => $filter instanceof TrashedFilter);
4545

46-
$placeholders = implode(',', array_fill(0, count($ids), '?'));
46+
$scoutQuery = static::getModel()::search($search);
4747

48-
$query->whereIn(
49-
'id',
50-
$ids
51-
);
48+
if (filled($state = $trashedFilter?->getState()['value'] ?? null)) {
49+
$state ? $scoutQuery->withTrashed() : $scoutQuery->onlyTrashed();
50+
}
5251

53-
$query->when(
54-
! $ids->isEmpty(),
55-
fn ($query) => $query->orderBySequence($ids->toArray())
52+
$ids = collect($scoutQuery->take(100)->keys())->map(
53+
fn ($result) => str_replace(static::getModel().'::', '', $result)
5654
);
55+
56+
$query
57+
->whereIn('id', $ids)
58+
->orderBySequence($ids);
5759
}
5860

5961
return $query;

packages/admin/src/Support/RelationManagers/PriceRelationManager.php

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Illuminate\Contracts\Support\Htmlable;
1818
use Illuminate\Database\Eloquent\Model;
1919
use Lunar\Admin\Events\ModelPricesUpdated;
20+
use Lunar\DataTypes\Price as PriceDataType;
2021
use Lunar\Facades\DB;
2122
use Lunar\Models\Currency;
2223
use Lunar\Models\CustomerGroup;
@@ -93,14 +94,10 @@ public function form(Schema $schema): Schema
9394
])->columns(3),
9495

9596
Group::make([
96-
TextInput::make('price')->formatStateUsing(
97-
fn ($state) => $state?->decimal(rounding: false)
98-
)->numeric()->helperText(
97+
TextInput::make('price')->numeric()->helperText(
9998
__('lunarpanel::relationmanagers.pricing.form.price.helper_text')
10099
)->required(),
101-
TextInput::make('compare_price')->formatStateUsing(
102-
fn ($state) => $state?->decimal(rounding: false)
103-
)->label(
100+
TextInput::make('compare_price')->label(
104101
__('lunarpanel::relationmanagers.pricing.form.compare_price.label')
105102
)->helperText(
106103
__('lunarpanel::relationmanagers.pricing.form.compare_price.helper_text')
@@ -179,22 +176,35 @@ public function table(Table $table): Table
179176
),
180177
])
181178
->recordActions([
182-
EditAction::make()->mutateDataUsing(function (array $data): array {
183-
$currencyModel = Currency::find($data['currency_id']);
184-
185-
$data['price'] = (int) ($data['price'] * $currencyModel->factor);
186-
187-
return $data;
188-
})->after(
189-
fn () => ModelPricesUpdated::dispatch(
190-
$this->getOwnerRecord()
191-
)
192-
),
179+
EditAction::make()
180+
->mutateRecordDataUsing(fn (array $data): array => $this->unwrapPriceData($data))
181+
->mutateDataUsing(function (array $data): array {
182+
$currencyModel = Currency::find($data['currency_id']);
183+
184+
$data['price'] = (int) ($data['price'] * $currencyModel->factor);
185+
186+
return $data;
187+
})->after(
188+
fn () => ModelPricesUpdated::dispatch(
189+
$this->getOwnerRecord()
190+
)
191+
),
193192
DeleteAction::make()->after(
194193
fn () => ModelPricesUpdated::dispatch(
195194
$this->getOwnerRecord()
196195
)
197196
),
198197
]);
199198
}
199+
200+
protected function unwrapPriceData(array $data): array
201+
{
202+
foreach (['price', 'compare_price'] as $key) {
203+
if (($data[$key] ?? null) instanceof PriceDataType) {
204+
$data[$key] = $data[$key]->decimal(rounding: false);
205+
}
206+
}
207+
208+
return $data;
209+
}
200210
}

packages/admin/src/Support/Resources/BaseResource.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,9 @@ protected static function applyGlobalSearchAttributeConstraints(Builder $query,
8484
fn ($result) => str_replace(static::getModel().'::', '', $result)
8585
);
8686

87-
$placeholders = implode(',', array_fill(0, count($ids), '?'));
88-
89-
$query->whereIn(
90-
'id',
91-
$ids
92-
);
93-
94-
$query->when(
95-
! $ids->isEmpty(),
96-
fn ($query) => $query->orderBySequence($ids->toArray())
97-
);
98-
87+
$query
88+
->whereIn('id', $ids)
89+
->orderBySequence($ids);
9990
} else {
10091
/** @var Connection $databaseConnection */
10192
$databaseConnection = $query->getConnection();

packages/core/.github/FUNDING.yml

Lines changed: 0 additions & 3 deletions
This file was deleted.

packages/core/composer.json

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
{
22
"name": "lunarphp/core",
33
"description": "Lunar Laravel e-commerce core functionality.",
4-
"keywords": ["lunar", "laravel", "ecommerce", "e-commerce", "headless", "store", "shop", "cart"],
4+
"keywords": [
5+
"lunar",
6+
"laravel",
7+
"ecommerce",
8+
"e-commerce",
9+
"headless",
10+
"store",
11+
"shop",
12+
"cart"
13+
],
514
"type": "library",
615
"license": "MIT",
716
"authors": [
817
{
9-
"name": "Lunar",
10-
"homepage": "https://lunarphp.io/"
18+
"name": "Lunar",
19+
"homepage": "https://lunarphp.io/"
1120
}
1221
],
1322
"autoload": {
@@ -37,7 +46,7 @@
3746
"spatie/laravel-medialibrary": "^11.12.7",
3847
"spatie/laravel-activitylog": "^4.10.1",
3948
"laravel/scout": "^10.13.1",
40-
"kalnoy/nestedset": "^v6.0.5",
49+
"kalnoy/nestedset": "^v6.0.5|^v7.0.1",
4150
"lukascivil/treewalker": "0.9.1",
4251
"spatie/php-structure-discoverer": "^2.3.1",
4352
"spatie/laravel-blink": "^1.7.1"

packages/core/src/LunarServiceProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,11 +357,11 @@ protected function registerObservers(): void
357357

358358
protected function registerBuilderMacros(): void
359359
{
360-
Builder::macro('orderBySequence', function (array $ids) {
360+
Builder::macro('orderBySequence', function (iterable $ids) {
361361
/** @var Builder $this */
362362
$driver = $this->getConnection()->getDriverName();
363363

364-
if (empty($ids)) {
364+
if (blank($ids)) {
365365
return $this;
366366
}
367367

0 commit comments

Comments
 (0)