grahpql productRecommendations returns the title and the desc of the main product

grahpql productRecommendations returns the title and the desc of the main product

Koffein
Shopify Partner
5 1 1

Title.

 

The

 

productRecommendations(productId: "productId", intent: COMPLEMENTARY) {

graphql call returns correct information, except for the title and description of the complementary products.

 

The title and the description are instead of the main products, which is a bit weird.

 

Any ideas, solutions?

Replies 4 (4)

Liam
Community Manager
3108 341 879

HI Koffein,

 

If you're getting unexpected results when using the `productRecommendations` query in Shopify's GraphQL API, it could be due to a misinterpretation of the query structure. Specifically, you should ensure that you're structuring your query correctly to access the properties of the recommended products. Can you share the full query?

 

Hope this helps,

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

Koffein
Shopify Partner
5 1 1

Hey Liam,

 

While prepping to answer you, I found the problem 🦆

The localization of the mock products in our shop was not complete and I was getting the wrong data from the correct product, but only because someone put it there (or did not update the translations).

 

Thanks for the help anyway! 😬

Liam
Community Manager
3108 341 879

No worries! This is easy to happen - glad you figured it out!

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

Khasim1
Shopify Partner
30 0 0

Hi @Liam 

 

Can you let me know if complementary products on the Hydrogen store are the one which will be based on the configuration in admin or these products are generated by Shopify and displayed. Because I have configured different products in the Search and Discovery app but when I run the query I get other products. 
Here is the query for same:

export let COMPLEMENT_PRODUCT_QUERY = `#graphql
  query getComplementaryProductRecommendations(
    $productId: ID!
    $count: Int
    $country: CountryCode
    $language: LanguageCode
    $intent: ProductRecommendationIntent!
  ) @inContext(country: $country, language: $language) {
    complementary: productRecommendations(intent: $intent, productId: $productId ) {
        ...ProductCard
    }
    additional: products(first: $count) {
      nodes {
        ...ProductCard
      }
    }
  }
  ${PRODUCT_CARD_FRAGMENT}
`;
Thanks