Magento 2 How to get Category Product Colletion in GraphQL
If you want to get product collection from a category then you are in the right place. In this tutorial, we will explain to you how to get products from category. You can get all product data like product's total_count, id, SKU, etc ...
-
Use the
categoryList
query returns also category product collection. -
This query searches for products, which allowed search by category filter with IDs.
Request
saveCopyzoom_out_map{
categoryList(filters: {ids: {eq: "10"}}) {
products {
total_count
items{
id
sku
name
url_key
stock_status
new
image{
url
label
position
}
small_image{
url
label
position
}
thumbnail{
url
label
position
}
short_description{
html
}
description{
html
}
price_range{
minimum_price{
regular_price{
value
currency
}
final_price{
value
currency
}
}
maximum_price{
regular_price{
value
currency
}
final_price{
value
currency
}
}
}
new_from_date
new_to_date
special_price
special_from_date
special_to_date
gift_message_available
country_of_manufacture
price_tiers{
quantity
final_price{
value
currency
}
discount{
amount_off
percent_off
}
}
}
page_info {
current_page
page_size
}
}
}
}
Response
saveCopyzoom_out_map{
"data": {
"categoryList": [
{
"products": {
"total_count": 6,
"items": [
{
"id": 47,
"sku": "240-LV04",
"name": "Beginner's Yoga",
"url_key": "beginner-s-yoga",
"stock_status": "IN_STOCK",
"new": null,
"image": {
"url": "http://domain.com/pub/media/catalog/product/cache/1548177c389d2065a93f4e1eaab84907/l/t/lt01.jpg",
"label": "Beginner's Yoga",
"position": null
},
"small_image": {
"url": "http://domain.com/pub/media/catalog/product/cache/1548177c389d2065a93f4e1eaab84907/l/t/lt01.jpg",
"label": "Beginner's Yoga",
"position": null
},
"thumbnail": {
"url": "http://domain.com/pub/media/catalog/product/cache/1548177c389d2065a93f4e1eaab84907/l/t/lt01.jpg",
"label": "Beginner's Yoga",
"position": null
},
"short_description": {
"html": "<p>\nThe most difficult yoga poses to master are the ones learned incorrectly as a beginner. Luma's Beginner's Yoga is a fantastic way to break into your initial yoga session and begin the journey to a longer, leaner, healthier body. Confidently find your way into yoga with this effective yet gentle program. You'll learn proper alignment and how to sidestep common mistakes.\n</p>"
},
"description": {
"html": "<p>Beginner's Yoga starts you down the path toward strength, balance and mental focus. With this video download, you don't have to be a great athlete or gym guru to learn the best and most basic techniques for lifelong yoga foundation. </p>\n<ul>\n<li>Video download</li>\n<li>Five workouts.</li>\n<li>Balance, strength and endurance.</li>\n<li>Flexibility and core strength.</li>\n<li>Includes modification for novices.</li>\n</ul>"
},
"price_range": {
"minimum_price": {
"regular_price": {
"value": 6,
"currency": "USD"
},
"final_price": {
"value": 6,
"currency": "USD"
}
},
"maximum_price": {
"regular_price": {
"value": 6,
"currency": "USD"
},
"final_price": {
"value": 6,
"currency": "USD"
}
}
},
"new_from_date": null,
"new_to_date": null,
"special_price": null,
"special_from_date": null,
"special_to_date": null,
"gift_message_available": null,
"country_of_manufacture": null,
"price_tiers": []
},
{
"id": 48,
"sku": "240-LV05",
"name": "LifeLong Fitness IV",
"url_key": "lifelong-fitness-iv",
"stock_status": "IN_STOCK",
"new": null,
"image": {
"url": "http://domain.com/pub/media/catalog/product/cache/1548177c389d2065a93f4e1eaab84907/l/t/lt02.jpg",
"label": "LifeLong Fitness IV",
"position": null
},
"small_image": {
"url": "http://domain.com/pub/media/catalog/product/cache/1548177c389d2065a93f4e1eaab84907/l/t/lt02.jpg",
"label": "LifeLong Fitness IV",
"position": null
},
"thumbnail": {
"url": "http://domain.com/pub/media/catalog/product/cache/1548177c389d2065a93f4e1eaab84907/l/t/lt02.jpg",
"label": "LifeLong Fitness IV",
"position": null
},
"short_description": {
"html": "<p>\nThe instructors and routines featured in LifeLong Fitness IV provide safe options to serve all types of physical conditions and abilities. Range of motion, body awareness and breathing practices are essential tools of yogic self-care, essential for maintaining alertness, health, and dignity over a lifetime. The LifeLong Fitness series acknowledges that as we age, the safety and sustainability of our exercise become as important as pushing our limits.\n</p>"
},
"description": {
"html": "<p>Luma LifeLong Fitness Series is a world recognized, evidence based exercise program designed specifically for individuals focused on staying active their whole lives. If followed regularly, participants will see improved heart rate and blood pressure, increased mobility, reduced joint pain and overall improvement in functional fitness and health.</>\n<ul>\n<li>10 minute warm up.</li>\n<li>30 minutes of mild aerobics.</li>\n<li>20 minutes of strength, stretch and balance.</li>\n<li>Extensive modifications for varying fitness levels.</li>\n</ul>"
},
"price_range": {
"minimum_price": {
"regular_price": {
"value": 14,
"currency": "USD"
},
"final_price": {
"value": 14,
"currency": "USD"
}
},
"maximum_price": {
"regular_price": {
"value": 14,
"currency": "USD"
},
"final_price": {
"value": 14,
"currency": "USD"
}
}
},
"new_from_date": null,
"new_to_date": null,
"special_price": null,
"special_from_date": null,
"special_to_date": null,
"gift_message_available": null,
"country_of_manufacture": null,
"price_tiers": []
},
{
"id": 49,
"sku": "240-LV06",
"name": "Yoga Adventure",
"url_key": "yoga-adventure",
"stock_status": "IN_STOCK",
"new": null,
"image": {
"url": "http://domain.com/pub/media/catalog/product/cache/1548177c389d2065a93f4e1eaab84907/l/t/lt03.jpg",
"label": "Yoga Adventure",
"position": null
},
"small_image": {
"url": "http://domain.com/pub/media/catalog/product/cache/1548177c389d2065a93f4e1eaab84907/l/t/lt03.jpg",
"label": "Yoga Adventure",
"position": null
},
"thumbnail": {
"url": "http://domain.com/pub/media/catalog/product/cache/1548177c389d2065a93f4e1eaab84907/l/t/lt03.jpg",
"label": "Yoga Adventure",
"position": null
},
"short_description": {
"html": "<p>\nThe practices on this downloadable training video are recommended only for experienced to advanced students. Those with the fundamental skills needed won't want to miss the insight and advice from world-renowned trainer Erin Renny in these exclusive Luma guided yoga sessions. Complete body, arm balance and leg strength workouts engage, strengthen and increase mobility.\n</p>"
},
"description": {
"html": "<p>Luma presents an innovative power vinyasa yoga class for intermediate and advanced practitioners. The video allows you to pace yourself, but more intense work yields longer rest. This class is great for more advanced students looking to learn proper alignment in their yoga practice.</p>\n<ul>\n<li>Includes a breakdown of 12 different postures.</li>\n<li>Chataranga Dandasana and prayer twist.</li>\n<li>Challenging posture (side crow).</li>\n<li>55 minutes of movement.</li>\n</ul>"
},
"price_range": {
"minimum_price": {
"regular_price": {
"value": 22,
"currency": "USD"
},
"final_price": {
"value": 22,
"currency": "USD"
}
},
"maximum_price": {
"regular_price": {
"value": 22,
"currency": "USD"
},
"final_price": {
"value": 22,
"currency": "USD"
}
}
},
"new_from_date": null,
"new_to_date": null,
"special_price": null,
"special_from_date": null,
"special_to_date": null,
"gift_message_available": null,
"country_of_manufacture": null,
"price_tiers": []
},
{
"id": 50,
"sku": "240-LV07",
"name": "Solo Power Circuit",
"url_key": "solo-power-circuit",
"stock_status": "IN_STOCK",
"new": null,
"image": {
"url": "http://domain.com/pub/media/catalog/product/cache/1548177c389d2065a93f4e1eaab84907/l/t/lt04.jpg",
"label": "Solo Power Circuit",
"position": null
},
"small_image": {
"url": "http://domain.com/pub/media/catalog/product/cache/1548177c389d2065a93f4e1eaab84907/l/t/lt04.jpg",
"label": "Solo Power Circuit",
"position": null
},
"thumbnail": {
"url": "http://domain.com/pub/media/catalog/product/cache/1548177c389d2065a93f4e1eaab84907/l/t/lt04.jpg",
"label": "Solo Power Circuit",
"position": null
},
"short_description": {
"html": "<p>\nMany contemporary exercise trends sacrifice form and precision in favor of reps and \"PR\" goals. Luma's Solo Power Circuit teaches techniques to keep you safe. But don't think you'll get off easily: when it comes to building muscle and burning fat, these routines won't disappoint. A fusion of circuit training, yoga, Pilates and running, Solo Power Circuit brings out your sweatiest best.\n</p>"
},
"description": {
"html": "<p>Circuit training helps banish the boredom of traditional workouts. The Solo Power Circuit download lets you experience Luma's maximum efficiency circuit training in the training time you have available. Learn secrets to shed pounds, decrease body fat, sculpt amazing abs, and tone to reshape your entire body. You'll feel the difference after just one circuit.</p>\n<ul>\n<li>Targets abs, arms and legs.</li>\n<li>6 fun interval training circuits.</li>\n<li>Easy to follow.</li>\n<li>No special equipment needed.</li>\n<li>43 minutes.</li>\n</ul>"
},
"price_range": {
"minimum_price": {
"regular_price": {
"value": 14,
"currency": "USD"
},
"final_price": {
"value": 14,
"currency": "USD"
}
},
"maximum_price": {
"regular_price": {
"value": 14,
"currency": "USD"
},
"final_price": {
"value": 14,
"currency": "USD"
}
}
},
"new_from_date": null,
"new_to_date": null,
"special_price": null,
"special_from_date": null,
"special_to_date": null,
"gift_message_available": null,
"country_of_manufacture": null,
"price_tiers": []
},
{
"id": 51,
"sku": "240-LV08",
"name": "Advanced Pilates & Yoga (Strength)",
"url_key": "advanced-pilates-yoga-strength",
"stock_status": "IN_STOCK",
"new": null,
"image": {
"url": "http://domain.com/pub/media/catalog/product/cache/1548177c389d2065a93f4e1eaab84907/l/t/lt05.jpg",
"label": "Advanced Pilates & Yoga (Strength)",
"position": null
},
"small_image": {
"url": "http://domain.com/pub/media/catalog/product/cache/1548177c389d2065a93f4e1eaab84907/l/t/lt05.jpg",
"label": "Advanced Pilates & Yoga (Strength)",
"position": null
},
"thumbnail": {
"url": "http://domain.com/pub/media/catalog/product/cache/1548177c389d2065a93f4e1eaab84907/l/t/lt05.jpg",
"label": "Advanced Pilates & Yoga (Strength)",
"position": null
},
"short_description": {
"html": "<p>\nNo equipment needed. Advanced Pilates & Yoga (Strength) is a muscle-defining program that employs balance, cardio and flexibility movements with plyometric and body-weight based exercises for an all-around, physically challenging workout. The Pilates elements of this compilation bring gentle resistance principals into the routines, emphasizing safety, technique and range of motion.\n</p>"
},
"description": {
"html": "<p>Advanced Pilates & Yoga will help you to increase your flexibility and tone core muscle groups through an invigorating workout for your whole body. The Pilates workout is a thorough strength-conditioning session that boosts flexibility, endurance and posture. The Yoga workout incorporates legacy and new poses into one continuous routine that will leave you feeling exhausted and fulfilled at once.</p>\n<ul>\n<li>Pilates-Yoga fusion.</li>\n<li>Breathing warmup and cooldown.</li>\n<li>Hour-long session.</li>\n<li>High-definition video.</li>\n<ul>"
},
"price_range": {
"minimum_price": {
"regular_price": {
"value": 18,
"currency": "USD"
},
"final_price": {
"value": 18,
"currency": "USD"
}
},
"maximum_price": {
"regular_price": {
"value": 18,
"currency": "USD"
},
"final_price": {
"value": 18,
"currency": "USD"
}
}
},
"new_from_date": null,
"new_to_date": null,
"special_price": null,
"special_from_date": null,
"special_to_date": null,
"gift_message_available": null,
"country_of_manufacture": null,
"price_tiers": []
},
{
"id": 52,
"sku": "240-LV09",
"name": "Luma Yoga For Life",
"url_key": "luma-yoga-for-life",
"stock_status": "IN_STOCK",
"new": null,
"image": {
"url": "http://domain.com/pub/media/catalog/product/cache/1548177c389d2065a93f4e1eaab84907/l/t/lt06.jpg",
"label": "Luma Yoga For Life",
"position": null
},
"small_image": {
"url": "http://domain.com/pub/media/catalog/product/cache/1548177c389d2065a93f4e1eaab84907/l/t/lt06.jpg",
"label": "Luma Yoga For Life",
"position": null
},
"thumbnail": {
"url": "http://domain.com/pub/media/catalog/product/cache/1548177c389d2065a93f4e1eaab84907/l/t/lt06.jpg",
"label": "Luma Yoga For Life",
"position": null
},
"short_description": {
"html": "<p>\nLuma founder Erin Renny on yoga and longevity: \"I won't promise you'll live longer with yoga. No one can promise that. But your life will be healthier, less stressful, and more physically in tune when you focus on connecting your mind and body or a regular basis. Yoga is my favorite way to express this connection. I want to share the secrets of lifelong yoga with anyone willing to breathe and learn with me.\"\n</p>"
},
"description": {
"html": "<ul><li>Increase strength + flexibility + metabolism</li><li>Burn calories + feel great</li><li>Gain energy + youthfulness + mental wellness</li> </ul><h3 style=\"margin-top: 30px;\">Download description</h3><p><strong style=\"display: block; margin: 20px 0 5px;\">Tone up mind and body</strong>Pro Yoga Instructor and Master Practitioner Marie Peale helps tone and sculpt your physique with her invigorating yet gentle approach.</p><p>You'll learn to use yoga to relax, control stress and increase your calorie-burning capacity, all while exploring traditional and new yoga poses that lengthen and strengthen your full muscular structure. </p><ul><li>Easy download</li><li>Audio options: Music and instruction or instruction only</li><li>Heart rate techniques explained</li><li>Breathing techniques explained</li><li>Move through exercises at your own pace</li></ul><p>Two 25-minute workout episodes and one 40-minute workout episode with warm-up and cool down:</p><p><strong style=\"display: block; margin: 20px 0 5px;\">Episode 1</strong>Creative, fun session geared toward opening your lungs. Combines stretching and breathing with a focus on hips and shoulders. </p><p><strong style=\"display: block; margin: 20px 0 5px;\">Episode 2</strong>Ramp up the tempo and energy with calorie-burning flows. A stimulating workout introducing the body-sculpting power of yoga.</p><p><strong style=\"display: block; margin: 20px 0 5px;\">Episode 3</strong>Push your fitness reach and stamina with an intense series of standing and floor exercises and poses. End this extra-length session with a meditative cool down.</p><h3 style=\"margin-top: 30px;\">instructor bio</h3><p><strong style=\"display: block; margin: 20px 0 5px;\">About Marie</strong>Marie is a trained martial artist and dancer with a BS in Biological Engineering and over 10 years as a certified yoga teacher. Marie has studied yoga in England, India and, in 2009, at the Ashraqat Ashram Yoga Farm in the United States. She has been teaching full time since then. Her focus on strength and wellness combines a deep knowledge of human biology and motivation guided by unconditional love for her audience.</p>"
},
"price_range": {
"minimum_price": {
"regular_price": {
"value": 0,
"currency": "USD"
},
"final_price": {
"value": 0,
"currency": "USD"
}
},
"maximum_price": {
"regular_price": {
"value": 0,
"currency": "USD"
},
"final_price": {
"value": 0,
"currency": "USD"
}
}
},
"new_from_date": null,
"new_to_date": null,
"special_price": null,
"special_from_date": null,
"special_to_date": null,
"gift_message_available": null,
"country_of_manufacture": null,
"price_tiers": []
}
],
"page_info": {
"current_page": 1,
"page_size": 20
}
}
}
]
}
}
That's it!!
If you are looking for more GraphQL solutions then check out our another article which is List of GraphQL Queries and Mutations for Magento 2.
I hope this article helps you to find what you were looking for.
Bookmark it for your future reference. Do comment below if you have any other questions on that.
P.S. Do share this article with your team.