Sample Use Cases and Flows

This article shares a possible use case your app could support, as well as sample flows that could support this use case. This can be a helpful jumping-off point as you plan your app's implementation.

Add and arrange products in category

Help merchants to manage their products by using categories. For this we will be using the Categories API.

  1. Call Create Category and pass "@wix/stores" to the treeReference.appNamespace field.
  2. Save category.id from the response.
  3. Call Bulk Add Items To Category and pass the items you want to add to the category. After products added to category you can rearrange them for example to promote some products to be displayed in the beginning. Note that you can arrange only 100 products, more products can be added but you cannot control arrangement of them. Call Set Arranged Items endpoint. Pass exactly same params as in step 2 but now items must be in same order in which you want to see them.
  4. Now you can load all products that belongs to given category and keep their arrangement by calling Search Products endpoint of ProductService with next body
Copy

Replace <categoryId> with real category id from step 1. Pay attention to sort.selectItemsBy parameter where you must pass filter by categoryId, this allows you to sort products by arrangement that you set in CategoriesService on step 3.

Prepare store for Christmas Sale

Before big sale merchant might want to prepare store by creating a new category for products on sale, adding ribbons to products to catch visitors' attention and of course setting new actual prices and compare at prices. Let's see how to do it step by step.

  1. Add and arrange products in category. This will allow visitor to filter by this category on storefront category page (if merchant enabled this filter in editor). Also it allows merchant to control which products visitor will see first.
  2. Create new ribbon by calling Create Ribbon endpoint of external RibbonService. Save ribbon.id that you received in response.
  3. To add ribbon "Sale!" to all products in category call Bulk Update Products By Filter endpoint. In filter send filter by category id. In product send only ribbon. So your request will look like:
Copy
  1. Finally, we need to update the actual prices and compare-at prices. To simplify, consider a single product with one variant where the actualPrice is set at $100.
  2. First we want to set a new compareAtPrice, this price will indicate to your client what is the price of the product before the sale. call Bulk Update Product Variants By Filter endpoint with variant with desired compareAtPrice and actualPrice:
Copy

After this call example product will have compareAtPrice 100$ and actualPrice 90$.

a) If you want to adjust all actual prices by some specific amount or percentage which depends on original actualPrice value call Bulk Adjust Product Variants By Filter. For example if you want to decrease current actual prices by 10% pass next body:

Copy

After this call example product will have compareAtPrice 100$ and actualPrice 81$.

b) If you want to calculate new actualPrice from compareAtPrice by applying some discount to it call Bulk Adjust Product Variants By Filter with actualPriceFromCompareAtPrice. For example if you want to set actualPrice as 20% discount from compareAtPrice pass next body:

Copy

After this call example product will have compareAtPrice 100$ and actualPrice 80$.

c) If you want to set exact actualPrice same for all variants of all products call Bulk Update Product Variants By Filter endpoint with variant with desired actualPrice:

Copy

After this call example product will have compareAtPrice 100$ and actualPrice 75$.

Extend product object with app specific fields

The Product object includes predefined fields that cannot be removed or renamed. However, there may be instances where you need to add additional fields to accommodate specific flows or use cases for your application.

For example, consider a real estate app that needs to store information about the total area and the type of unit (such as whether it is an apartment or a house). This can be achieved using the extendedFields field of the Product object.

Before proceeding, you may want to review our documentation on data extensions or schema plugins here.

  1. Follow this guide to create an extension of type "Stores Catalog Product" in the Dev Center. Be sure to note the namespace of your app, as you will need it for the next steps. For this example, let's assume the namespace is @my-user-name/real-estate-app.
  2. In the JSON Editor, enter the following value:
Copy

This defines two fields: areaInSqm, which includes minimum value validation, and unitType, which includes maximum length validation. Both fields can be read and written by your app as well as by users, such as the site owner. 3. Save your extension. Please note that, according to this guide, you must have your app approved before you can proceed with testing. 4. Once your app is approved, you can click "Test Your App" and select the site where you want to install it. Be sure to grant the app permissions to read and write to the stores catalog. 5. You can now create a product with extended fields by calling the Create Product endpoint or update an existing product by calling the Update Product endpoint. In your request, include the extendedFields object with your namespace and the relevant field values.

Copy

Alternatively, you can update a product's extended fields without passing a revision by using the Update Extended Fields endpoint. 6. When you call the Get Product endpoint, the response will include the extendedFields object with your namespace.

Did this help?