@plasma-platform/tm-service-carts

4.3.0 • Public • Published

Documentation

Table of Contents

CartsService

Carts Micro Service API SDK

Parameters

  • url string service url
  • token (string | null) user access tocken if available (optional, default null)

addNewCart

Add new cart

Parameters

  • currency string (required) Currency code iso3
  • attributes object List of predefined attributes to be stored with cart
    • attributes.affiliate string Affiliate name
    • attributes.trackers object Analytics trackers
    • attributes.trackers string [ga] - Google Analytics tracker
    • attributes.trackers string [ad] - Google Adwords tracker
    • attributes.trackers string [sc] - Soft Cube tracker

Examples

(async () => {
  const cartsService = new CartsService('https://jsonplaceholder.typicode.com/', 'dsugsahfdkljhafljkdfhajkldshfad');
  const cart = await cartsService.addNewCart('USD', { affiliate: 'colorlib' });
})();

Returns object object with new cart properties

cloneCart

Clone cart

Parameters

  • id string (required) cart id for cone

Examples

(async () => {
  const cartsService = new CartsService('https://jsonplaceholder.typicode.com/', 'hfkjasdhfljkadhflkajdshflkadjhald');
  const cart = await cartsService.cloneCart(111);
})();

Returns object object with new cart properties

getCartById

Get cart by id

Parameters

  • id string (required) Cart id

Examples

(async () => {
  const cartsService = new CartsService('https://jsonplaceholder.typicode.com/');
  const cart = await cartsService.getCartById(111);
})();

Returns object object with cart properties

getCartCalculatedById

Get cart calculated by id

Parameters

  • id string (required) Cart id

Examples

(async () => {
  const cartsService = new CartsService('https://jsonplaceholder.typicode.com/');
  const cart = await cartsService.getCartCalculatedById(111);
})();

Returns object object with cart properties

getMyCarts

Get my carts

Parameters

  • typeSort string type of sorting products in cart

Examples

(async () => {
  const cartsService = new CartsService('https://jsonplaceholder.typicode.com/');
  const cart = await cartsService.getMyCarts();
})();

Returns array array with objects cart properties

linkItemToCart

Link item to cart

Parameters

  • productServiceLink string (required) link to product in service products
  • cartId string (required) cart id
  • itemType string (required) type of product (products | services | discounts | link-discounts)
  • data object (required) params for link product to cart
    • data.license number license id
    • data.channel string channel for service (required if itemType is services)
    • data.position number position for service
    • data.presentation_id string presentation id for service

Examples

(async () => {
  const cartsService = new CartsService('https://jsonplaceholder.typicode.com/');
  const cart = await cartsService.linkItemToCart('http://service-products.dev/api/v1/products/en/55555', 111, 'products', {
    license: 50,
  });
})();

Returns object object cart properties

linkItemToItem

Link item to item

Parameters

  • productServiceLink string (required) link to product in service products
  • cartId string (required) cart id
  • itemId number (required) item id
  • data object (required) params for link product to cart
    • data.channel string (required) channel for service
    • data.position number position for service
    • data.presentation_id string presentation id for service
  • typeLink string type of link to item

Examples

(async () => {
  const cartsService = new CartsService('https://jsonplaceholder.typicode.com/');
  const cart = await cartsService.linkItemToItem('http://service-services.dev/api/v1/services/en/1', 111, 222, {
    channel: 'tm-cart'
  }, 'bundles');
})();

Returns object object cart properties

linkServiceToBundle

Link service to bundle

Parameters

  • productServiceLinks string (required) link to service in service products
  • cartId string (required) cart id
  • itemId number (required) item id
  • data object (required) params for link product to cart
    • data.channel string (required) channel for service
  • bundleId string bundle's id

Examples

(async () => {
  const cartsService = new CartsService('https://jsonplaceholder.typicode.com/');
  const cart = await cartsService.linkItemToItem('http://service-services.dev/api/v1/services/en/1', 111, 222, {
    channel: 'tm-cart'
  }, 'qwerty123');
})();

Returns object object cart properties

unlinkServiceFromBundle

Unlink service from bundle

Parameters

  • productServiceLinks string (required) link to service in service products
  • cartId string (required) cart id
  • itemId number (required) item id
  • bundleId string bundle's id

Examples

(async () => {
  const cartsService = new CartsService('https://jsonplaceholder.typicode.com/');
  const cart = await cartsService.unlinkServiceFromBundle('http://service-services.dev/api/v1/services/en/1', 111, 222, 'qwerty123');
})();

Returns object object cart properties

mergeCarts

Merge carts

Parameters

  • users_cart_id string (required) users cart id
  • anonymous_cart_id string (required) anonymous cart id

Examples

(async () => {
  const cartsService = new CartsService('https://jsonplaceholder.typicode.com/', 'dsugsahfdkljhafljkdfhajkldshfad');
  const cart = await cartsService.mergeCarts(111, 333);
})();

Returns object object with new cart properties

unLinkItemFromCart

Unlink item from cart

Parameters

  • productServiceLink string (required) link to product in service products
  • cartId string (required) cart id
  • itemType string (required) type of product (products | services | discounts | link-discounts)

Examples

(async () => {
  const cartsService = new CartsService('https://jsonplaceholder.typicode.com/');
  const cart = await cartsService.unLinkItemFromCart('http://service-products.dev/api/v1/products/en/55555', 111, 'products');
})();

Returns object object cart properties

unLinkItemFromItem

Unlink item from item

Parameters

  • productServiceLink string (required) link to product in service products
  • cartId string (required) cart id
  • itemTypeTarget string (required) item type target
  • itemId number (required) item id
  • itemTypeSource string (required) item type source

Examples

(async () => {
  const cartsService = new CartsService('https://jsonplaceholder.typicode.com/');
  const cart = await cartsService.unLinkItemFromItem('http://service-services.dev/api/v1/services/en/1', 111, 'services', 222, 'services');
})();

Returns object object cart properties

updateCart

update cart

Parameters

  • id string (required) cart id for cone
  • currecy string currency for shopping cart (iso3)
  • attributes object list of predefined attributes to be stored with cart
    • attributes.affiliate string Affiliate name
    • attributes.trackers object Analytics trackers
    • attributes.trackers string [ga] - Google Analytics tracker
    • attributes.trackers string [ad] - Google Adwords tracker
    • attributes.trackers string [sc] - Soft Cube tracker

Returns object object with new cart properties

reassignCart

Reassign cart

Parameters

  • cardId string (required) cart Id
  • link string (required) link to user profile

Examples

(async () => {
  const cartsService = new CartsService('https://jsonplaceholder.typicode.com/', 'dsugsahfdkljhafljkdfhajkldshfad');
  const cart = await cartsService.reassignCart('123');
})();

Returns object object with new cart properties

getToken

Get token for centrifuge

Parameters

  • options object
    • options.id string (required) cart Id
    • options.time number (required) timestamp for centrifuge

Examples

<caption>Get token for centrifuge<caption>
import Config from 'Config';
import CartsService from '@plasma-platform/tm-service-carts';
import TMCentrifuge from '@plasma-platform/tm-centrifuge';
(async () => {
  const cartsService = new CartsService('//socket.templatemonster.com/', 'ZW7NJyKVEtjyGCjPBXOZyQrjNZ5aOjIcJD7SAFNm');
  const timestamp = Math.round(new Date().getTime() / 1000);
  const [ cart ] = await cartsService.getMyCarts('-created_at&per-page=1');
  const token = await cartsService.getToken({
     id: cart.id,
     timestamp,
   });
  const centrifuge = TMCentrifuge({
     url: Config.centrifugeCartUrl,
     timestamp,
  });

  centrifuge.subscribe('update', (message)=>{});
})();
  • Throws any ErrorBadRequest

Returns object object with new cart properties

defaultAutoTrim

Object with class service messages

Package Sidebar

Install

npm i @plasma-platform/tm-service-carts

Weekly Downloads

2

Version

4.3.0

License

CC-BY-4.0

Unpacked Size

1.72 MB

Total Files

35

Last publish

Collaborators

  • alienmonster
  • ch-tm
  • viram