@php $p = $product ?? null; $tagsCsv = $p && is_array($p->tags_json) ? implode(', ', $p->tags_json) : ''; $galleryUrls = $p && is_array($p->gallery_json) ? $p->gallery_json : []; // Existing variants (ordered by the relation) preloaded for the editor. $existingVariants = $p ? $p->variants()->get() : collect(); // Derive option definitions (name => ordered unique values) from them so the // Options builder is pre-filled when editing a product that already has // variants. $variantOptionDefs = []; foreach ($existingVariants as $ev) { foreach ((array) $ev->options_json as $oName => $oVal) { $oName = trim((string) $oName); $oVal = trim((string) $oVal); if ($oName === '' || $oVal === '') continue; if (!isset($variantOptionDefs[$oName])) $variantOptionDefs[$oName] = []; if (!in_array($oVal, $variantOptionDefs[$oName], true)) $variantOptionDefs[$oName][] = $oVal; } } $variantGrid = 'grid grid-cols-[minmax(110px,1.3fr)_1fr_0.85fr_0.75fr_1.2fr_34px] gap-2'; $variantInput = 'px-2.5 py-1.5 border border-paper-200 rounded-lg text-[12px] focus:outline-none focus:border-wa-deep focus:ring-4 focus:ring-wa-deep/10'; @endphp
@csrf @if ($p) @method('PUT') @endif @if ($errors->any())
@foreach ($errors->all() as $e)
{{ $e }}
@endforeach
@endif {{-- Two-column shell. Left column = wide editing area, right = sticky organization rail. --}}
{{-- ============================== LEFT COLUMN ============================== --}}
{{-- Basics card --}}
{{ __('Basics') }}
{{-- Media card --}}
{{ __('Media') }}
{{ __('Primary image · drop or paste a URL') }}
{{ __('Tips for great product photos') }}
{{ __('Use square (1:1) images at 1024×1024 px or larger. Plain backgrounds convert better than busy ones.') }}
{{-- Gallery — extra product images (read by storefront product detail page) --}}
{{ __('Gallery') }}
{{ __('Add more images to the product detail page. Buyers see these as thumbnails.') }}
@foreach ($galleryUrls as $url)
@endforeach @if (empty($galleryUrls))
{{ __('No gallery images yet — click "Add image URL" above to add one.') }}
@endif
{{-- Hidden template that JS clones on Add --}}
{{-- Pricing card --}}
{{ __('Pricing') }}
{{-- Inventory + shipping card --}}
{{ __('Inventory & shipping') }}
{{-- Variants card. Optional — a product with no rows here keeps using the flat SKU / price / stock above (fully backward-compatible). The merchant defines option NAMES + VALUES, builds one row per combination, then sets a per-variant SKU / price / stock / image. The hidden variants_present flag tells the controller the editor was rendered, so it reconciles (creates/updates/removes) variant rows. --}}
{{ __('Variants') }}

{{ __('Optional. Add options like Size or Colour, then build a row per combination — each with its own SKU, price and stock. Leave a variant price blank to inherit the product price above. No variants? This product uses the single SKU / price / stock above.') }}

{{-- Option definitions builder --}}
{{ __('Options') }}
@foreach ($variantOptionDefs as $oName => $oVals)
@endforeach
{{ __('Creates one row per combination. Rows you already have are kept.') }}
{{-- Variant rows --}}
isEmpty()) style="display:none" @endif>
{{ __('Variant') }}
{{ __('SKU') }}
{{ __('Price') }}
{{ __('Stock') }}
{{ __('Image URL') }}
@foreach ($existingVariants as $i => $ev) @php $vLabel = $ev->label(); $vPrice = $ev->price_minor !== null ? number_format($ev->price_minor / 100, 2, '.', '') : ''; // Blank stock = untracked/available; show the number only when // tracked (>0) or explicitly sold-out (0 with in_stock=false), // so re-saving round-trips the "untracked" state correctly. $vStock = ($ev->stock_qty > 0 || !$ev->in_stock) ? (string) $ev->stock_qty : ''; @endphp
{{ $vLabel }}
@endforeach
isEmpty()) style="display:none" @endif> {{ __('No variants yet — add options above and click "Build variant rows".') }}
{{-- Hidden templates cloned by JS (no name= attrs; JS assigns indexed names on add) --}}
{{-- ============================== RIGHT COLUMN (sticky rail) ============================== --}}
{{-- Action bar. Kept IN-FLOW (not sticky): the app is `overflow-x-clip`, which makes a `sticky bottom` bar pin to the bottom of the whole page (far below the fold, unreachable) instead of the viewport — the client couldn't scroll to Save. A normal footer sits at the end of the form and is reached by scrolling the page normally. `space-y-5` on the form spaces it from the cards above. --}}
{{ __('Cancel') }}