Add SKU/GTIN fields, live barcode preview, and Shopify price import
Deploy / deploy (push) Successful in 26s

- Add SKU and GTIN fields to product variant repeater
- Render EAN/UPC barcode live from GTIN input (picqer/php-barcode-generator)
- Pull variant price from Shopify API instead of defaulting to 0
- Sync sku/gtin through EditProduct and CreateProduct save logic

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Malek TellissiandClaude Sonnet 4.6 committed 2026-09-12 04:46:00 +02:00
1 parent 35cacb2e99
commit 25b32c717b
8 files changed
+129 -18

No files matched your search

@@ -8,13 +8,17 @@ use App\Models\Product;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Components\Placeholder;
use Filament\Forms\Components\Repeater;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Get;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Support\HtmlString;
use App\Models\Packing;
use Picqer\Barcode\BarcodeGeneratorSVG;
class ProductResource extends Resource {
protected static ?string $model = Product::class;
@@ -51,10 +55,6 @@ class ProductResource extends Resource {
->required(),
Repeater::make('sizes')
->schema([
TextInput::make('gtin')
->label('GTIN'),
TextInput::make('description')
->label('Bezeichnung'),
Select::make('packing_id')
->label('Verpackung')
->options(function () {
@@ -68,25 +68,48 @@ class ProductResource extends Resource {
->label('Preis (in EUR)')
->numeric()
->required(),
TextInput::make('sku')
->label('SKU'),
TextInput::make('gtin')
->label('GTIN')
->live(debounce: 500),
Placeholder::make('barcode_preview')
->label('Barcode')
->content(function (Get $get): HtmlString {
$gtin = trim((string) $get('gtin'));
if (empty($gtin)) {
return new HtmlString('');
}
$type = match (strlen($gtin)) {
8 => BarcodeGeneratorSVG::TYPE_EAN_8,
13 => BarcodeGeneratorSVG::TYPE_EAN_13,
12 => BarcodeGeneratorSVG::TYPE_UPC_A,
14 => BarcodeGeneratorSVG::TYPE_CODABAR,
default => BarcodeGeneratorSVG::TYPE_CODE_128,
};
$svg = (new BarcodeGeneratorSVG())->getBarcode($gtin, $type, 2, 60);
return new HtmlString($svg);
})
->columnSpanFull()
->visible(fn (Get $get) => filled($get('gtin'))),
])
->label('Größen & Preise')
->columns(2)
->addActionLabel('Option hinzufügen')
->afterStateHydrated(function ($state, $set, $record) {
if ($record) {
// Load the spices relationship with pivot data
$record->load('sizes');
// Map the spices and their pivot data to the format the repeater expects
$sizesData = $record->sizes->map(function ($size) {
return [
'packing_id' => $size->id,
'price' => $size->pivot->price,
'packing_id' => $size->id,
'price' => $size->pivot->price,
'description' => $size->pivot->description,
'sku' => $size->pivot->sku,
'gtin' => $size->pivot->gtin,
];
})->toArray();
// Set the state for the repeater field to the mapped spices data
$set('sizes', $sizesData);
}
return $state;
@@ -17,10 +17,12 @@ class CreateProduct extends CreateRecord
foreach ($data['sizes'] as $size) {
ProductSize::create([
'product_id' => $record->id,
'packing_id' => $size['packing_id'],
'description' => $size['description'],
'price' => $size['price'],
'product_id' => $record->id,
'packing_id' => $size['packing_id'],
'description' => $size['description'] ?? null,
'price' => $size['price'],
'sku' => $size['sku'] ?? null,
'gtin' => $size['gtin'] ?? null,
]);
}
return $record;
@@ -27,7 +27,12 @@ class EditProduct extends EditRecord
$sizes = collect($this->data['sizes'] ?? [])
->mapWithKeys(function ($size) {
return [
$size['packing_id'] => ['description' => $size['description'], 'price' =>$size['price']],
$size['packing_id'] => [
'description' => $size['description'] ?? null,
'price' => $size['price'],
'sku' => $size['sku'] ?? null,
'gtin' => $size['gtin'] ?? null,
],
];
})
->toArray();