Skip to content

Commit

Permalink
Sync full variant data
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeholder committed Oct 4, 2023
1 parent 38ce9f5 commit 06fc783
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/services/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,18 @@ public function getMetafieldsByProductId(int $id): array
]);
}

/**
* Retrieves "metafields" for the provided Shopify product ID.
*
* @param int $id Shopify Product ID
*/
public function getVariantsByProductId(int $id): array
{
$variants = $this->get("products/{$id}/variants");

return $variants['variants'];
}

/**
* Shortcut for retrieving arbitrary API resources. A plain (parsed) response body is returned, so it’s the caller’s responsibility for unpacking it properly.
*
Expand Down
2 changes: 1 addition & 1 deletion src/services/Products.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public function createOrUpdateProduct(ShopifyProduct $product, array $metafields
'tags' => $product->tags,
'templateSuffix' => $product->template_suffix,
'updatedAt' => $product->updated_at,
'variants' => $product->variants,
'variants' => Plugin::getInstance()->getApi()->getVariantsByProductId($product->id),
'vendor' => $product->vendor,
// This one is unusual, because we’re merging two different Shopify API resources:
'metaFields' => $metaFields,
Expand Down

0 comments on commit 06fc783

Please sign in to comment.