From 48f960820304d9971030fe42ab4d39fd22f50f53 Mon Sep 17 00:00:00 2001 From: Ryan Mitchell Date: Tue, 14 Jul 2026 14:32:53 +0100 Subject: [PATCH] Show collection breadcrumb in discount selection --- .../CollectionConditionRelationManager.php | 21 +++++++++++++++++-- .../CollectionLimitationRelationManager.php | 13 +++++++++--- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/packages/admin/src/Filament/Resources/DiscountResource/RelationManagers/CollectionConditionRelationManager.php b/packages/admin/src/Filament/Resources/DiscountResource/RelationManagers/CollectionConditionRelationManager.php index c288f87e12..6fadcd7747 100644 --- a/packages/admin/src/Filament/Resources/DiscountResource/RelationManagers/CollectionConditionRelationManager.php +++ b/packages/admin/src/Filament/Resources/DiscountResource/RelationManagers/CollectionConditionRelationManager.php @@ -54,11 +54,13 @@ public function getDefaultTable(Table $table): Table ->getSearchResultsUsing(static function (string $search): array { return get_search_builder(Collection::modelClass(), $search) ->get() - ->mapWithKeys(fn (CollectionContract $record): array => [$record->getKey() => $record->attr('name')]) + ->mapWithKeys(fn (CollectionContract $record): array => [$record->getKey() => static::getCollectionOptionLabel($record)]) ->all(); }) ->getOptionLabelUsing(function ($value): string { - return Collection::modelClass()::find($value)?->attr('name') ?? $value; + $record = Collection::modelClass()::find($value); + + return $record ? static::getCollectionOptionLabel($record) : $value; }), Forms\Components\Hidden::make('discountable_type') ->default(Collection::morphName()), @@ -76,6 +78,9 @@ public function getDefaultTable(Table $table): Table ) ->formatStateUsing( fn (Model $record) => $record->discountable?->attr('name') + ) + ->description( + fn (Model $record) => $record->discountable ? static::getCollectionPath($record->discountable) : null ), ])->recordActions([ DeleteAction::make(), @@ -83,4 +88,16 @@ public function getDefaultTable(Table $table): Table DeleteBulkAction::make(), ]); } + + protected static function getCollectionPath(CollectionContract $record): string + { + return collect([$record->group->name]) + ->merge($record->breadcrumb) + ->implode(' > '); + } + + protected static function getCollectionOptionLabel(CollectionContract $record): string + { + return $record->attr('name').' ('.static::getCollectionPath($record).')'; + } } diff --git a/packages/admin/src/Filament/Resources/DiscountResource/RelationManagers/CollectionLimitationRelationManager.php b/packages/admin/src/Filament/Resources/DiscountResource/RelationManagers/CollectionLimitationRelationManager.php index 400106d2e8..4be0924ca0 100644 --- a/packages/admin/src/Filament/Resources/DiscountResource/RelationManagers/CollectionLimitationRelationManager.php +++ b/packages/admin/src/Filament/Resources/DiscountResource/RelationManagers/CollectionLimitationRelationManager.php @@ -50,8 +50,8 @@ public function getDefaultTable(Table $table): Table 'exclusion' => __('lunarpanel::discount.relationmanagers.collections.form.type.options.exclusion.label'), ] )->default('limitation'), - ])->recordTitle(function ($record) { - return $record->attr('name'); + ])->recordTitle(function (Collection $record) { + return $record->attr('name').' ('.static::getCollectionPath($record).')'; })->recordSelectSearchColumns(['attribute_data->name']) ->preloadRecordSelect() ->label( @@ -62,7 +62,7 @@ public function getDefaultTable(Table $table): Table ->label( __('lunarpanel::discount.relationmanagers.collections.table.name.label') ) - ->description(fn (Collection $record): string => $record->breadcrumb->implode(' > ')) + ->description(fn (Collection $record): string => static::getCollectionPath($record)) ->formatStateUsing( fn (Model $record) => $record->attr('name') ), @@ -78,4 +78,11 @@ public function getDefaultTable(Table $table): Table DetachBulkAction::make(), ]); } + + protected static function getCollectionPath(Collection $record): string + { + return collect([$record->group->name]) + ->merge($record->breadcrumb) + ->implode(' > '); + } }