Vue Storefront is now Alokai! Learn More
Products

Products

Introduction

This section will cover the basics of products and how to fetch them. We will also cover how to fetch the product's variants and options.

API Reference

You can find all available CT module methods and their description in the API Reference.

Fetching products

To fetch products, you can use the getProduct method of the CT module.

Fetching the first page of all products.

import { sdk } from '~/sdk.config.ts';

const { products } = await sdk.ct.getProduct();

Offset and limit

Fetching the third page of all products sliced by 25 products.

import { sdk } from '~/sdk.config.ts';

const { products } = await sdk.ct.getProduct({
  offset: 50,
  limit: 25
});

Category identifier filter

Fetching the first page of products filtered by category identifier.

import { sdk } from '~/sdk.config.ts';

const { products } = await sdk.ct.getProduct({
  catId: '3d45e2d2-fe47-4e8b-968e-faa87991f233'
});

Fetching product by sku

To fetch a product by sku, you need to use the getProductBySku method of the CT module.

Fetching product by sku.

import { sdk } from '~/sdk.config.ts';

const { products } = await sdk.ct.getProductBySku({
  sku: 'id'
});

Filtering

To filter, sort or search for products, you need to use the getFacet method of the CT module.

Filtering by attribute. Please note that the filters key must be a name of any of the facets defined in the config file integrations.ct.configuration.faceting.availableFacets array of server middleware configuration.

const whiteBags = await sdk.ct.getFacet({
  phrase: 'bag',
  filters: {
    color: ['white']
  }
});

Sorting

Sorting by sorting option The value of sort is an id of a sorting option define inside config in integrations.ct.configuration.faceting.sortingOptions array of server middleware configuration.

const bagsSortedByPrice = await sdk.ct.getFacet({
  phrase: 'bag',
  sort: 'price-up'
});

Text search

import { sdk } from '~/sdk.config.ts';
const response = await sdk.ct.getFacet({
  phrase: 'bag'
});
const allProductsMatchPhrase = response.results.every((product) =>
  product.name.toLowerCase().includes('bag')
);

Managing Product Reviews

To get product reviews, you can use the getProductReviews method of the CT module.

Fetching the third page of product reviews sliced by 10 reviews.

import { sdk } from '~/sdk.config.ts';

const { reviews } = await sdk.ct.getProductReviews({
  productId: '891c95f8-7bf4-4945-9ab5-00906a5f76ba',
  limit: 10,
  offset: 20
});

To add a product review, you can use the addProductReview method of the CT module.

Adding a product review.

import { sdk } from '~/sdk.config.ts';

const { review } = await sdk.ct.addProductReview({
  productId: '891c95f8-7bf4-4945-9ab5-00906a5f76ba',
  draft: {
    authorName: 'John Doe',
    text: 'Best product ever',
    rating: 5
  }
});

To delete a product review, you can use the deleteProductReview method of the CT module.

Deleting a product review.

import { sdk } from '~/sdk.config.ts';

const { review } = await sdk.ct.deleteProductReview({
  id: 'c9e9a3c8-547f-4bc0-907d-4805423e803b',
  version: 1
});

Only authors can delete their reviews

You need to be an author of the review to delete it.