diff --git a/app/Console/Commands/ShopifySync.php b/app/Console/Commands/ShopifySync.php index f36cf66..d3050b5 100644 --- a/app/Console/Commands/ShopifySync.php +++ b/app/Console/Commands/ShopifySync.php @@ -35,6 +35,11 @@ class ShopifySync extends Command continue; // not mapped yet — run shopify:map first } + // Preis immer aktualisieren + if (! $dryRun && $size->price != $variant['price']) { + $size->update(['price' => $variant['price']]); + } + $shopifyQty = $variant['inventory_quantity']; $localQty = ProductInventory::where('size_id', $size->id) ->whereNull('out_at') diff --git a/app/Filament/User/Resources/ProductResource.php b/app/Filament/User/Resources/ProductResource.php index 75d884c..499ca8a 100644 --- a/app/Filament/User/Resources/ProductResource.php +++ b/app/Filament/User/Resources/ProductResource.php @@ -70,14 +70,11 @@ class ProductResource extends Resource { ->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)) { + $gtin = preg_replace('/\D/', '', (string) $get('gtin')); + if (strlen($gtin) < 8) { return new HtmlString(''); } $type = match (strlen($gtin)) { @@ -87,11 +84,20 @@ class ProductResource extends Resource { 14 => BarcodeGeneratorSVG::TYPE_CODABAR, default => BarcodeGeneratorSVG::TYPE_CODE_128, }; - $svg = (new BarcodeGeneratorSVG())->getBarcode($gtin, $type, 2, 60); - return new HtmlString($svg); + try { + $svg = (new BarcodeGeneratorSVG())->getBarcode($gtin, $type, 2, 60); + return new HtmlString($svg); + } catch (\Throwable) { + return new HtmlString(''); + } }) ->columnSpanFull() - ->visible(fn (Get $get) => filled($get('gtin'))), + ->visible(fn (Get $get) => strlen(preg_replace('/\D/', '', (string) $get('gtin'))) >= 8), + TextInput::make('gtin') + ->label('GTIN') + ->mask('9 999999 999999') + ->dehydrateStateUsing(fn ($state) => preg_replace('/\D/', '', (string) $state)) + ->live(debounce: 500), ]) ->label('Größen & Preise') ->columns(2)