# BigCommerce parameters

> Use the available parameter types to incorporate content from BigCommerce into your components and compositions.

Source: https://docs.uniform.app/docs/integrations/commerce/bigcommerce/bigcommerce-parameters

After you install the BigCommerce integration, the following
parameter types are available. You can use these to incorporate
content from BigCommerce into your components and compositions.

| Parameter type | Description |
| --- | --- |
| [BigCommerce Product](#big-commerce-product) | Select a single product from BigCommerce. |
| [BigCommerce Product List](#big-commerce-product-list) | Select multiple products from BigCommerce. |
| [BigCommerce Product Query](#big-commerce-product-query) | Specify search criteria that's used to select a single or multiple products from BigCommerce. |

## BigCommerce product

This parameter type allows a Uniform user to select a single
BigCommerce product.

### Add parameter to component

To allow a user to select a product from BigCommerce,
you must add a parameter to a component. The parameter is used
to store the identifier to the selected product when the user
selects a product.

1. In Uniform, navigate to your component.
2. Add a new parameter using the parameter type **BigCommerce Product**.
3. The following values can be specified:

   | Name | Description |
   | --- | --- |
   | Required | Indicates whether the value is required when the component is used. |

   ![BigCommerce Product parameter configuration.](https://docs.uniform.app/images/integrations/commerce/bigcommerce/use-parameters/bigcommerce-product/parameter-config.png)

### Edit parameter value

When you use a component with a BigCommerce Product parameter,
by default no product will be selected. You are prompted to
select a product.

1. Click **Select**.

   ![](https://docs.uniform.app/images/integrations/commerce/bigcommerce/use-parameters/bigcommerce-product/edit-value-default.png)
2. Click the product you want to select.

   ![](https://docs.uniform.app/images/integrations/commerce/bigcommerce/use-parameters/bigcommerce-product/edit-value-filters.png)

   > **About this step:**
   >
   > A couple of filters are available. The dropdown allows you to filter by content type. The text box allows you to filter by product name.
3. Click **Accept** to save your selection.

   ![](https://docs.uniform.app/images/integrations/commerce/bigcommerce/use-parameters/bigcommerce-product/edit-value-selected.png)
4. You will see details about the product you selected, including the title and some metadata.

   ![](https://docs.uniform.app/images/integrations/commerce/bigcommerce/use-parameters/bigcommerce-product/edit-value-saved.png)

   > **About this step:**
   >
   > After your selection is saved, you are presented with the following options:
   >
   > - If you want to edit the selected product in BigCommerce, click **Edit**.
   > - If you want to deselect the product, click **Unlink**.

### Configure an enhancer

When a product is selected, Uniform only stores the identifier
for the product. Your front-end application must retrieve the
details for the product. Uniform provides an enhancer to
simplify this process.

> **Tip:**
>
> Using the enhancer provided by Uniform saves you from having
> to write logic to interact directly with BigCommerce.

#### How Uniform stores the selected product

The following is an example of what Uniform
stores for the parameter.

```json
{
  "type": "bigcommerceProduct",
  "value": "######################"
}
```

The product ID is stored as the value.

#### Add the enhancer

Uniform provides an enhancer so you don't need to write the API
calls to BigCommerce to retrieve data for products.

1. Add the following npm packages to your front-end application:

   ```
   @uniformdev/canvas
   @uniformdev/canvas-bigcommerce
   ```
2. In a text editor, open the file where you retrieve the
   composition definition from Uniform.

   > **About this step:**
   >
   > You are looking for the code calls the async function
   > `getComposition`. The code below assumes the
   > object returned is set in a variable `composition`.
3. Add the following import statements:

   ```javascript
   import { EnhancerBuilder, enhance } from '@uniformdev/canvas';
   import { 
       createBigCommerceEnhancer,
       createBigCommerceClient,
       CANVAS_BIGCOMMERCE_PARAMETER_TYPES,
   } from '@uniformdev/canvas-bigcommerce';
   ```
4. Add the following code:

   ```javascript
   const bigCommerceEnhancer = createBigCommerceEnhancer({
       client: createBigCommerceClient({
       storeHash: "!!! YOUR BIGCOMMERCE STORE HASH !!!",
       token: "!!! YOUR BIGCOMMERCE API TOKEN !!!",
       }),
       createProductOptions: () => {
       return {
           // Modify or exclude this property if you want 
           // more fields returned from the BigCommerce API
           include_fields: ['id', 'name'],
       };
       },
       createProductQueryOptions: () => {
       return {
           // Modify or exclude this property if you want 
           // more fields returned from the BigCommerce API
           include_fields: ['id', 'name'],
       };
       },
   });
   ```

   > **About this step:**
   >
   > We recommend you moving the BigCommerce credentials to
   > environment variables rather than hard-coding them in the
   > front-end app.
5. Add the following code:

```javascript
await enhance({
  composition,
  enhancers: new EnhancerBuilder().parameterType(
    CANVAS_BIGCOMMERCE_PARAMETER_TYPES, 
    bigCommerceEnhancer,
  ),
  context: {},
});
```

> **About this step:**
>
> This registers the enhancer to be used for any occurrence
> of the BigCommerce Product parameter.

> **Next steps:**
>
> Now the parameter value in the composition is mutated to
> include the field values for the selected BigCommerce
> product (instead of just being identifiers).

## BigCommerce Product List

This parameter type allows a Uniform user to select multiple BigCommerce products.

### Add parameter to component

To allow a user to select multiple products from BigCommerce,
you must add a parameter to a component. The parameter is used
to store the identifiers to the selected products when the user
selects products.

1. In Uniform, navigate to your component.
2. Add a new parameter using the parameter type **BigCommerce Product List**.
3. The following values can be specified:

   | Name | Description |
   | --- | --- |
   | Required | Indicates whether the value is required when the component is used. |

   ![BigCommerce Product List parameter configuration.](https://docs.uniform.app/images/integrations/commerce/bigcommerce/use-parameters/bigcommerce-product-list/add-parameter-to-component.png)

### Edit parameter value

This parameter type works the same way as [BigCommerce Product](#bigcommerce-product),
adding the ability to select multiple products from the list
when the parameter value is edited.

![Example of the editing interface for a BigCommerce Product List parameter on a component.](https://docs.uniform.app/images/integrations/commerce/bigcommerce/use-parameters/bigcommerce-product-list/edit-parameter-value.png)

### Configure an enhancer

This parameter type uses the same enhancer as the [BigCommerce Product](#configure-an-enhancer)
parameter type.

> **Note:**
>
> The parameter settings are stored in Canvas in a slightly
> different format. Instead of a single product ID being
> stored, the value is stored as an array of product IDs.
>
> ```json
> {
>   "type": "bigcommerceProductList",
>   "value": [
>     "######################",
>     "######################"
>   ]
> }
> ```

## BigCommerce Product Query

This parameter type allows a Uniform user to configure a query
that will determine the BigCommerce products that are retrieved.

### Add parameter to component

In order to allow a user to configure a query to determine the
products from BigCommerce to retrieve, you must add a parameter
to a component. The parameter is used to store the query settings
used to perform the search.

1. In Uniform, navigate to your component.
2. Add a new parameter using the parameter type **BigCommerce Product Query**.
3. The following values can be specified:

   | Name | Description |
   | --- | --- |
   | Required | Indicates whether the value is required when the component is used. |

   ![BigCommerce Product Query parameter configuration.](https://docs.uniform.app/images/integrations/commerce/bigcommerce/use-parameters/bigcommerce-product-query/add-parameter-to-component.png)

### Edit parameter value

Configuring this parameter type involves specifying the way
a product search should work. You are able to control the
following search settings:

| Field | Description |
| --- | --- |
| Brand | Only products associated with the selected brand are included. |
| Count | The maximum number of products that are returned. |
| Keyword | Only products whose names match the specified keyword(s) are included. |
| Sort | The product property used to sort the products that are returned. |
| Sort Order | Whether the products should be sorted in ascending or descending order. |

![Example of the editing interface for a BigCommerce Product Query parameter on a component.](https://docs.uniform.app/images/integrations/commerce/bigcommerce/use-parameters/bigcommerce-product-query/edit-parameter-value.png)

### Configure an enhancer

This parameter type uses the same enhancer as the [BigCommerce Product](#configure-an-enhancer)
parameter type.

> **Note:**
>
> The parameter settings are stored in Canvas in a slightly
> different format. Instead of a single product ID being
> stored, the value stores the settings used to perform
> the search.
>
> ```json
> {
>   "type": "bigcommerceProductQuery",
>   "value": {
>     "count": 1,
>     "categories": [
>       "######################",
>       "######################"
>     ],
>     "brand": "######################",
>     "keyword": "######################",
>     "sort": "######################",
>     "sortOrder": "asc"
>   }
> }
> ```
