Legacy Knowledge Base
Publicado Jun. 25, 2030

Add Bulk products to the Cart

Written By

Kartik Singh

How To articles are not official guidelines or officially supported documentation. They are community-contributed content and may not always reflect the latest updates to Liferay DXP. We welcome your feedback to improve How To articles!

While we make every effort to ensure this Knowledge Base is accurate, it may not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with any feedback or concerns.

Legacy Article

You are viewing an article from our legacy "FastTrack" publication program, made available for informational purposes. Articles in this program were published without a requirement for independent editing or verification and are provided"as is" without guarantee.

Before using any information from this article, independently verify its suitability for your situation and project.

Issue

  • Is there a way to add Bulk products to the cart using the Liferay API?

Environment

  • Liferay DXP 7.4 [all versions]
  • Quarterly Release 
  • Commerce 4.0

Resolution

  • Liferay provides an API, from which it will help to add bulk products to the cart.
    Liferay API: /headless-commerce-delivery-cart/v1.0/carts/{cartId}

  • Refer to the below example:
  1. Navigate to Control Panel > Sites > Create a 'Minium' site.
  2. Navigate to Control Panel> Accounts> and create an ‘Account', let's say 'Test Account’.
  3. Hit the ‘localhost:8080/o/api' Url, open the '/headless-commerce-delivery-cart/v1.0/carts/{cartId}’ API and use the below attributes to add single/bulk products to the cart.
    {
    "cartItems": [
    {
    "productId": 35265,
    "quantity": 10,
    "skuId": 35269
    },
    {
    "productId": 35286,
    "quantity": 5,
    "skuId": 35302
    },
    {
    "productId": 35326,
    "quantity": 35,
    "skuId": 35330
    },
    {
    "productId": 35345,
    "quantity": 9,
    "skuId": 35349
    },
    {
    "productId": 35370,
    "quantity": 9,
    "skuId": 35374
    }
    ]
    }
  4. In the 'skuId' provide the ‘CPInstanceId’, and click on the “Execute” button, and all products will be added to the “Cart“.

Note:

  1. CartID = OrderID
  2. productId: Navigated to Control Panel> Commerce> Product, and open any product, let's say ‘ABS Sensor' where we found ‘ProductId’ as ‘ID’
  3. quantity: We can set the quantity value as per our requirement.
  4. skuId: The 'skuId', is ‘CPInstanceId’, which can find in the ‘CPInstance’ table in the Database. (Ex: To find the 'skuId' of 'CPInstanceId' for this product ‘35265’ ID, execute this query in the Database “SELECT * FROM demo.CPInstance where CPDefinitionId=35265;“.)
  • Kindly refer to the attached snapshots for the same.

Additional Information

  • Add products to the cart with attributes such as (quantity, size, and color): Please take a look at the JSON format below.
{
"cartItems": [
{
"options": "[
{
"key": "package-quantity",
"skuOptionKey": "package-quantity",
"skuOptionName": "Package Quantity",
"skuOptionValueKey": "112",
"skuOptionValueNames": ["112"],
"value": "112"
},
{
"key": "color",
"skuOptionKey": "color",
"skuOptionName": "Color",
"skuOptionValueKey": "white",
"skuOptionValueNames":["White"],
"value": "white"
},
{
"key": "size",
"skuOptionKey": "size",
"skuOptionName": "Size",
"skuOptionValueKey": "l",
"skuOptionValueNames":["L"],
"value":"l"
}
]",
"quantity": 1,
"replacedSkuId": 0,
"skuId": 35617
}
]
}

 

Note: Only JSON format has changed, to add bulk product steps, kindly refer to the same steps mentioned in the 'Resolution' section.

Snapshots:

Did this article resolve your issue ?

Legacy Knowledge Base