> For the complete documentation index, see [llms.txt](https://w3block.gitbook.io/w3block-eng/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://w3block.gitbook.io/w3block-eng/dev-docs/api/commerce-api-services/products.md).

# Products

Products are basically a kind of "wrapper" around a NFT collection. It can have a set of tokens also known as stocks to be sold grouped in the product. Some characteristics of products:

* Products can have prices by currency, which means that it can be sold in multiple payment gateways, depending on the currency that should be used in the order creation
* Products can have a distribution type which is used to select the tokens to be delivered if the token inside the product is not specifically defined in the order purchase creation. The distribution types can be:
  * **random**: It selects some available token randomly
  * **sequential**: It selects the next available token by tokenId
  * **fixed**: You can define for each one product token which user can purchase the token and this kind of match distribute based on that rules.
* &#x20;Products can have a pricing type which defines if the price will be applied for all tokens inside the product or if the price is defined by each token. Available price types:
  * **product**: Its defined by product (one for all tokens)
  * **token**: Each token must define a price
* Products can have custom images, name and description instead of just using the blockchain information.

<details>

<summary>Product Model (Example)</summary>

```json
{
    "id": "434d550e-3502-4afb-9a3f-asd13413sad",
    "createdAt": "2022-10-18T17:01:29.867Z",
    "updatedAt": "2022-10-31T22:11:02.422Z",
    "companyId": "asd13413sad-d3af-40d9-a19e-a263fdfe6e92",
    "name": "Teste",
    "description": "Teste descrição",
    "images": [
        {
            "thumb": "http://res.cloudinary.com/tropix-dev/image/upload/v1667254203/commerce/010e92ea-d3af-40d9-a19e-a263fdfe6e92/86db28d6-3bf8-4906-9d2a-fdf792dd74b0.png",
            "assetId": "86db28d6-3bf8-4906-9d2a-fdf792dd74b0",
            "original": "http://res.cloudinary.com/tropix-dev/image/upload/v1667254203/commerce/010e92ea-d3af-40d9-a19e-a263fdfe6e92/86db28d6-3bf8-4906-9d2a-fdf792dd74b0.png"
        }
    ],
    "prices": [
        {
            "amount": "1.50",
            "currencyId": "65fe1119-6ec0-4b78-8d30-cb989914bdcb",
            "currency": {
                "id": "65fe1119-6ec0-4b78-8d30-cb989914bdcb",
                "createdAt": "2022-08-02T19:49:36.166Z",
                "updatedAt": "2022-08-02T19:49:36.166Z",
                "name": "BRL",
                "crypto": false,
                "symbol": "R$",
                "code": "BRL"
            }
        }
    ],
    "distributionType": "random",
    "pricingType": "product",
    "contractAddress": "0x5478a7790e45bb08213b9d7384bf50f65fc0a667",
    "chainId": 80001,
    "startSaleAt": null,
    "endSaleAt": null,
    "status": "published",
    "draftData": {
        "range": "1-5",
        "keyCollectionId": "e3517532-4ebd-4b65-98e4-023888f1ccdd"
    },
    "slug": "teste-shark-qa",
    "stockAmount": 30,
    "tokensAmount": 30,
    "canPurchase": true
}
```

</details>

## Service Methods

### List the products of company/tenant

<details>

<summary>Using SDK</summary>

{% code lineNumbers="true" %}

```typescript
// init your sdk as defined in main page of Commerce service
import { W3blockCommerceSDK } from '@w3block/sdk-commerce';
const sdk: W3blockCommerceSDK;
...

const tenantId = '<your tenant id>';
const products = await sdk.api.companies.listProducts(tenantId, {page: 1, limit: 100});
console.log('products', products);
```

{% endcode %}

</details>

Rest API reference:

{% openapi src="<https://commerce.pixway.io/sdk-json>" path="/companies/{companyId}/products" method="get" %}
<https://commerce.pixway.io/sdk-json>
{% endopenapi %}

### Gets a product by id

<details>

<summary>Using SDK</summary>

{% code lineNumbers="true" %}

```typescript
// init your sdk as defined in main page of Commerce service
import { W3blockCommerceSDK } from '@w3block/sdk-commerce';
const sdk: W3blockCommerceSDK;
...

const tenantId = '<your tenant id>';
const productId = '<your product id>';
const product = await sdk.api.companies.getProduct(tenantId, productId);
console.log('product', product);
```

{% endcode %}

</details>

Rest API reference:

{% openapi src="<https://commerce.pixway.io/sdk-json>" path="/companies/{companyId}/products/{productId}" method="get" %}
<https://commerce.pixway.io/sdk-json>
{% endopenapi %}

### Gets a product by slug

<details>

<summary>Using SDK</summary>

{% code lineNumbers="true" %}

```typescript
// init your sdk as defined in main page of Commerce service
import { W3blockCommerceSDK } from '@w3block/sdk-commerce';
const sdk: W3blockCommerceSDK;
...

const tenantId = '<your tenant id>';
const productSlug = '<your product slug>';
const product = await sdk.api.companies.getProductBySlug(tenantId, productSlug);
console.log('product', product);
```

{% endcode %}

</details>

Rest API reference:

{% openapi src="<https://commerce.pixway.io/sdk-json>" path="/companies/{companyId}/products/get-by-slug/{slug}" method="get" %}
<https://commerce.pixway.io/sdk-json>
{% endopenapi %}

### Check if some product can be purchased

{% hint style="info" %}
If this method returns canPurchase=true without authentication, that means the product doesn't have any order rule.
{% endhint %}

<details>

<summary>Using SDK</summary>

{% code lineNumbers="true" %}

```typescript
// init your sdk as defined in main page of Commerce service
import { W3blockCommerceSDK } from '@w3block/sdk-commerce';
const sdk: W3blockCommerceSDK;
...

const tenantId = '<your tenant id>';
const productId = '<your product id>';
const { canPurchase } = await sdk.api.companies.canPurchaseProduct(tenantId, productId);
console.log('canPurchase', canPurchase);
```

{% endcode %}

</details>

Rest API reference:

{% openapi src="<https://commerce.pixway.io/sdk-json>" path="/companies/{companyId}/products/{productId}/can-purchase" method="get" %}
<https://commerce.pixway.io/sdk-json>
{% endopenapi %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://w3block.gitbook.io/w3block-eng/dev-docs/api/commerce-api-services/products.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
