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/product variant attribute filling #1997

Draft
wants to merge 7 commits into
base: 1.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Lunar\Admin\Filament\Resources\OrderResource;
use Lunar\Admin\Filament\Resources\OrderResource\Pages\ManageOrder;
use Lunar\Admin\Support\RelationManagers\BaseRelationManager;
use Lunar\Admin\Filament\Resources\OrderResource\Pages\ManageOrder;
use Lunar\Models\Order;

class OrdersRelationManager extends BaseRelationManager
Expand Down
15 changes: 14 additions & 1 deletion packages/admin/src/Filament/Resources/ProductResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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);
}
Expand Down
3 changes: 1 addition & 2 deletions packages/admin/src/Support/Forms/Components/Attributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Loading