|
11 | 11 | use craft\shopify\elements\Product;
|
12 | 12 | use craft\shopify\elements\Product as ProductElement;
|
13 | 13 | use craft\shopify\events\ShopifyProductSyncEvent;
|
14 |
| -use craft\shopify\helpers\Api as ApiHelper; |
15 | 14 | use craft\shopify\helpers\Metafields as MetafieldsHelper;
|
16 |
| -use craft\shopify\jobs\UpdateProductMetadata; |
17 |
| -use craft\shopify\jobs\UpdateProductVariants; |
18 | 15 | use craft\shopify\Plugin;
|
19 | 16 | use craft\shopify\records\ProductData as ProductDataRecord;
|
20 | 17 | use Shopify\Rest\Admin2023_10\Metafield as ShopifyMetafield;
|
@@ -61,32 +58,15 @@ class Products extends Component
|
61 | 58 | * @throws \Throwable
|
62 | 59 | * @throws \yii\base\InvalidConfigException
|
63 | 60 | */
|
64 |
| - public function syncAllProducts(bool $asynchronous = true): void |
| 61 | + public function syncAllProducts(): void |
65 | 62 | {
|
66 | 63 | $api = Plugin::getInstance()->getApi();
|
67 | 64 | $products = $api->getAllProducts();
|
68 | 65 |
|
69 | 66 | foreach ($products as $product) {
|
70 |
| - if ($asynchronous) { |
71 |
| - $this->createOrUpdateProduct($product); |
72 |
| - Craft::$app->getQueue()->push(new UpdateProductMetadata([ |
73 |
| - 'description' => Craft::t('shopify', 'Updating product metafields for “{title}”', [ |
74 |
| - 'title' => $product->title, |
75 |
| - ]), |
76 |
| - 'shopifyProductId' => $product->id, |
77 |
| - ])); |
78 |
| - Craft::$app->getQueue()->push(new UpdateProductVariants([ |
79 |
| - 'description' => Craft::t('shopify', 'Updating product variants for “{title}”', [ |
80 |
| - 'title' => $product->title, |
81 |
| - ]), |
82 |
| - 'shopifyProductId' => $product->id, |
83 |
| - ])); |
84 |
| - } else { |
85 |
| - $metaFields = $api->getMetafieldsByProductId($product->id); |
86 |
| - ApiHelper::rateLimit(); |
87 |
| - $variants = $api->getVariantsByProductId($product->id); |
88 |
| - $this->createOrUpdateProduct($product, $metaFields, $variants); |
89 |
| - } |
| 67 | + $variants = $api->getVariantsByProductId($product->id); |
| 68 | + $metafields = $api->getMetafieldsByProductId($product->id); |
| 69 | + $this->createOrUpdateProduct($product, $metafields, $variants); |
90 | 70 | }
|
91 | 71 |
|
92 | 72 | // Remove any products that are no longer in Shopify just in case.
|
@@ -126,7 +106,8 @@ public function syncProductByInventoryItemId($id): void
|
126 | 106 | if ($productId = $api->getProductIdByInventoryItemId($id)) {
|
127 | 107 | $product = $api->getProductByShopifyId($productId);
|
128 | 108 | $metaFields = $api->getMetafieldsByProductId($product->id);
|
129 |
| - $this->createOrUpdateProduct($product, $metaFields); |
| 109 | + $variants = $api->getVariantsByProductId($product->id); |
| 110 | + $this->createOrUpdateProduct($product, $metaFields, $variants); |
130 | 111 | }
|
131 | 112 | }
|
132 | 113 |
|
@@ -161,7 +142,6 @@ public function createOrUpdateProduct(ShopifyProduct $product, array $metafields
|
161 | 142 | 'updatedAt' => $product->updated_at,
|
162 | 143 | 'variants' => $variants ?? $product->variants,
|
163 | 144 | 'vendor' => $product->vendor,
|
164 |
| - // This one is unusual, because we’re merging two different Shopify API resources: |
165 | 145 | 'metaFields' => $metaFields,
|
166 | 146 | ];
|
167 | 147 |
|
|
0 commit comments