Deploy / deploy (push) Successful in 14s
Log clear hint for 403 (IP whitelist), 401, 429, 5xx. Commands exit with failure and print error when API returns no data. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
63 lines
1.9 KiB
PHP
63 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Models\ProductSize;
|
|
use App\Services\ShopifyService;
|
|
use Illuminate\Console\Command;
|
|
|
|
class ShopifyMap extends Command
|
|
{
|
|
protected $signature = 'shopify:map {--dry-run : Änderungen nur anzeigen, nichts speichern}';
|
|
protected $description = 'Verknüpft Shopify-Variant-IDs mit lokalen ProductSizes per SKU';
|
|
|
|
public function handle(ShopifyService $shopify): int
|
|
{
|
|
$dryRun = $this->option('dry-run');
|
|
$variants = $shopify->getAllVariants();
|
|
|
|
if (empty($variants)) {
|
|
$this->error('Keine Varianten von Shopify erhalten — API-Aufruf fehlgeschlagen (Details im Log).');
|
|
return self::FAILURE;
|
|
}
|
|
|
|
$this->info('Shopify-Varianten geladen: ' . count($variants));
|
|
|
|
$mapped = 0;
|
|
$skipped = 0;
|
|
$noSku = 0;
|
|
|
|
foreach ($variants as $variant) {
|
|
if (empty($variant['sku'])) {
|
|
$noSku++;
|
|
continue;
|
|
}
|
|
|
|
$size = ProductSize::where('sku', $variant['sku'])->first();
|
|
|
|
if (!$size) {
|
|
$this->warn(" SKU nicht gefunden: {$variant['sku']} ({$variant['product_title']})");
|
|
$skipped++;
|
|
continue;
|
|
}
|
|
|
|
if ($size->shopify_variant_id === $variant['id']) {
|
|
continue; // already correct
|
|
}
|
|
|
|
if (!$dryRun) {
|
|
$size->update(['shopify_variant_id' => $variant['id']]);
|
|
}
|
|
|
|
$this->line(" {$variant['sku']} → Variant-ID {$variant['id']}");
|
|
$mapped++;
|
|
}
|
|
|
|
$this->info("✓ {$mapped} verknüpft" . ($dryRun ? ' (dry-run)' : ''));
|
|
if ($skipped) $this->warn("⚠ {$skipped} SKUs lokal nicht gefunden");
|
|
if ($noSku) $this->warn("⚠ {$noSku} Shopify-Varianten ohne SKU übersprungen");
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
}
|