-
Notifications
You must be signed in to change notification settings - Fork 467
Description
Context
I'm working on an e-commerce site using Lunar where users can register, make purchases, and manage their accounts. The platform needs to handle product variant management properly when administrators create and delete variants through the admin panel.
What I'm Trying to Do
Delete all additional variants of a product to convert it back to a simple product with full admin navigation (Inventory, Pricing, Shipping, Identifiers).
The Problem
When you create variants and then delete them, the product should return to being a "unit product" showing the complete navigation menu. Instead, the navigation pages remain hidden because the code uses withTrashed()->count() which includes soft-deleted variants.
What I've Checked
- Verified the issue exists in all 4 affected pages
- Confirmed it uses
withTrashed()->count() == 1for navigation logic - Tested the behavior with real data
- Confirmed that soft-deleted variants are the cause
Steps to Reproduce
- Create a new product (has 1 variant by default - shows full navigation)
- Add additional variants (2+ variants - navigation becomes limited to Variants tab)
- Delete all additional variants leaving only 1 active variant
- Return to the product edit page
- Observe that navigation remains limited instead of showing full navigation
Current Result
Product with 1 active variant + N soft-deleted variants = Limited navigation (only Variants tab visible)
Expected Result
Product with 1 active variant (regardless of soft-deleted variants) = Full navigation (Inventory, Pricing, Shipping, Identifiers tabs visible)
Technical Details
Affected Files:
All 4 pages use the same problematic pattern:
packages/admin/src/Filament/Resources/ProductResource/Pages/ManageProductInventory.php:42
public static function shouldRegisterNavigation(array $parameters = []): bool
{
return $parameters['record']->variants()->withTrashed()->count() == 1;
}packages/admin/src/Filament/Resources/ProductResource/Pages/ManageProductPricing.php:33
packages/admin/src/Filament/Resources/ProductResource/Pages/ManageProductShipping.php:48
packages/admin/src/Filament/Resources/ProductResource/Pages/ManageProductIdentifiers.php:39
All contain identical logic.
Root Cause Analysis
The navigation logic counts all variants including soft-deleted ones:
variants()->withTrashed()->count() == 1- includes deleted variants- Should use:
variants()->count() == 1- only active variants
Proposed Solution
Change the navigation condition in all 4 affected files:
// Current (problematic)
return $parameters['record']->variants()->withTrashed()->count() == 1;
// Fixed
return $parameters['record']->variants()->count() == 1;This change would:
- Show full navigation for products with 1 active variant
- Maintain proper navigation for products with 2+ active variants
- Preserve soft-delete functionality for data integrity
- Improve UX by allowing products to return to "unit product" state
Environment
- Lunar version: 1.0.0-rc.7
- Laravel Version: 11.47.0
- PHP Version: 8.4.15
- Database Driver & Version: MySQL 8.0
Why This Matters
This breaks a fundamental admin workflow:
- Poor UX: Admins can't properly manage products after variant deletion
- Inconsistent behavior: Navigation depends on historical data instead of current state
- Loss of functionality: Can't access Inventory, Pricing, etc. for logically simple products
- Confusing state: Product appears to have variants when it actually has only one
Additional Notes
- This affects the core product management experience
- Soft-delete preservation for data integrity is important, but shouldn't affect UI logic
- Similar pattern might exist in other resources (worth investigating)
- The
getVariant()methods in these pages also usewithTrashed()->first()which is consistent with current design but may need review
I've already created a PR for this fix: #2404