Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix container resolution and morph map for extended models #1933

Open
wants to merge 45 commits into
base: 1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
23a0b17
update order pipelines
repl6669 Sep 2, 2024
bfaab6d
update cart pipelines
repl6669 Sep 2, 2024
5f877c8
update cart line pipeline
repl6669 Sep 2, 2024
edb019f
override getMorphClass method to use model namespace from model manifest
repl6669 Sep 3, 2024
231ff4a
Merge branch '1.x' into update-container-resolution
glennjacobs Sep 3, 2024
6a7a1f9
add base test case which can replace all models when configured
repl6669 Sep 3, 2024
a97136d
add stub models
repl6669 Sep 3, 2024
8d4a830
set up autoloading
repl6669 Sep 3, 2024
3b665ad
extend base test case
repl6669 Sep 3, 2024
d301890
add custom phpunit config file with model replacing turned on
repl6669 Sep 3, 2024
bba7e0e
conditianlly expect correct model
repl6669 Sep 3, 2024
a6f5e7e
add test model manifest
repl6669 Sep 4, 2024
a1fc5b1
add model stubs
repl6669 Sep 4, 2024
293ae32
change namespace
repl6669 Sep 4, 2024
0e3e975
remove stubs folder and base test case
repl6669 Sep 4, 2024
d974781
conditionally use test model manifest
repl6669 Sep 4, 2024
a07aab9
update container resolution
repl6669 Sep 4, 2024
2e8b528
skip test, because it was a false positive?
repl6669 Sep 4, 2024
1485724
fix test
repl6669 Sep 4, 2024
3f18f67
update container resolution
repl6669 Sep 4, 2024
f7d1722
update container resolution in actions
repl6669 Sep 4, 2024
48e8f96
update container resolution
repl6669 Sep 4, 2024
64bf492
run test suites with and without extended models
repl6669 Sep 4, 2024
5456e89
finish container resolution update for core
repl6669 Sep 5, 2024
8f97c5e
finish container resolution for admini
repl6669 Sep 5, 2024
72837bc
finish container resolution for opayo
repl6669 Sep 5, 2024
6abc9a6
finish container resolution for stripe
repl6669 Sep 5, 2024
83db9b0
finish container resolution for paypal
repl6669 Sep 5, 2024
23aa806
finish container resolution for table-rate-shipping
repl6669 Sep 5, 2024
a9f8855
fix cart line modifier
repl6669 Sep 5, 2024
7f4226a
fix phpstan errors
repl6669 Sep 5, 2024
11443d7
remove unnecessary variables
repl6669 Sep 5, 2024
3320ec7
merge 1.0
repl6669 Sep 11, 2024
7829d10
remove test model manifest
repl6669 Sep 11, 2024
f98a015
add base test case
repl6669 Sep 11, 2024
113b3d6
fix redundancy in test
repl6669 Sep 11, 2024
125fa8a
try to find the right morph class in all model ancestors
repl6669 Sep 11, 2024
f67b1bf
add find lunar model method, update morph map continuoustly after app…
repl6669 Sep 11, 2024
612a744
fix custom model namespace
repl6669 Sep 11, 2024
6614de3
update rest of the test cases
repl6669 Sep 11, 2024
347498a
simplify method
repl6669 Sep 12, 2024
370f920
Merge branch '1.x' into update-container-resolution
repl6669 Sep 30, 2024
5beba84
chore: fix code style
actions-user Sep 30, 2024
17345c3
remove unnecessary ::modelClass() calls
repl6669 Sep 30, 2024
155a4a8
Merge branch '1.x' into update-container-resolution
repl6669 Oct 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ jobs:
laravel: [11.*, 10.*]
dependency-version: [prefer-stable]
testsuite: [core, admin, shipping, stripe]
extend-models: ["true", "false"]
include:
- laravel: 11.*
testbench: 9.*
- laravel: 10.*
testbench: 8.*
name: ${{ matrix.testsuite }} - PHP ${{ matrix.php }} - L${{ matrix.laravel }} ${{ matrix.dependency-version == 'prefer-lowest' && '↓' || '↑' }}
name: ${{ matrix.testsuite }} - PHP ${{ matrix.php }} - L${{ matrix.laravel }} ${{ matrix.dependency-version == 'prefer-lowest' && '↓' || '↑' }} ${{ matrix.extend-models == 'true' && 'E' || '' }}
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand Down Expand Up @@ -47,4 +48,5 @@ jobs:
APP_ENV: testing
DB_CONNECTION: testing
DB_DATABASE: ":memory:"
LUNAR_TESTING_REPLACE_MODELS: ${{ matrix.extend-models }}
run: ./vendor/bin/pest --testsuite ${{ matrix.testsuite }}
4 changes: 4 additions & 0 deletions .phpactor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"$schema": "/Users/theimer/.local/share/nvim/mason/packages/phpactor/source/phpactor.schema.json",
"language_server_phpstan.enabled": true
}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
},
"autoload-dev": {
"psr-4": {
"Lunar\\Tests\\": "tests",
"Lunar\\Tests\\Admin\\": "tests/admin",
"Lunar\\Tests\\Core\\": "tests/core",
"Lunar\\Tests\\Opayo\\": "tests/opayo",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
use Lunar\Admin\Support\Resources\BaseResource;
use Lunar\Admin\Support\Tables\Columns\TranslatedTextColumn;
use Lunar\Facades\AttributeManifest;
use Lunar\Models\Contracts\AttributeGroup;
use Lunar\Models\Contracts\AttributeGroup as AttributeGroupContract;
use Lunar\Models\Language;

class AttributeGroupResource extends BaseResource
{
protected static ?string $permission = 'settings:manage-attributes';

protected static ?string $model = AttributeGroup::class;
protected static ?string $model = AttributeGroupContract::class;

protected static ?int $navigationSort = 1;

Expand Down
4 changes: 2 additions & 2 deletions packages/admin/src/Filament/Resources/BrandResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
use Lunar\Admin\Filament\Resources\BrandResource\Pages;
use Lunar\Admin\Support\Forms\Components\Attributes;
use Lunar\Admin\Support\Resources\BaseResource;
use Lunar\Models\Contracts\Brand;
use Lunar\Models\Contracts\Brand as BrandContract;

class BrandResource extends BaseResource
{
protected static ?string $permission = 'catalog:manage-products';

protected static ?string $model = Brand::class;
protected static ?string $model = BrandContract::class;

protected static ?int $navigationSort = 3;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Lunar\Admin\Support\Pages\BaseManageRelatedRecords;
use Lunar\Admin\Support\Tables\Columns\TranslatedTextColumn;
use Lunar\Models\Collection;
use Lunar\Models\Contracts\Collection as CollectionContract;

class ManageBrandCollections extends BaseManageRelatedRecords
{
Expand Down Expand Up @@ -54,7 +55,7 @@ function (Forms\Components\Select $select) {
->getSearchResultsUsing(static function (Forms\Components\Select $component, string $search): array {
return Collection::search($search)
->get()
->mapWithKeys(fn (Collection $record): array => [$record->getKey() => $record->breadcrumb->push($record->translateAttribute('name'))->join(' > ')])
->mapWithKeys(fn (CollectionContract $record): array => [$record->getKey() => $record->breadcrumb->push($record->translateAttribute('name'))->join(' > ')])
->all();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Lunar\Admin\Filament\Resources\BrandResource;
use Lunar\Admin\Filament\Resources\ProductResource;
use Lunar\Admin\Support\Pages\BaseManageRelatedRecords;
use Lunar\Models\Contracts\Product as ProductContract;
use Lunar\Models\Product;

class ManageBrandProducts extends BaseManageRelatedRecords
Expand Down Expand Up @@ -73,7 +74,7 @@ public function table(Table $table): Table
->getSearchResultsUsing(static function (Forms\Components\Select $component, string $search): array {
return Product::search($search)
->get()
->mapWithKeys(fn (Product $record): array => [$record->getKey() => $record->translateAttribute('name')])
->mapWithKeys(fn (ProductContract $record): array => [$record->getKey() => $record->translateAttribute('name')])
->all();
}),
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

use Lunar\Admin\Filament\Resources\BrandResource;
use Lunar\Admin\Support\Resources\Pages\ManageUrlsRelatedRecords;
use Lunar\Models\Brand;
use Lunar\Models\Contracts\Brand as BrandContract;

class ManageBrandUrls extends ManageUrlsRelatedRecords
{
protected static string $resource = BrandResource::class;

protected static string $model = Brand::class;
protected static string $model = BrandContract::class;
}
4 changes: 2 additions & 2 deletions packages/admin/src/Filament/Resources/ChannelResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
use Illuminate\Support\Str;
use Lunar\Admin\Filament\Resources\ChannelResource\Pages;
use Lunar\Admin\Support\Resources\BaseResource;
use Lunar\Models\Contracts\Channel;
use Lunar\Models\Contracts\Channel as ChannelContract;

class ChannelResource extends BaseResource
{
protected static ?string $permission = 'settings:core';

protected static ?string $model = Channel::class;
protected static ?string $model = ChannelContract::class;

protected static ?int $navigationSort = 1;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
use Illuminate\Support\Str;
use Lunar\Admin\Filament\Resources\CollectionGroupResource\Pages;
use Lunar\Admin\Support\Resources\BaseResource;
use Lunar\Models\Contracts\CollectionGroup;
use Lunar\Models\Contracts\CollectionGroup as CollectionGroupContract;

class CollectionGroupResource extends BaseResource
{
protected static ?string $permission = 'catalog:manage-products';

protected static ?string $model = CollectionGroup::class;
protected static ?string $model = CollectionGroupContract::class;

protected static ?int $navigationSort = 3;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Lunar\Admin\Support\Actions\Collections\MoveCollection;
use Lunar\Facades\DB;
use Lunar\Models\Collection;
use Lunar\Models\Contracts\Collection as CollectionContract;

class CollectionTreeView extends Widget implements HasActions, HasForms
{
Expand Down Expand Up @@ -191,12 +192,12 @@ public function moveAction()
->label(
__('lunarpanel::components.collection-tree-view.actions.move.form.target_id.label')
)
->model(Collection::class)
->model(Collection::modelClass())
->searchable()
->getSearchResultsUsing(static function (Forms\Components\Select $component, string $search): array {
return get_search_builder(Collection::class, $search)
return get_search_builder(Collection::modelClass(), $search)
->get()
->mapWithKeys(fn (Collection $record): array => [$record->getKey() => $record->breadcrumb->push($record->translateAttribute('name'))->join(' > ')])
->mapWithKeys(fn (CollectionContract $record): array => [$record->getKey() => $record->breadcrumb->push($record->translateAttribute('name'))->join(' > ')])
->all();
}),
])->after(
Expand Down
6 changes: 3 additions & 3 deletions packages/admin/src/Filament/Resources/CollectionResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
use Lunar\Admin\Filament\Resources\CollectionResource\Pages;
use Lunar\Admin\Support\Forms\Components\Attributes;
use Lunar\Admin\Support\Resources\BaseResource;
use Lunar\Models\Contracts\Collection;
use Lunar\Models\Contracts\Collection as CollectionContract;

class CollectionResource extends BaseResource
{
protected static ?string $permission = 'catalog:manage-collections';

protected static ?string $model = Collection::class;
protected static ?string $model = CollectionContract::class;

protected static int $globalSearchResultsLimit = 5;

Expand All @@ -38,7 +38,7 @@ public static function getNavigationItems(): array
return [];
}

public static function getCollectionBreadcrumbs(Collection $collection): array
public static function getCollectionBreadcrumbs(CollectionContract $collection): array
{
$crumbs = [
CollectionGroupResource::getUrl('index') => CollectionGroupResource::getPluralLabel(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Lunar\Admin\Support\Pages\BaseEditRecord;
use Lunar\Facades\DB;
use Lunar\Models\Collection;
use Lunar\Models\Contracts\Collection as CollectionContract;

class EditCollection extends BaseEditRecord
{
Expand Down Expand Up @@ -51,22 +52,22 @@ protected function getDefaultHeaderActions(): array
return [
DeleteAction::make('delete')->form([
Forms\Components\Select::make('target_collection')
->model(Collection::class)
->model(Collection::modelClass())
->searchable()
->getSearchResultsUsing(static function (Forms\Components\Select $component, string $search) use ($record): array {
return get_search_builder(Collection::class, $search)
return get_search_builder(Collection::modelClass(), $search)
->get()
->reject(
fn ($result) => $result->isDescendantOf($record)
)
->mapWithKeys(fn (Collection $record): array => [$record->getKey() => $record->translateAttribute('name')])
->mapWithKeys(fn (CollectionContract $record): array => [$record->getKey() => $record->translateAttribute('name')])
->all();
})->helperText(
'Choose which collection the children of this collection should be transferred to.'
)->hidden(
fn () => ! $record->children()->count()
),
])->before(function (Collection $collection, array $data) {
])->before(function (CollectionContract $collection, array $data) {

$targetId = $data['target_collection'] ?? null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Lunar\Admin\Filament\Resources\CollectionResource;
use Lunar\Admin\Filament\Resources\ProductResource;
use Lunar\Admin\Support\Pages\BaseManageRelatedRecords;
use Lunar\Models\Contracts\Product as ProductContract;
use Lunar\Models\Product;

class ManageCollectionProducts extends BaseManageRelatedRecords
Expand Down Expand Up @@ -91,7 +92,7 @@ public function table(Table $table): Table

return get_search_builder($relationModel, $search)
->get()
->mapWithKeys(fn (Product $record): array => [$record->getKey() => $record->translateAttribute('name')])
->mapWithKeys(fn (ProductContract $record): array => [$record->getKey() => $record->translateAttribute('name')])
->all();
}),
])->action(function (array $arguments, array $data, Form $form, Table $table) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

use Lunar\Admin\Filament\Resources\CollectionResource;
use Lunar\Admin\Support\Resources\Pages\ManageUrlsRelatedRecords;
use Lunar\Models\Collection;
use Lunar\Models\Contracts\Collection as CollectionContract;

class ManageCollectionUrls extends ManageUrlsRelatedRecords
{
protected static string $resource = CollectionResource::class;

protected static string $model = Collection::class;
protected static string $model = CollectionContract::class;

public function getBreadcrumbs(): array
{
Expand Down
4 changes: 2 additions & 2 deletions packages/admin/src/Filament/Resources/CurrencyResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
use Illuminate\Database\Eloquent\Model;
use Lunar\Admin\Filament\Resources\CurrencyResource\Pages;
use Lunar\Admin\Support\Resources\BaseResource;
use Lunar\Models\Contracts\Currency;
use Lunar\Models\Contracts\Currency as CurrencyContract;

class CurrencyResource extends BaseResource
{
protected static ?string $permission = 'settings:core';

protected static ?string $model = Currency::class;
protected static ?string $model = CurrencyContract::class;

protected static ?int $navigationSort = 1;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
use Lunar\Admin\Filament\Resources\CustomerGroupResource\Pages;
use Lunar\Admin\Support\Forms\Components\Attributes;
use Lunar\Admin\Support\Resources\BaseResource;
use Lunar\Models\Contracts\CustomerGroup;
use Lunar\Models\Contracts\CustomerGroup as CustomerGroupContract;

class CustomerGroupResource extends BaseResource
{
protected static ?string $permission = 'settings:core';

protected static ?string $model = CustomerGroup::class;
protected static ?string $model = CustomerGroupContract::class;

protected static ?int $navigationSort = 1;

Expand Down
4 changes: 2 additions & 2 deletions packages/admin/src/Filament/Resources/CustomerResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
use Lunar\Admin\Filament\Resources\CustomerResource\RelationManagers\UserRelationManager;
use Lunar\Admin\Filament\Resources\CustomerResource\Widgets\CustomerStatsOverviewWidget;
use Lunar\Admin\Support\Resources\BaseResource;
use Lunar\Models\Contracts\Customer;
use Lunar\Models\Contracts\Customer as CustomerContract;

class CustomerResource extends BaseResource
{
protected static ?string $permission = 'sales:manage-customers';

protected static ?string $model = Customer::class;
protected static ?string $model = CustomerContract::class;

protected static ?int $navigationSort = 2;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Illuminate\Database\Eloquent\Model;
use Lunar\Admin\Events\CustomerAddressEdited;
use Lunar\Admin\Support\RelationManagers\BaseRelationManager;
use Lunar\Models\Address;
use Lunar\Models\Contracts\Address as AddressContract;
use Lunar\Models\State;

class AddressRelationManager extends BaseRelationManager
Expand Down Expand Up @@ -71,7 +71,7 @@ public function getDefaultTable(Table $table): Table
->after(
fn (Model $record) => CustomerAddressEdited::dispatch($record)
)
->fillForm(fn (Address $record): array => [
->fillForm(fn (AddressContract $record): array => [
'title' => $record->title,
'first_name' => $record->first_name,
'last_name' => $record->last_name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Filament\Tables\Table;
use Lunar\Admin\Filament\Resources\OrderResource;
use Lunar\Admin\Support\RelationManagers\BaseRelationManager;
use Lunar\Models\Order;
use Lunar\Models\Contracts\Order as OrderContract;

class OrdersRelationManager extends BaseRelationManager
{
Expand All @@ -18,7 +18,7 @@ public function getDefaultTable(Table $table): Table
OrderResource::getTableColumns()
)->actions([
Tables\Actions\Action::make('viewOrder')
->url(fn (Order $record): string => route('filament.lunar.resources.orders.order', $record)),
->url(fn (OrderContract $record): string => route('filament.lunar.resources.orders.order', $record)),
]);
}
}
4 changes: 2 additions & 2 deletions packages/admin/src/Filament/Resources/DiscountResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
use Lunar\DiscountTypes\AmountOff;
use Lunar\DiscountTypes\BuyXGetY;
use Lunar\Facades\Discounts;
use Lunar\Models\Contracts\Discount;
use Lunar\Models\Contracts\Discount as DiscountContract;
use Lunar\Models\Currency;

class DiscountResource extends BaseResource
{
protected static ?string $permission = 'sales:manage-discounts';

protected static ?string $model = Discount::class;
protected static ?string $model = DiscountContract::class;

protected static ?int $navigationSort = 3;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Model;
use Lunar\Admin\Support\RelationManagers\BaseRelationManager;
use Lunar\Models\Contracts\Product as ProductContract;
use Lunar\Models\Product;

class ProductConditionRelationManager extends BaseRelationManager
Expand Down Expand Up @@ -38,20 +39,20 @@ public function getDefaultTable(Table $table): Table
->paginated(false)
->modifyQueryUsing(
fn ($query) => $query->whereIn('type', ['condition'])
->wherePurchasableType(Product::class)
->wherePurchasableType(Product::modelClass())
->whereHas('purchasable')
)
->headerActions([
Tables\Actions\CreateAction::make()->form([
Forms\Components\MorphToSelect::make('purchasable')
->searchable(true)
->types([
Forms\Components\MorphToSelect\Type::make(Product::class)
Forms\Components\MorphToSelect\Type::make(Product::modelClass())
->titleAttribute('name.en')
->getSearchResultsUsing(static function (Forms\Components\Select $component, string $search): array {
return get_search_builder(Product::class, $search)
return get_search_builder(Product::modelClass(), $search)
->get()
->mapWithKeys(fn (Product $record): array => [$record->getKey() => $record->attr('name')])
->mapWithKeys(fn (ProductContract $record): array => [$record->getKey() => $record->attr('name')])
->all();
}),
]),
Expand Down
Loading