From 311a5fecf007a99052541325dd3e3676e57edb83 Mon Sep 17 00:00:00 2001 From: Aidas Klimas Date: Sun, 20 Oct 2024 21:13:41 +0800 Subject: [PATCH] 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); }