@extends('layouts.admin') @section('title', $product->exists ? 'Edit: '.$product->name : 'Add Bamboo Product') @section('actions') @if($product->exists) Preview Storefront @endif ← Products @endsection @php $highlightsInit = old('highlights', $product->highlights ?? ['']); if (empty($highlightsInit)) { $highlightsInit = ['']; } $specsInit = []; if (old('spec_keys')) { foreach (old('spec_keys') as $i => $k) { $specsInit[] = ['k' => $k, 'v' => old('spec_values')[$i] ?? '']; } } else { foreach (($product->specifications ?? []) as $k => $v) { $specsInit[] = ['k' => $k, 'v' => $v]; } } if (empty($specsInit)) { $specsInit[] = ['k' => '', 'v' => '']; } $variantsInit = old('variants'); if ($variantsInit === null) { $variantsInit = $product->exists ? $product->variants->map(function ($v) { $opts = collect($v->options ?? [])->map(fn ($val, $key) => "{$key}: {$val}")->implode(', '); return [ 'id' => $v->id, 'name' => $v->name, 'sku' => $v->sku, 'options_text' => $opts, 'price' => $v->price, 'compare_at_price' => $v->compare_at_price, 'stock' => $v->stock, 'is_active' => $v->is_active, ]; })->values()->all() : []; } @endphp @section('content')