Add Shopify pull-from feature and fix product creation payload
Deploy / deploy (push) Successful in 14s
Deploy / deploy (push) Successful in 14s
- Add "Aus Shopify laden" button on product edit page that pulls description and variant prices/SKUs/GTINs from Shopify back into SMS - Add ShopifyService::getProduct() for fetching a single product - Add 'options' to createProduct() payload so Shopify properly creates variants (without it Shopify ignores variant option values) - Add request/response logging to createProduct() for diagnosing transfer issues - Remove dead code from ProductResource (mutateFormData*, getRecord, getActions) - Clean up imports in ProductResource Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
9ef24fc45f
commit
811f5a015e
3 files changed
+99
-58
No files matched your search
@@ -31,6 +31,15 @@ class EditProduct extends EditRecord
|
||||
->exists()
|
||||
)
|
||||
->action(fn () => $this->createProductInShopify()),
|
||||
Actions\Action::make('pull-from-shopify')
|
||||
->label('Aus Shopify laden')
|
||||
->icon('heroicon-o-arrow-down-tray')
|
||||
->color('gray')
|
||||
->requiresConfirmation()
|
||||
->modalHeading('Aus Shopify aktualisieren')
|
||||
->modalDescription('Überschreibt Beschreibung und Variantenpreise/-SKUs mit den aktuellen Shopify-Daten.')
|
||||
->visible(fn () => (bool) $this->record->shopify_product_id)
|
||||
->action(fn () => $this->pullFromShopify()),
|
||||
Actions\Action::make('rezept-versionen')
|
||||
->label('Rezept-Versionen')
|
||||
->icon('heroicon-o-clock')
|
||||
@@ -181,6 +190,50 @@ class EditProduct extends EditRecord
|
||||
}
|
||||
}
|
||||
|
||||
public function pullFromShopify(): void
|
||||
{
|
||||
$product = $this->record;
|
||||
|
||||
if (! $product->shopify_product_id) {
|
||||
Notification::make()->title('Kein Shopify-Produkt verknüpft')->warning()->send();
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$data = app(ShopifyService::class)->getProduct($product->shopify_product_id);
|
||||
|
||||
$updates = [];
|
||||
if (! empty($data['description'])) {
|
||||
$updates['description'] = $data['description'];
|
||||
}
|
||||
if ($updates) {
|
||||
$product->update($updates);
|
||||
}
|
||||
|
||||
$variantMap = collect($data['variants'])->keyBy('shopify_variant_id');
|
||||
|
||||
ProductSize::where('product_id', $product->id)
|
||||
->whereNotNull('shopify_variant_id')
|
||||
->get()
|
||||
->each(function (ProductSize $size) use ($variantMap) {
|
||||
$shopifyVariant = $variantMap->get($size->shopify_variant_id);
|
||||
if (! $shopifyVariant) {
|
||||
return;
|
||||
}
|
||||
$size->update([
|
||||
'price' => $shopifyVariant['price'],
|
||||
'sku' => $shopifyVariant['sku'] ?: $size->sku,
|
||||
'gtin' => $shopifyVariant['gtin'] ?: $size->gtin,
|
||||
]);
|
||||
});
|
||||
|
||||
Notification::make()->title('Aus Shopify aktualisiert')->success()->send();
|
||||
$this->redirect(ProductResource::getUrl('edit', ['record' => $product]));
|
||||
} catch (\Throwable $e) {
|
||||
Notification::make()->title('Shopify-Fehler')->body($e->getMessage())->danger()->send();
|
||||
}
|
||||
}
|
||||
|
||||
public function syncVariantWithShopify(int $sizeId): void
|
||||
{
|
||||
$size = ProductSize::find($sizeId);
|
||||
|
||||
Reference in new issue
Block a user