Add 'Publish to Shopify' for locally-created products
Deploy / deploy (push) Successful in 14s

New header action on the product edit page creates the entire product
(title, description, all variants) in Shopify via API. The returned
shopify_product_id and per-variant shopify_variant_ids are stored
locally. After success the page reloads so status badges update.
Button is hidden once the product is already linked to Shopify.

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:22:37 +02:00
1 parent 3ebd9845b0
commit 6fe34883c6
2 files changed
+86

No files matched your search

@@ -17,6 +17,15 @@ class EditProduct extends EditRecord
protected function getHeaderActions(): array
{
return [
Actions\Action::make('shopify-create-product')
->label('In Shopify veröffentlichen')
->icon('heroicon-o-arrow-up-tray')
->color('warning')
->requiresConfirmation()
->modalHeading('Produkt in Shopify anlegen')
->modalDescription('Erstellt das Produkt mit allen Varianten in Shopify und verknüpft die IDs.')
->visible(fn () => ! $this->record->shopify_product_id)
->action(fn () => $this->createProductInShopify()),
Actions\Action::make('rezept-versionen')
->label('Rezept-Versionen')
->icon('heroicon-o-clock')
@@ -112,6 +121,35 @@ class EditProduct extends EditRecord
$product->update(['recipes_id' => $recipe->id]);
}
public function createProductInShopify(): void
{
$product = $this->record;
if ($product->shopify_product_id) {
Notification::make()->title('Bereits in Shopify verknüpft')->warning()->send();
return;
}
$sizes = ProductSize::with('packing')->where('product_id', $product->id)->get();
try {
$result = app(ShopifyService::class)->createProduct($product, $sizes);
$product->update(['shopify_product_id' => $result['shopify_product_id']]);
foreach ($result['variants'] as $packingId => $variantId) {
ProductSize::where('product_id', $product->id)
->where('packing_id', $packingId)
->update(['shopify_variant_id' => $variantId]);
}
Notification::make()->title('Produkt in Shopify erstellt')->success()->send();
$this->redirect(ProductResource::getUrl('edit', ['record' => $product]));
} catch (\Throwable $e) {
Notification::make()->title('Shopify-Fehler')->body($e->getMessage())->danger()->send();
}
}
public function publishVariantToShopify(int $sizeId): void
{
$size = ProductSize::with('packing')->find($sizeId);