Download and store Shopify product images locally on import
Deploy / deploy (push) Successful in 13s
Deploy / deploy (push) Successful in 13s
Images are fetched from Shopify CDN, stored in storage/app/public/product-images/ as UUIDs, and saved in the Product.images array — matching Filament's FileUpload format. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
edc4c5a28c
commit
9ee67dfb69
2 files changed
+31
-1
No files matched your search
@@ -25,7 +25,7 @@ class ShopifyService
|
||||
public function getAllVariants(): array
|
||||
{
|
||||
$variants = [];
|
||||
$url = "{$this->baseUrl}/products.json?limit=250&fields=id,title,variants";
|
||||
$url = "{$this->baseUrl}/products.json?limit=250&fields=id,title,variants,images";
|
||||
|
||||
while ($url) {
|
||||
$response = Http::withHeader('X-Shopify-Access-Token', $this->token)->get($url);
|
||||
@@ -48,6 +48,7 @@ class ShopifyService
|
||||
}
|
||||
|
||||
foreach ($response->json('products', []) as $product) {
|
||||
$imageUrls = collect($product['images'] ?? [])->pluck('src')->all();
|
||||
foreach ($product['variants'] as $variant) {
|
||||
$variants[] = [
|
||||
'id' => (string) $variant['id'],
|
||||
@@ -55,6 +56,7 @@ class ShopifyService
|
||||
'inventory_quantity' => (int) ($variant['inventory_quantity'] ?? 0),
|
||||
'product_title' => $product['title'],
|
||||
'option1' => $variant['option1'] ?? '',
|
||||
'image_urls' => $imageUrls,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user