Reputation: 1481
I am implementing a Shopify Store into a WordPress theme and one thing I need for that is a way to query Shopify products with the product handle instead of ID as shown on their docs:
http://shopify.github.io/js-buy-sdk/api/classes/ShopClient.html#method-fetchProduct
The reason for this is what I want to have the single product view with a SEO friendly URL, built precisely from the product handle.
On Shopify's site someone mentions a non-documented way to achieve this, I couldn't however get it to work: https://ecommerce.shopify.com/c/shopify-apis-and-technology/t/how-do-i-query-for-a-product-using-its-handle-322118#comment-346792
Have anyone had luck with this?
Upvotes: 2
Views: 3463
Reputation: 2003
You can use this to fetch product by handle.
client.product.fetchByHandle(handle).then(
product => { // Your product },
error => { // error },
)
Upvotes: 1
Reputation: 394
I think fetchQueryProducts() is what you're looking for. As an example:
var shopClient = ShopifyBuy.buildClient({
apiKey: 'my_key',
myShopifyDomain: 'your_myshopify_domain',
appId: 6
});
shopClient.fetchQueryProducts({handle: 'your_product_handle'}).then(function(products) {
// Your product is at products[0] if successful
});
Upvotes: 1
Reputation: 308
There's no way in the API that I know of to do this. You may end up having to store a mapping of IDs to handles, and keep that mapping updated via webhooks.
Upvotes: 0