From a39a34fd3b314b2e5eca689ab215109a469aa1e0 Mon Sep 17 00:00:00 2001 From: Aidas Klimas Date: Sun, 20 Oct 2024 21:10:21 +0800 Subject: [PATCH 1/2] Update Attributes.php --- packages/admin/src/Support/Forms/Components/Attributes.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/admin/src/Support/Forms/Components/Attributes.php b/packages/admin/src/Support/Forms/Components/Attributes.php index 8df4b49223..e57ad4ee1a 100644 --- a/packages/admin/src/Support/Forms/Components/Attributes.php +++ b/packages/admin/src/Support/Forms/Components/Attributes.php @@ -22,11 +22,10 @@ protected function setUp(): void if (blank($this->childComponents)) { $this->schema(function (\Filament\Forms\Get $get, Livewire $livewire, ?Model $record) { - $modelClass = $livewire::getResource()::getModel(); $productTypeId = null; - $morphMap = $modelClass::morphName(); + $morphMap = $record ? $record::morphName() : $livewire::getResource()::getModel()::morphName(); $attributeQuery = Attribute::where('attribute_type', $morphMap); From 311a5fecf007a99052541325dd3e3676e57edb83 Mon Sep 17 00:00:00 2001 From: Aidas Klimas Date: Sun, 20 Oct 2024 21:13:41 +0800 Subject: [PATCH 2/2] show variant products if it's the only variant --- .../src/Filament/Resources/ProductResource.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/admin/src/Filament/Resources/ProductResource.php b/packages/admin/src/Filament/Resources/ProductResource.php index 724c09a1a9..c11b1fab6a 100644 --- a/packages/admin/src/Filament/Resources/ProductResource.php +++ b/packages/admin/src/Filament/Resources/ProductResource.php @@ -99,7 +99,7 @@ public static function getWidgets(): array public static function getDefaultForm(Form $form): Form { return $form - ->schema([ + ->schema(fn (Product $record) => [ Shout::make('product-status') ->content( __('lunarpanel::product.status.unpublished.content') @@ -123,6 +123,19 @@ public static function getDefaultForm(Form $form): Form static::getMainFormComponents(), ), static::getAttributeDataFormComponent(), + ...( + $record->variants->count() === 1 ? + [Forms\Components\Repeater::make('variants') + ->relationship() + ->schema([ + Attributes::make()->statePath('attribute_data') + ]) + ->maxItems(1) + ->addable(false) + ->deletable(false) + ->label('Variant details')] : + [] + ) ]) ->columns(1); }