Magento 2 How to get Simple Products in GraphQL

We all know that Simple Products can be sold individually or as a part of configurable, grouped, or bundle products. Now, In this article, we will explain to you how to get simple products.

This query searches for products that match the specified search criteria. Also, this query use for all filter attributes, search, pageSize, currentPage, sort, and use aggregations (Layered Navigation Aggregations). Just like use fields attribute_code, count, label, options (In Array).

The following query returns information about the product with a sku of any.

Request

saveCopyzoom_out_map
{ products(filter: { sku: { eq: "24-MB01" } }) { total_count sort_fields { default options { label value __typename } } aggregations { count attribute_code label __typename options { count label value } } page_info { current_page page_size total_pages __typename } items { id name sku url_key stock_status new_from_date new_to_date special_price special_from_date special_to_date __typename short_description { html } description { html } sale new gender attribute_set_id meta_title meta_keyword meta_description manufacturer size color country_of_manufacture gift_message_available image { url label } small_image { url label } thumbnail { url label } swatch_image media_gallery { url label } categories { id name is_anchor url_key url_path level display_mode default_sort_by description } price_range { minimum_price { regular_price { value currency } final_price { value currency } } maximum_price { regular_price { value currency } final_price { value currency } } } price_tiers { quantity final_price { value currency } } } } }

Response

saveCopyzoom_out_map
{ "data": { "products": { "total_count": 1, "sort_fields": { "default": "position", "options": [ { "label": "Position", "value": "position", "__typename": "SortField" }, { "label": "Product Name", "value": "name", "__typename": "SortField" }, { "label": "Price", "value": "price", "__typename": "SortField" } ] }, "aggregations": [ { "count": 1, "attribute_code": "price", "label": "Price", "__typename": "Aggregation", "options": [ { "count": 1, "label": "40-*", "value": "40_*" } ] }, { "count": 2, "attribute_code": "category_id", "label": "Category", "__typename": "Aggregation", "options": [ { "count": 1, "label": "Gear", "value": "3" }, { "count": 1, "label": "Bags", "value": "4" } ] }, { "count": 1, "attribute_code": "color", "label": "Color", "__typename": "Aggregation", "options": [ { "count": 1, "label": "Black", "value": "5476" } ] }, { "count": 1, "attribute_code": "eco_collection", "label": "Eco Collection", "__typename": "Aggregation", "options": [ { "count": 1, "label": "0", "value": "0" } ] }, { "count": 1, "attribute_code": "erin_recommends", "label": "Erin Recommends", "__typename": "Aggregation", "options": [ { "count": 1, "label": "0", "value": "0" } ] }, { "count": 1, "attribute_code": "new", "label": "New", "__typename": "Aggregation", "options": [ { "count": 1, "label": "0", "value": "0" } ] }, { "count": 1, "attribute_code": "performance_fabric", "label": "Performance Fabric", "__typename": "Aggregation", "options": [ { "count": 1, "label": "0", "value": "0" } ] }, { "count": 1, "attribute_code": "sale", "label": "Sale", "__typename": "Aggregation", "options": [ { "count": 1, "label": "0", "value": "0" } ] } ], "page_info": { "current_page": 1, "page_size": 20, "total_pages": 1, "__typename": "SearchResultPageInfo" }, "items": [ { "id": 1, "name": "Joust Duffle Bag", "sku": "24-MB01", "url_key": "joust-duffle-bag", "stock_status": "IN_STOCK", "new_from_date": null, "new_to_date": null, "special_price": null, "special_from_date": null, "special_to_date": null, "__typename": "SimpleProduct", "short_description": { "html": "" }, "description": { "html": "<p>The sporty Joust Duffle Bag can't be beat - not in the gym, not on the luggage carousel, not anywhere. Big enough to haul a basketball or soccer ball and some sneakers with plenty of room to spare, it's ideal for athletes with places to go.<p>" }, "sale": 0, "new": 0, "gender": null, "attribute_set_id": 15, "meta_title": null, "meta_keyword": null, "meta_description": null, "manufacturer": null, "size": null, "color": 5476, "country_of_manufacture": null, "gift_message_available": "0", "image": { "url": "http://domain.com/pub/media/catalog/product/cache/1548177c389d2065a93f4e1eaab84907/m/b/mb01-blue-0.jpg", "label": "Image" }, "small_image": { "url": "http://domain.com/pub/media/catalog/product/cache/1548177c389d2065a93f4e1eaab84907/m/b/mb01-blue-0.jpg", "label": "Image" }, "thumbnail": { "url": "http://domain.com/pub/media/catalog/product/cache/1548177c389d2065a93f4e1eaab84907/m/b/mb01-blue-0.jpg", "label": "Image" }, "swatch_image": null, "media_gallery": [ { "url": "http://domain.com/pub/media/catalog/product/cache/1548177c389d2065a93f4e1eaab84907/m/b/mb01-blue-0.jpg", "label": "Image" } ], "categories": [ { "id": 3, "name": "Gear", "is_anchor": 0, "url_key": "gear", "url_path": "gear", "level": 2, "display_mode": "PAGE", "default_sort_by": null, "description": null }, { "id": 4, "name": "Bags", "is_anchor": 1, "url_key": "bags", "url_path": "gear/bags", "level": 3, "display_mode": "PRODUCTS", "default_sort_by": null, "description": "<p><strong>Lorem Ipsum</strong> is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.</p>" } ], "price_range": { "minimum_price": { "regular_price": { "value": 34, "currency": "USD" }, "final_price": { "value": 34, "currency": "USD" } }, "maximum_price": { "regular_price": { "value": 34, "currency": "USD" }, "final_price": { "value": 34, "currency": "USD" } } }, "price_tiers": [] } ] } } }

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.




Recent Articles
Tags
Newsletter
Chrome Extension
Copyright © 2024 devhooks.in All rights reserved.
Ads OFF toggle_off
wifi_off