Cross-Sell Product GraphQL Query in Magento 2 to get all the cross-sell items as an output with GraphQL response.
You can fetch the Cross-sell Product from the Product GraphQL Query by applying the product SKU as a filter name.
Before going with the current article, Check full details of Product Query, Brief details of Product Query GraphQL in Magento.
Cross-Sell Product GraphQL Query Magento 2 Payload,
{
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
}
}
}
}
}
}
}
crosssell_products{}
field used to retrieve cross-sell items of the product. You can set any field to retrieve as output from the Product Query.
Output for the Magento Sample Data,
{
"data": {
"products": {
"items": [
{
"id": 1,
"name": "Joust Duffle Bag",
"crosssell_products": [
{
"id": 20,
"sku": "24-UG01",
"stock_status": "IN_STOCK",
"short_description": {
"html": ""
},
"url_key": "quest-lumaflex-trade-band",
"name": "Quest Lumaflex™ Band",
"special_price": null,
"price_range": {
"minimum_price": {
"final_price": {
"value": 19,
"currency": "USD"
}
},
"maximum_price": {
"final_price": {
"value": 19,
"currency": "USD"
}
}
}
},
{
"id": 32,
"sku": "24-WG083-blue",
"stock_status": "IN_STOCK",
"short_description": {
"html": ""
},
"url_key": "sprite-stasis-ball-75-cm-blue",
"name": "Sprite Stasis Ball 75 cm",
"special_price": null,
"price_range": {
"minimum_price": {
"final_price": {
"value": 32,
"currency": "USD"
}
},
"maximum_price": {
"final_price": {
"value": 32,
"currency": "USD"
}
}
}
},
{
"id": 34,
"sku": "24-WG086",
"stock_status": "IN_STOCK",
"short_description": {
"html": ""
},
"url_key": "sprite-yoga-strap-8-foot",
"name": "Sprite Yoga Strap 8 foot",
"special_price": null,
"price_range": {
"minimum_price": {
"final_price": {
"value": 17,
"currency": "USD"
}
},
"maximum_price": {
"final_price": {
"value": 17,
"currency": "USD"
}
}
}
},
{
"id": 51,
"sku": "24-WG085_Group",
"stock_status": "IN_STOCK",
"short_description": {
"html": ""
},
"url_key": "set-of-sprite-yoga-straps",
"name": "Set of Sprite Yoga Straps",
"special_price": null,
"price_range": {
"minimum_price": {
"final_price": {
"value": 14,
"currency": "USD"
}
},
"maximum_price": {
"final_price": {
"value": 14,
"currency": "USD"
}
}
}
}
]
}
]
}
}
}
You can add/remove the field based on your requirement in the product Query. This is the demonstration purpose only.
You can also interested to read GraphQL Query,
- Get Related Product GraphQL Query in Magento 2.
- Get Upsell Product GraphQL Query Magento 2.