Retrieve Cross-Sell Products

How to Retrieve Cross-Sell Products Using GraphQL in Magento 2?

Fetching cross-sell product details using GraphQL in Magento 2 is a powerful way to retrieve related items for a product. Cross-sell products are displayed as suggestions during the checkout process, helping merchants boost sales and enhance the shopping experience.

This guide provides a detailed explanation of how to use GraphQL to fetch cross-sell products based on a product SKU. We'll cover the query structure, its customization options, and how to interpret the response.

What Are Cross-Sell Products?

Cross-sell products are strategically chosen items suggested to customers during the cart or checkout process. These products complement the items already in the customer’s cart and encourage additional purchases, driving both higher cart values and an improved shopping experience. Cross-sells target the "impulse buy" mindset and are effective for upselling or bundling related products.

Example of Cross-Sell Products:

  • Main Product: Joust Duffle Bag
  • Cross-Sell Suggestions: Quest Lumaflex™ Band, Sprite Stasis Ball 75 cm

Key Benefits of Cross-Sell Products:

  • Increased Average Order Value (AOV): Encourage customers to add more items, boosting revenue per transaction.
  • Improved Customer Experience: Help customers discover useful, complementary items.
  • Targeted Recommendations: Leverage customer behavior and preferences for relevant product suggestions.
  • Reduced Cart Abandonment: Engage customers with attractive offers before they leave the checkout page.

How Cross-Sell Products Differ from Related or Upsell Products:

Aspect Cross-Sell Products Upsell Products
Placement Shown on the cart or checkout page Shown on the product page
Purpose Encourage customers to add complementary items Suggest higher-end or premium versions of a product
Example Scenario A water bottle added to a cart with a yoga mat Suggesting a higher-priced yoga mat

Tips for Effective Cross-Selling:

  • Analyze Customer Behavior: Use analytics to identify frequently purchased combinations.
  • Highlight Value: Show why the additional product enhances the main product.
  • Keep It Relevant: Suggest only items that make sense with the main product.
  • Leverage Discounts or Bundles: Offer discounts for adding cross-sell items to incentivize purchases.

Incorporating cross-sell products is a powerful way to improve customer satisfaction and increase sales.

Show to Use the Cross-Sell Product GraphQL Query in Magento 2?

Fetching cross-sell products in Magento 2 via GraphQL allows you to display relevant suggestions dynamically, enhancing the user experience and boosting revenue. Below is a guide on how to structure and understand this query.

GraphQL Query Structure

{

"products"(filter: { "sku": { "eq": "24-MB01" } }) {

"items" {

"id",

"name",

"crosssell_products" {

"id",

"sku",

"stock_status",

"short_description" {

"html"

},

"url_key",

"name",

"special_price",

"price_range" {

"minimum_price" {

"final_price" {

"value",

"currency"

}

},

"maximum_price" {

"final_price" {

"value",

"currency"

}

}

}

}

}

}

}

Query Breakdown

Field Name Description
filter Filters products using SKU to fetch specific product details.
crosssell_products Retrieves all cross-sell products associated with the given SKU.
price_range Provides pricing details, including minimum and maximum prices.
special_price Displays promotional pricing if available.
stock_status Indicates whether the product is in stock or out of stock.
short_description Includes a brief description of the cross-sell products.
url_key Provides the URL path for direct navigation to the product page.

You can modify this query to include additional fields like images or inventory data, depending on your requirements.

Sample GraphQL Response

{

"data": {

"products": {

"items": [

{

"id": 1,

"name": "Joust Duffle Bag",

"crosssell_products": [

{

"id": 20,

"sku": "24-UG01",

"stock_status": "IN_STOCK",

"url_key": "quest-lumaflex-trade-band",

"name": "Quest Lumaflex™ Band",

"price_range": {

"minimum_price": {

"final_price": {

"value": 19,

"currency": "USD"

}

}

}

},

{

"id": 32,

"sku": "24-WG083-blue",

"stock_status": "IN_STOCK",

"url_key": "sprite-stasis-ball-75-cm-blue",

"name": "Sprite Stasis Ball 75 cm",

"price_range": {

"minimum_price": {

"final_price": {

"value": 32,

"currency": "USD"

}

}

}

}

]

}

]

}

}

}

Use Cases for Cross-Sell GraphQL Query

  • Boosting Cart Value: Dynamically fetch complementary products to increase the likelihood of impulse purchases.
  • Improving User Experience: Offer tailored suggestions based on the selected products in the cart.
  • Promotional Campaigns: Use special_price to highlight ongoing deals on cross-sell items.

Benefits of Using GraphQL for Cross-Sell Products

  • Flexibility: Query only the fields you need, reducing payload size.
  • Single Endpoint: Avoid multiple calls for fetching related information.
  • Customization: Easily adapt the query for unique business requirements.

By leveraging the GraphQL query for cross-sell products, Magento 2 store owners can provide personalized shopping experiences, ultimately driving higher conversion rates.

Steps to Implement Cross-Sell Product Query

Set Up GraphQL Endpoint:

  • Use a GraphQL client or tool like GraphiQL to test your queries.
  • Ensure your Magento 2 instance has the required permissions for GraphQL access.

Customize the Query:

  • Modify fields in the query to include only necessary data, such as images or inventory status.

Test and Optimize:

  • Verify the query response to ensure it matches your requirements.
  • Optimize by removing unnecessary fields to improve performance.

Additional Query Customizations for Cross-Sell Products

1. Including Product Images

To display product images in the cross-sell section, include the image field in your query. This ensures users can visually identify the suggested products, enhancing the shopping experience.

crosssell_products {

id

sku

name

image {

url

}

}

  • Example Use Case: Display product thumbnails alongside names and prices in the cross-sell carousel or grid layout.
  • Tip: Ensure that the image URLs are accessible from the frontend and optimized for web performance.

2. Fetching Inventory Details

To display the availability of cross-sell products, include inventory-related fields such as stock_status. This allows users to know whether the suggested items are in stock.

crosssell_products {

sku

stock_status

}

  • Example Output:
    • stock_status: IN_STOCK
    • stock_status: OUT_OF_STOCK
  • Advanced Integration: Combine this with inventory quantity to show the exact number of items left in stock, creating a sense of urgency.

3. Retrieving Product Prices

Include the price_range field to display the pricing details of cross-sell products. This field ensures accurate and up-to-date pricing, including any discounts.

crosssell_products {

price_range {

minimum_price {

final_price {

value

currency

}

}

}

}

  • Example Use Case: Display dynamic pricing based on customer groups, special promotions, or currency settings.
  • Tip: Highlight discounts or special offers on cross-sell products to increase conversions.

4. Fetching Short Descriptions

Enhance the cross-sell display by including a brief description of the products. Use the short_description field to provide users with a quick overview of the product’s features or benefits.

crosssell_products {

short_description

}

  • Example Use Case: Display a short summary beneath the product name to attract more attention and inform the user.

Comprehensive Benefits of Cross-Sell Queries

Boost Sales

  • Increased Average Order Value: Suggesting complementary products encourages customers to purchase more items.
  • Example: Recommending fitness accessories (e.g., resistance bands) alongside a yoga mat.

Enhanced User Experience

  • Personalized Recommendations: Cross-sell queries can be tailored based on browsing history or cart contents, improving relevance.
  • Example: Suggesting a matching laptop bag for a selected laptop.
  • Customizable and Scalable

  • Tailored Data Retrieval: Modify query fields to include exactly what you need, such as stock levels, pricing, or product categories.
  • Flexible Integration: Works seamlessly with Magento’s frontend, custom themes, or third-party integrations.
  • Example Query Combining All Fields

    {

    products(filter: { sku: { eq: "24-MB01" } }) {

    items {

    id

    name

    crosssell_products {

    id

    sku

    name

    image {

    url

    }

    stock_status

    price_range {

    minimum_price {

    final_price {

    value

    currency

    }

    }

    }

    short_description

    }

    }

    }

    }

    Example Use Case for Frontend Integration

    • Scenario: You want to display cross-sell products on the product detail page.
    • Implementation:
      • Use the query above to fetch data.
      • Dynamically render the cross-sell section in a slider or grid layout.
      • Include product images, prices, availability, and short descriptions for an engaging display.

    Pro Tips for Optimization

    • Lazy Loading Images: Use lazy loading techniques to improve page performance.
    • Caching Responses: Cache GraphQL responses for frequently accessed products to reduce server load.
    • Real-Time Updates: Leverage Magento’s event system to update cross-sell suggestions dynamically based on user actions.

    Tip

    To enhance your eCommerce store’s performance with Magento, focus on optimizing site speed by utilizing Emmo themes and extensions. These tools are designed for efficiency, ensuring your website loads quickly and provides a smooth user experience. Start leveraging Emmo's powerful solutions today to boost customer satisfaction and drive sales!

    Conclusion

    Leveraging Magento 2’s GraphQL capabilities to implement cross-sell product queries is a powerful way to enhance user experience and boost sales. By customizing queries, such as retrieving product details, images, stock status, prices, and short descriptions, you can provide personalized recommendations that drive customer engagement.

    The ability to filter and optimize queries ensures you only fetch the necessary data, improving performance and scalability. Including features like price ranges and stock statuses further empowers store owners to deliver accurate and relevant suggestions to customers, increasing their likelihood of purchasing complementary products.

    Incorporating these advanced GraphQL features not only simplifies data management but also aligns with modern eCommerce trends of personalization and efficiency. By following the outlined steps and examples, you can effectively implement cross-sell functionality to maximize the potential of your Magento 2 store.

    FAQs

    What is the purpose of cross-sell products in Magento 2?

    Cross-sell products are complementary items displayed to customers during their shopping journey, encouraging them to add more products to their cart and increase the average order value.

    How can I retrieve cross-sell products using GraphQL in Magento 2?

    You can use a GraphQL query to retrieve cross-sell products, including details like name, SKU, images, price, and stock status, by specifying the crosssell_products field in your query.

    What fields can I include in a cross-sell product query?

    Fields like product ID, name, SKU, stock status, image URLs, price range, and short description can be included to provide comprehensive product details.

    How do cross-sell products improve user experience?

    Cross-sell products enhance the shopping experience by offering personalized recommendations that match the customer’s interests, making it easier to find related items.

    What is the benefit of fetching stock status in cross-sell queries?

    Fetching stock status ensures that customers only see available products, reducing frustration and improving the likelihood of conversion.

    Can I include product images in cross-sell queries?

    Yes, you can include product images by adding the image { url } field in your GraphQL query to display visual product information.

    What is the significance of the price_range field in cross-sell queries?

    The price_range field provides pricing details, including the minimum price and currency, helping customers quickly understand product costs.

    How do I optimize cross-sell queries for better performance?

    To optimize cross-sell queries, include only the fields you need, such as images, prices, and stock status, and avoid unnecessary data to improve query speed.

    What tools can I use to test cross-sell product queries?

    You can use tools like GraphiQL, Postman, or Magento's built-in GraphQL interface to test and validate your cross-sell product queries.

    Can cross-sell product queries be customized for specific categories?

    Yes, you can customize cross-sell queries by applying filters to retrieve products from specific categories or based on other attributes like SKU.

    What is the role of the short_description field in cross-sell queries?

    The short_description field provides a brief overview of the product, helping customers quickly understand its features and benefits.

    How can cross-sell products boost sales in Magento 2 stores?

    Cross-sell products boost sales by promoting complementary items that customers are likely to buy together, increasing the overall order value.

    Are cross-sell products displayed on all pages?

    Cross-sell products are typically displayed on the cart page, but they can be configured to appear on other pages depending on the store’s requirements.