Access a community of over 900,000 Shopify Merchants and Partners and engage in meaningful conversations with your peers.
So I've been on the Shopify Storefront docs and I found this.
I looks like I can get recommended products by providing a product id.
I've written the query below, but it always returns an empty array:
import { gql } from '@ts-gql/tag';
import type { Client } from '../utils/apollo-client';
export const PRODUCT_RECOMMENDATIONS = gql`
query productRecommendations(
$productId: ID!
$variantsFirst: Int = 1
$imagesFirst: Int = 5
) {
productRecommendations(productId: $productId) {
description
handle
id
images(first: $imagesFirst) {
edges {
node {
id
originalSrc
altText
}
}
}
priceRange {
maxVariantPrice {
amount
}
minVariantPrice {
amount
}
}
productType
tags
title
variants(first: $variantsFirst) {
edges {
node {
sku
availableForSale
id
compareAtPriceV2 {
amount
currencyCode
}
priceV2 {
amount
currencyCode
}
title
image {
id
originalSrc
altText
}
}
}
}
}
}
` as import('../../../__generated__/ts-gql/productRecommendations').type;
export type ProductRecommendations =
typeof PRODUCT_RECOMMENDATIONS['___type']['result']['productRecommendations'];
export async function getProductRecommendations(
client: Client,
productId: string,
variantsFirst?: number,
imagesFirst?: number
): Promise<ProductRecommendations | void> {
const { data } = await client.query({
query: PRODUCT_RECOMMENDATIONS,
variables: {
productId,
variantsFirst,
imagesFirst,
},
});
return data?.productRecommendations;
}
Is this because I'm using the Shopify Lite plan? I'd really like to use this feature if possible for a headless Shopify site that I'm building with Next.js.
Hello @lukebennett! Have you succeeded with Product Recommendations with StoreFront API?
I'm trying to use such SDK: https://www.npmjs.com/package/shopify-buy#builds
but it seems it doesn't support the Product Recommendation method.
Best I can tell it's not available unless you're on the Shopify Plus plan:
https://shopify.dev/themes/product-merchandising/recommendations#requirements-and-limitations
Pretty sure I've seen product recommendations used in themes before, but I guess they used a different API...
User | RANK |
---|---|
43 | |
42 | |
31 | |
9 | |
9 |