DocumentationCommerceVideos and Tutorials

Create a grouped product

Last update: December 6, 2023
  • Topics:
  • Catalog Management
  • Admin Workspace
  • Backend Development
  • Integration
  • REST

CREATED FOR:

  • Beginner
  • Developer
  • User

A grouped product consists of simple standalone products that are presented as a group. You can offer variations of a single product or group them by season or theme. Before creating a grouped product, verify that all the simple products to include in the group are available in Adobe Commerce, and create any that do not exist.

In this tutorial, you learn how to create a grouped product using the REST API and the Adobe Commerce Admin.

Use the REST API to create a group product in the Admin:

  1. Create an empty grouped product.

  2. Create simple products for use in the grouped product.

  3. Populate the empty grouped product with simple products.

  4. Create an empty grouped product and associate the simple products.

    When you associate simple products to the grouped product, the sort order attribute (position) in the payload is used by the frontend to display the associated products in a desired order. If the position attribute is not specified, the products are displayed in the order that they were added to the grouped product.

When creating grouped products from the Adobe Commerce Admin, create the simple products first. When you are ready to create the grouped product, associate the simple products by assigning them to the grouped product in one batch.

Who is this video for?

  • Website managers
  • eCommerce merchandisers
  • New Adobe Commerce developers who want to learn how to create grouped products in Adobe Commerce using the REST API.

Video content

video poster

https://video.tv.adobe.com/v/3425920?learn=on

Transcript
Creating a grouped product with Adobe Commerce. For this exercise, I am going to be using the bearer token to communicate with my local Adobe Commerce instance. It’s just meant to be brought up that you should probably be using OAuth or perhaps even the admin users credentials rather than the bearer token. This has been deprecated, but for demo purposes, I’m just setting everything up because this is the quick and easiest way to do a demo. For grouped products, in this particular demonstration, I’m going to be creating three simple products first. Then we’re going to create the shell grouped product, which won’t have any associated products with it. We’re going to use a subsequent post URL to add two of our simple products, showing you that payload. Finally, we’re going to put the third simple product on and then our final example will be through the REST APIs. We’re going to delete one of those simple products from the group product. So let’s go ahead and just quickly create our three simple products. This endpoint is nothing new, it’s V1 products. Our payload, we just need to have a SKU, a name, the attribute set ID, a price, and then we just want to make this a simple product. If you’re curious where to get the attribute set ID, this comes from the Adobe Commerce instance. So if you log in and you find your attribute sets, this particular one doesn’t have anything but one attribute set, the default one. When you click on it, this ID number that you find up here, this is the ID number that you’re going to want to use for your API codes. So let’s go ahead and head back to our APIs. Simple product group one, we’re going to go ahead and send this. This is going to create one simple product for us. And great, we have a nice response back, that’s good. Let’s just quickly go ahead and do two and three. You’ll notice everything is very similar, the SKU, the name, the attribute set again, a different price, and once again, a simple product. So let’s just hit send. There’s that. And then our third one. Great. So we have our simple products. And the reason why we did this is we want, when we go to create our grouped product, we want to have everything in place that when we associate these simple products to this parent group product, everything’s ready to go. So let’s go ahead and create that shell grouped product and very similar payload. We need a SKU, a name, an attribute set ID. However, you’ll notice that this one is not a simple product. We want to make a grouped product. And here’s just another optional product attribute for visibility. Just wanted to show you that there are many available. I’m just keeping it to a limited set for this demo. So we’re going to go ahead and hit send on this post request and we have created our group product. And if you go down to the payload, the response, you’ll notice that there is no associated products and that’s expected because at this point, it doesn’t know that they exist. So we’re going to go ahead and we’re going to link the first two products to our new group product that we just created. The post URL is a little bit different. It’s V1 products and then the SKU of the grouped product that we’re trying to make an associated link with slash links. The payload will have items with an array. And in this case, we’re going to be adding two individual simple products to this group product. It’s going to be SKU one and SKU two. You’ll notice here that the link type is associated. The product link type is simple because these are simple products. There is a position number. This is mainly for the front end when it goes to reorganizing the associated products to this, it helps know which one to display first, second, third, et cetera. So this one, I created two different positions, position one and two. And then once again, another optional product attribute for quantity, just to show you that more exists. We’re going to hit send and this is going to link two products to our group product. When you get a response of true, that means everything was successful. So unlike the creation of the simple products or the group product, where you get a full response payload back, the adding of these children links simply is true or false. True is obviously good, false would be, there was something maybe wrong with the payload or you didn’t have permission to access the API endpoint or whatever. So now we’re going to go ahead and just get the details for this simple product. So let’s go ahead and I’m going to go back and we’re going to grab my SKU and let’s just get this value. So now when we get this product, we’re going to get all of its attributes. And if we go to the product link section, we’re going to see there are two new SKUs that are linked to this group product. And it’s SKU one and SKU two, which is exactly what we were hoping for. So the next step we can do is we can add our third product to this group product. And this URL for this put request is a little bit different. It’s V1 products. Then it’s going to be the SKU for the group product that we’re trying to associate with slash links. The payload’s a little bit different, entity is the key. And then inside of that, we need SKU, the link type of associated, the link SKU. So in this case, we’re going to add our third SKU. And this is a simple product. I chose position four just because I didn’t want to collide with the first two. And so one and two were used. And once again, this is just to show you that it is kind of arbitrary, but I just chose four. And then there’s another optional extension attributes for quantity, but we’re just showing you that it exists. So we’ll go ahead and just add this third SKU to our group product. And once again, true or false is expected. True is great, but it means everything was successful. Now, when we fetch the data for our group product, and we scroll down, we find that there are three associated products with this group product. SKU one, SKU two, and SKU three, which is great. That’s exactly what we wanted. So now the last demonstration for the APIs is how to remove a link from a group product. The method is going to be delete. The URL is a little bit different. It’s a V1 products, which is the same. The third element is the SKU for the grouped product. Slash links. And then this word associated is next. Now you get associated by knowing how you made these links part of this group product. And you can recall from our, when we posted these new links, we had some attributes in the array and the link type was associated. There are four to choose from, but for this demonstration, like I said, we decided to use associated because that’s what’s appropriate for a group product. But there are others available. And, but for this purpose, we didn’t need them because one’s cross-sell, one’s up-sell and one’s related. But once again, for this demonstration, the appropriate one would be the word associate. So to delete, once again, we need to do V1 products, the SKU for the group product that we’re trying to reference, the word links, and then associated because that’s the type of link that we’re gonna be removing. And then the last piece is the SKU for the children product that we’re trying to remove as part of this group product. There is no payload in the body because once again, we’re using a delete, everything’s in the URL. So when we hit send, once again, we’re looking for a Boolean response. So true is great. Now, when we go ahead and fetch the payload for this group product, we’re gonna be back down to two associated product links. We’ve got SKU one and SKU two. Let’s see what this looks like in the commerce admin. You get to this by going to catalog products. And you’ll see here that these last four are the SKUs that I created. So this was created via the API, via the API, via the API. And this is my group product that we created via the API. These first three are simple products that I created in the admin prior to this, cause I wanted to expedite this second phase of showing you how to create a group product from the app. So the only process that’s slightly different from using the admin versus using the API is when you’re in the commerce admin, you don’t have to do it in two steps. You can associate the simple products when you’re creating the grouped product, the shell parent product for this group. The required values for this are going to be the attribute set, the product name. So admin grouped product. SKUs a little bit irrelevant, but we’ll just leave that. And then you’ll go down to this section where it says grouped products. And we’re going to add some products to our group. And this is why having these products create ahead of time should expedite the entire process. So it’s going to bring up a nice modal window and you get to choose from your current catalog of products that you want to associate. And we’re just going to go ahead and just create and select these first three. And all you have to do is hit add selected products. It produces this nice grid view that says, this is what you were expecting to do. Have you made a mistake? You can remove them. Here’s your position numbers where you can make some modifications. And then at this point, if you’re happy and you don’t want to add any more values, once again, they’re all optional except for those three. You can go ahead and hit save and close. We’ll go down here to our last part that we created. And we’ll click on that row. And everything looks great. We have our three associated products with the SKU of Commerce Admin Product 1, product 3. Now we can take the SKU that we have here. We can go back to our API if we’re just curious and we can just fetch this to see what this looks like. And we’ll scroll down to the product links and we’ll see that, here we go. We’ve got product 1, product E, and then product 3. So that’s great. That just proves that everything we did was working as expected. And it’s exactly the same as the process and using the APIs. I hope this helped. And please continue your learning using Experience League.

Setup for the grouped product

In this example, there are three simple products (created first) and a grouped product. Two simple products are associated with the grouped product, and then the third simple product is added to the grouped product.

Create the first simple product using cURL

curl --location '{{your.url.here}}/rest/default/V1/products' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {{Your Bearer Token}}' \
--header 'Cookie: PHPSESSID=a42da0096288718c9556f77549c6305f; private_content_version=564dde2976849891583a9a649073f01e' \
--data '{
  "product": {
    "sku": "product-sku-one",
    "name": "Simple product one",
    "attribute_set_id": 4,
    "price": 1.11,
    "type_id": "simple"
  }
}

Create the second simple product using cURL

curl --location '{{your.url.here}}/rest/default/V1/products' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {{Your Bearer Token}}' \
--header 'Cookie: PHPSESSID=a42da0096288718c9556f77549c6305f; private_content_version=564dde2976849891583a9a649073f01e' \
--data '{
  "product": {
    "sku": "product-sku-two",
    "name": "Simple Product two",
    "attribute_set_id": 4,
    "price": 2.22,
    "type_id": "simple"
  }
}

Create the third simple product using cURL

curl --location '{{your.url.here}}/rest/default/V1/products' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {{Your Bearer Token}}' \
--header 'Cookie: PHPSESSID=a42da0096288718c9556f77549c6305f; private_content_version=564dde2976849891583a9a649073f01e' \
--data '{
  "product": {
    "sku": "product-sku-three",
    "name": "Simple product three",
    "attribute_set_id": 4,
    "price": 3.33,
    "type_id": "simple"
  }
}

Create an empty grouped product using cURL

curl --location '{{your.url.here}}/rest/default/V1/products' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {{Your Bearer Token}}' \
--header 'Cookie: PHPSESSID=28a020734488eef2600f8d5c7f302b53; private_content_version=564dde2976849891583a9a649073f01e' \
--data '{
    "product":{
        "sku":"my-new-grouped-product",
        "name":"This is my New Grouped Product",
        "attribute_set_id":4,
        "type_id":"grouped",
        "visibility":4
    }
}
'

Add the first and second simple products to the grouped product

curl --location '{{your.url.here}}/rest/default/V1/products/my-new-grouped-product/links' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {{Your Bearer Token}}' \
--header 'Cookie: PHPSESSID=28a020734488eef2600f8d5c7f302b53; private_content_version=564dde2976849891583a9a649073f01e' \
--data '{
    "items":[
        {
            "sku":"my-new-grouped-product",
            "link_type":"associated",
            "linked_product_sku":"product-sku-one",
            "linked_product_type":"simple",
            "position":1,
            "extension_attributes":{
            "qty":1
            }
        },
        {
            "sku":"my-new-grouped-product",
            "link_type":"associated",
            "linked_product_sku":"product-sku-two",
            "linked_product_type":"simple",
            "position":2,
            "extension_attributes":{
            "qty":1
            }
        }
    ]
}
'

Add the third simple product to the existing grouped product

Include the appropriate position number (anything except 1 or 2), which are used for the first two products originally associated to the grouped product. For this example, the position is 4.

curl --location --request PUT '{{your.url.here}}/rest/default/V1/products/my-new-grouped-product/links' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {{Your Bearer Token}}' \
--header 'Cookie: PHPSESSID=9e61396705e9c17423eca2bdf2deefb2' \
--data '{
    "entity":{
        "sku":"my-new-grouped-product",
        "link_type":"associated",
        "linked_product_sku":"product-sku-three",
        "linked_product_type":"simple",
        "position":4,
        "extension_attributes":{
            "qty":1
        }
    }
}

'

Delete a simple product from a grouped product

To delete a simple product from a grouped product, use: DELETE /V1/products/{sku}/links/{type}/{linkedProductSku}.

To discover what to use as {type}, use xdebug to capture the request and evaluate the $linkTypes: related, crosssell, uupsell, and associated.
Grouped Product link types - alt text

When linking the simple products to the grouped product, the payload contained a few sections similar to:

        {
            "sku":"my-new-grouped-product",
            "link_type":"associated",
            "linked_product_sku":"product-sku-two",
            "linked_product_type":"simple",
            "position":2,
            "extension_attributes":{
            "qty":1
            }
        }

In the payload, the link_type value associated provides the {type} value required in the DELETE request. The request URL will be similar to /V1/products/my-new-grouped-product/links/associated/product-sku-three.

See the cURL request to delete the simple product with the product-sku-three SKU from the grouped product with the my-new-grouped-product SKU:

curl --location --request DELETE '{{your.url.here}}rest/default/V1/products/my-new-grouped-product/links/associated/product-sku-three' \
--header 'Authorization: Bearer {{Your Bearer Token}}' \
--header 'Cookie: PHPSESSID=9e61396705e9c17423eca2bdf2deefb2'

Get a grouped product using cURL

curl --location '{{your.url.here}}rest/default/V1/products/some-grouped-product-sku' \
--header 'Authorization: Bearer {{Your Bearer Token}}' \
--header 'Cookie: private_content_version=3b797a6cc3c5c71f2193109fb9838b12'

Additional resources

  • Create and manage grouped products
  • Grouped Product
  • Adobe Developer REST tutorials
  • Adobe Commerce REST ReDoc
recommendation-more-help
3a5f7e19-f383-4af8-8983-d01154c1402f