Edit in GitHubLog an issue

Create and manage grouped products tutorial

A grouped product consists of simple standalone products that are presented as a group. A group can contain variations of a single product or a collection of products that are to be sold together.

This tutorial describes how you can use the Adobe Commerce REST API to create and manage grouped products.

Before you begin#

  • Install a Commerce instance with sample data. The sample data defines a functional store, called Luma, that sells fitness clothing and accessories.

  • Install a REST client. You can use any REST client to send calls to Commerce. Postman is recommended.

  • Obtain an admin authorization token. All calls in this tutorial require administrator privileges. See Generate the admin token for more information.

Other resources#

  • REST Tutorials provides additional information about completing any Commerce REST tutorial.

1. Create an empty grouped product#

The first step is to create the grouped product container. In the next step, we'll add individual products to the grouped product.

Endpoint#

POST V1/products

Payload#

The attribute_set_id: 11 line corresponds to gear. The value of 4 for the visibility attribute indicates the product will be displayed on the storefront and can be searched.

Copied to your clipboard
1 {
2 "product":{
3 "sku":"new-grouped",
4 "name":"New Grouped Product",
5 "attribute_set_id":11,
6 "type_id":"grouped",
7 "visibility":4
8 }
9 }

Response#

Copied to your clipboard
1{
2 "id": 2053,
3 "sku": "new-grouped",
4 "name": "New Grouped Product",
5 "attribute_set_id": 11,
6 "status": 1,
7 "visibility": 4,
8 "type_id": "grouped",
9 "created_at": "2019-08-15 17:51:13",
10 "updated_at": "2019-08-15 17:51:13",
11 "extension_attributes": {
12 "website_ids": [
13 1
14 ],
15 "stock_item": {
16 "item_id": 2053,
17 "product_id": 2053,
18 "stock_id": 1,
19 "qty": 0,
20 "is_in_stock": false,
21 "is_qty_decimal": false,
22 "show_default_notification_message": false,
23 "use_config_min_qty": true,
24 "min_qty": 0,
25 "use_config_min_sale_qty": 1,
26 "min_sale_qty": 1,
27 "use_config_max_sale_qty": true,
28 "max_sale_qty": 10000,
29 "use_config_backorders": true,
30 "backorders": 0,
31 "use_config_notify_stock_qty": true,
32 "notify_stock_qty": 1,
33 "use_config_qty_increments": true,
34 "qty_increments": 0,
35 "use_config_enable_qty_inc": true,
36 "enable_qty_increments": false,
37 "use_config_manage_stock": true,
38 "manage_stock": true,
39 "low_stock_date": null,
40 "is_decimal_divided": false,
41 "stock_status_changed_auto": 0
42 }
43 },
44 "product_links": [],
45 "options": [],
46 "media_gallery_entries": [],
47 "tier_prices": [],
48 "custom_attributes": [
49 {
50 "attribute_code": "options_container",
51 "value": "container2"
52 },
53 {
54 "attribute_code": "url_key",
55 "value": "new-grouped-product"
56 },
57 {
58 "attribute_code": "required_options",
59 "value": "0"
60 },
61 {
62 "attribute_code": "has_options",
63 "value": "0"
64 },
65 {
66 "attribute_code": "category_ids",
67 "value": []
68 }
69 ]
70}

2. Populate the grouped product with simple products#

Now that we have created a grouped product, we need to add simple items to it. In this example, we add three types of backpacks.

Endpoint#

POST V1/products/new-grouped/links

Payload#

Copied to your clipboard
1 {
2 "items":[
3 {
4 "sku":"new-grouped",
5 "link_type":"associated",
6 "linked_product_sku":"24-WB01",
7 "linked_product_type":"simple",
8 "position":1,
9 "extension_attributes":{
10 "qty":1
11 }
12 },
13 {
14 "sku":"new-grouped",
15 "link_type":"associated",
16 "linked_product_sku":"24-WB02",
17 "linked_product_type":"simple",
18 "position":2,
19 "extension_attributes":{
20 "qty":1
21 }
22 },
23 {
24 "sku":"new-grouped",
25 "link_type":"associated",
26 "linked_product_sku":"24-WB05",
27 "linked_product_type":"simple",
28 "position":3,
29 "extension_attributes":{
30 "qty":1
31 }
32 }
33 ]
34 }

Response#

true

3. Add another simple product to the grouped product#

This step uses the PUT /V1/products/new-grouped/links endpoint to add an item to the grouped product.

Endpoint#

PUT /V1/products/new-grouped/links

Payload#

Copied to your clipboard
1 {
2 "entity":{
3 "sku":"new-grouped",
4 "link_type":"associated",
5 "linked_product_sku":"24-UG01",
6 "linked_product_type":"simple",
7 "position":4,
8 "extension_attributes":{
9 "qty":1
10 }
11 }
12 }

Response#

true

Verify the steps#

  1. Log into the Admin.

  2. Select Catalog > Products.

  3. Click on the New Grouped Product grouped product and expand the Grouped Products section.

    New grouped product

Add a grouped product to a cart#

Customers can now add this grouped products to their carts, as shown below.

Refer to the Order processing tutorial for more information about how to add items to a cart with REST.

Endpoint#

POST /V1/carts/mine/items

Payload#

Copied to your clipboard
1{
2 "cartItem": {
3 "sku": "new-grouped",
4 "qty": 1,
5 "quote_id": "3"
6 }
7}

Response#

Copied to your clipboard
1{
2 "item_id": 5,
3 "sku": "24-WB01",
4 "qty": 1,
5 "name": "Voyage Yoga Bag",
6 "price": 32,
7 "product_type": "grouped",
8 "quote_id": "3"
9}
  • Privacy
  • Terms of Use
  • Do not sell my personal information
  • AdChoices
Copyright © 2022 Adobe. All rights reserved.