This article explains how to handle item customization and variants when implementing the Catalog service plugin.
catalogReference
objectWhen Wix calls the Get Catalog Items endpoint, it includes a catalogReference
object containing the reference details for each item to retrieve from your catalog. This object includes the following properties:
catalogItemId
: The ID of the item in the catalog it belongs to. You can use any system you like for generating and storing unique item IDs. You may wish to expose an API so your app can query and retrieve item IDs.appId
: ID of the app providing the catalog. You can get your app's ID from your app's dashboard.options
: Additional item details in key:value pairs. Use this optional field to specify a variant of the item or add custom details. See below for more information.options
fieldIn some cases, your catalog might need more than just the item ID and app ID in order to return all of the correct item details. On a site's item page, visitors can often choose variants of the item or add custom details. For example:
There are several ways you can use the options
object for handling item variants. Here are two different approaches to implementing it. Decide which approach to take based on your technical requirements, existing system architecture, and business needs.
options
You can pass specific information about the item in the options
object as key:value pairs. You can choose how to structure the information and what keys and values to support.
For example, you can specify item variant details in any of the following ways:
"options": {"Size": "M", "Color": "Red"}
"options": {"customText": "Natalie"}
"options": {"recipientName": "Omar", "message": "Happy anniversary!"}
If you take this approach, make sure that:
options
properties, processes them, and returns the correct item details.options
property of the item's catalogReference
only includes key:value pairs that your catalog supports.Use this approach if:
options
object's properties in your implementation of Get Catalog Items.options
You can create a separate API that processes item variants and returns a unique variant ID. Then your app can pass an options
object containing only the item variant ID. When Wix calls Get Catalog Items, your Catalog service plugin retrieves the correct details for the item variant on the basis of this ID and returns them.
For example, suppose you are creating an app for processing donations that can be added to a customer's transaction. You could implement this as follows:
organizationId
, campaignId
and amount
. It returns a unique donationId
.donationId
.donationId
.catalogReference
object's options
property. For example: "options": { "donationId": "bf3b953d-d0b7-4755-a54e-13c167fc4484"}
.catalogReference
for the item, including the unique donationId
. On the basis of this ID, the endpoint returns the full details for the specific donation, which can then be added to the cart, checkout, or order.If you take this approach, make sure that:
options
property of the item's catalogReference
contains a field with the item variant ID your API generated.options
object, and returns the correct item details.Use this approach if: