Add Shopify publish/sync per product variant
Deploy / deploy (push) Successful in 14s

Each size row in the product form now shows a Shopify status badge
(green ✓ Shopify / gray Lokal). For saved variants, an action button
appears: 'Zu Shopify' for local-only variants (creates via Shopify
API and stores the returned variant ID), 'Shopify sync' for linked
variants (pushes price/SKU/GTIN to Shopify).

Also fixes:
- gtin missing from ProductSize::$fillable (was silently not saved)
- shopify_product_id added to products table and stored on import
- sizes afterStateHydrated now loads ProductSize directly instead of
  via the belongsToMany pivot (gets product_size_id, shopify_variant_id)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Malek TellissiandClaude Sonnet 4.6 committed 2026-09-12 17:20:26 +02:00
1 parent e187465553
commit 3ebd9845b0
7 files changed
+189 -20

No files matched your search

@@ -5,7 +5,9 @@ namespace App\Filament\User\Resources\ProductResource\Pages;
use App\Filament\User\Resources\ProductResource;
use App\Models\ProductSize;
use App\Models\Recipe;
use App\Services\ShopifyService;
use Filament\Actions;
use Filament\Notifications\Notification;
use Filament\Resources\Pages\EditRecord;
class EditProduct extends EditRecord
@@ -109,4 +111,46 @@ class EditProduct extends EditRecord
$product->update(['recipes_id' => $recipe->id]);
}
public function publishVariantToShopify(int $sizeId): void
{
$size = ProductSize::with('packing')->find($sizeId);
$product = $this->record;
if (! $size || $size->shopify_variant_id || ! $product->shopify_product_id) {
Notification::make()
->title('Nicht möglich')
->body($product->shopify_product_id
? 'Variante bereits in Shopify verknüpft.'
: 'Produkt hat keine Shopify-ID — zuerst shopify:import ausführen.')
->warning()
->send();
return;
}
try {
$variantId = app(ShopifyService::class)->createVariant($product->shopify_product_id, $size);
$size->update(['shopify_variant_id' => $variantId]);
Notification::make()->title('Variante in Shopify veröffentlicht')->success()->send();
} catch (\Throwable $e) {
Notification::make()->title('Shopify-Fehler')->body($e->getMessage())->danger()->send();
}
}
public function syncVariantWithShopify(int $sizeId): void
{
$size = ProductSize::find($sizeId);
if (! $size || ! $size->shopify_variant_id) {
Notification::make()->title('Keine Shopify-Verknüpfung')->warning()->send();
return;
}
try {
app(ShopifyService::class)->updateVariant($size);
Notification::make()->title('Shopify synchronisiert')->success()->send();
} catch (\Throwable $e) {
Notification::make()->title('Shopify-Fehler')->body($e->getMessage())->danger()->send();
}
}
}