The EcommerceService is used to get all the data related to the e-commerce operations such as get cart details, search products, add products to the wishlist. You can import the EcommerceService from the experro-storefront package.
import { EcommerceService } from 'experro-storefront';
Here is a list of functions that the EcommerceService provides.
  1. getCart
  2. createCart
  3. updateCustomerId
  4. addToCart
  5. updateCart
  6. deleteItemInCart
  7. search
  8. facetedSearch
  9. getFacetByCategoryName
  10. getProductReviewsByProductId
  11. addProductReview
  12. addCouponCode
  13. removeCouponCodeById
  14. createWishlist
  15. updateWishlist
  16. deleteWishlist
  17. getAllWishlists
  18. getWishlistById
  19. addItemToWishlist
  20. deleteItemFromWishlistById

getCart

The function returns cart details.
const cartObj = await EcommerceService.getCart();

createCart

The function is used to create a cart. It accepts an object with customerId and line_items as properties.
const cart = await EcommerceService.createCart({ customerId, line_items });
If the user is logged in, provide userId as a customerId and line_items is an array of the products object that need to be added in cart.

updateCustomerId

The function updates the customer id for the existing cart. It accepts object with customerId and cartId the properties.
const cart = await EcommerceService.updateCustomerId({ customerId, cartId });
If the user is logged in, provide userId as a customerId.

addToCart

The function adds a product to the cart. It accepts an object with line_items as the property.
const cart = await EcommerceService.addToCart({ line_items });
The line_items is an array of the product object.

updateCart

The function updates the item in the cart. It accepts an object with itemId and line_item as the properties.
const cart = await EcommerceService.updateCart({ itemId, line_item });
The itemId is the id of the product item or line_item you want to update in the cart.

deleteItemInCart

The function delete the items from the cart. It accepts an object with itemId as the property.
const cart = await EcommerceService.deleteItemInCart({ itemId });

The function provide a ways to search the items or products available for the purchase.It accepts object with searchObj as property.
const result = await EcommerceService.search({ searchObj);
The searchObj can have the following properties.
searchObj: {
  body: {
    search_terms: text,
  },
  skip: 0,
  limit: 10,
  fieldsToQuery: 'images_ej, price_efi',
  sortBy: 'relevance',
  facet: []
},
PropertyDescriptionType
search_termSearch textString
skipSkip the result (for pagination)Number
limitLimit the result (items per page)Number
sortBySort the result byString
facetsFilters applied to the searchArray

facetedSearch

This function returns facets based on search criteria. It accepts an object with searchObj property.
const result = await EcommerceService.facetedSearch({ searchObj });

getFacetByCategoryName

The function returns facets based on searched category. It accepts string. The value of the string can either be the name of a category to search or All for a random search.
const result = await EcommerceService.getFacetByCategoryName(categoryName);

getProductReviewsByProductId

The function returns reviews for the given product. It accepts an object with productId as the property.
const reviews = await EcommerceService.getProductReviewsByProductId({ productId });

addProductReview

The function add a review for the given product. It accepts an object with productId and body as the properties.
const review = await EcommerceService.addProductReview({ productId, body });
The productId is the provider_id_esi of the particular product. body is an object with following properties.
PropertyDescriptionType
titleTitle of the reviewString
date_reviewedDate of the submitting the reviewDate
textReview commentString
ratingRating between 1 to 5Number
nameName of the userString
emailEmail of the userString
body: {
  title: 'Title for the review',
  date_reviewed: '2023/12/03',
  text: 'Review comment',
  rating: 4,
  name: 'Kai Doe',
  email: 'kai@doe.com',
}

addCouponCode

This function apply the coupon code for the products in the cart. It accepts an object with body as the property.
const result = await EcommerceService.addCouponCode({ body });
body is an object with following property
PropertyDescriptionType
coupon_codeCoupon codeString
body: {
  coupon_code: 'COUPON_CODE',
},

removeCouponCodeById

The function removes the coupon code. It accepts an object with couponId as property.
const couponCode = await EcommerceService.removeCouponCodeById({ couponId });
The couponId is an id of the particular coupon that should be removed.

createWishlist

This function create a new wishlist. It accepts an object with body property.
const wishlist = await EcommerceService.createWishlist({ body });
body is an object with following property.
PropertyDescriptionType
customer_idLogged in customer idNumber
is_publicMake this wishlist public or notBoolean
nameName of the wishlistString
itemsProduct items to add in wishlist.Object
body: {
  customer_id: 12,
  is_public: false,
  name: "School Shopping",
  items: [
    {
      "product_id": 12,
      "variant_id": 152,
    },
  ],
}

updateWishlist

This function update existing wishlist’s items, name, and visibility. It accepts an object with wishlistId and body as the properties.
const wishlist = await EcommerceService.updateWishlist({ wishlistId, body });
wishlistId is an id of an existing wishlist. body is an object.

deleteWishlist

This function deletes the wishlist. It accepts an object with wishlistId property.
const wishlist = await EcommerceService.deleteWishlist({ wishlistId });

getAllWishlists

This function returns all the wishlist.
const wishlists = await EcommerceService.getAllWishlists();

getWishlistById

This function returns wishlist by given id. It accepts an object with wishlistId as property.
const wishlist = await EcommerceService.getWishlistById({ wishlistId });

addItemToWishlist

This function adds product item into an existing wishlist. The function accepts an object with wishlistId and body as properties.
const wishlist = await EcommerceService.addItemToWishlist({ wishlistId, body });
wishlistId is an id of the existing wishlist in which item needs to be added. The items is an array of the object with product_id and variant_id properties.
{
  items: [
    {
      "product_id": 12,
      "variant_id": 152,
    },
  ],
}

deleteItemFromWishlistById

This function deletes a particular item from the wishlist by item id. The function accepts wishlistId and itemId as properties.
const wishlist = await EcommerceService.deleteItemFromWishlistById({ wishlistId, itemId });
The wishlistId is an id of the existing wishlist and itemId is the product item id which is going to be deleted from wishlist.

subscribeToNewsLetter

This method is designed to handle newsletter subscriptions within the context of a BigCommerce store, for now.
This function serves as a valuable tool for incorporating newsletter subscription functionality into a BigCommerce store. You only need to provide an email-id as an input parameter to enable the integration.
 const formSubmit = await EcommerceService.subscribeToNewsLetter(data?.email);
Newsletter subscriptions for the BigCommerce store will be processed through this function. If the provided email ID is not already subscribed, the function will execute the subscription. Otherwise, it will return an appropriate error message.