@plasma-platform/cart

Scripts for carts

Usage no npm install needed!

<script type="module">
  import plasmaPlatformCart from 'https://cdn.skypack.dev/@plasma-platform/cart';
</script>

README

version nextVersion downloads license dependency


Full documentation
install:
npm i @plasma-platform/cart -S

Short documentation

Table of Contents

ActionsServiceCarts

addToCartProductsWithServices

Adds a product to the cart and services to the product. if there is no cartId and no cookies(cart_id) a new cart is automatically created, adds products and services, and subscribe to the centrifuge

Parameters

  • cartId string user cart id
  • templateId number product id (isRequired)
  • orderId string order id
  • services Array ids service list
  • support Array ids support list
  • locale String current locale
  • data Object data.license for products | data.channel for services (isRequired)
  • itemType String product type(services or products) (isRequired)
  • attributes Object List of predefined attributes to be stored with cart(affiliate, operator, description, channel)
  • currency String Currency code iso3
  • channel String current channel
  • customAdd boolean custom create cart with item

deleteItemFromCart

UnLink Item(services|product) From Cart

Parameters

deleteItemFromItem

UnLink item(services|product) from item

Parameters

Examples

deleteItemFromItem({
productLink: 'https://api.templatemonsterdev.com/services/v1/services/en/362',
cartId: 'asd3253464oidfgds',
typeTarget: 'products',
typeSource: 'services',
itemId: 55555,
});

getCart

get current user or anonymous cart. takes authorized user cart or anonymous cart from cookies(cart_id)

Parameters

  • locale String current locale
  • id String cart id(if don't id automatically taken cart id from cookies)

getInfoItemsInCart

get products info items from cart

Parameters

  • cartItems Array array items from cart (use selector getCartItemsSelector) (isRequired)
  • locale Selector current locale

linkItemToCart

link item(services|product) in user cart

Parameters

  • productId Number product id (isRequired)
  • cartId String user cart id (isRequired)
  • itemType String products type (isRequired)
  • data Object data.license for products | data.channel for services (isRequired)
  • orderId String order id

linkItemToItem

link item(services) in product

Parameters

postCart

create new cart

Parameters

  • attributes Object List of predefined attributes to be stored with cart(affiliate, operator, description, channel)
  • currency String Currency code iso3

reassignCart

reassign anonymous cart to user (cookies(access_token) isRequired)

Parameters

  • locale String current locale
  • cartId String anonymous cart id (isRequired)
  • userId String user profile id (isRequired)

showServicePopup

show services popup

Parameters

  • show Boolean show or hide popup (isRequired)
  • templateId Number product id (isRequired)
  • serviceId Number service id (isRequired)

subscriptionCentrifuge

subscription centrifuge

Parameters

  • cartId String user cart id (isRequired)
  • currentLocale String current locale
  • templateId Number template id. if need add products after subscription centrifuge
  • servicesProduct Array services ids. if need add services in product after subscription centrifuge
  • support Array support ids. if need add support to product after subscription centrifuge
  • data Object data.license for products | data.channel for services
  • addItemAfterSubscribe Boolean if need add products after subscription centrifuge
  • itemType String item type
  • channel String current channel
  • anonymousCartId String anonymous cart id if need merge carts

updateCart

Update cart, authorization is optional, if cart belongs to user then only that user can update the cart, but anonymous cart can be updated by anyone.

Parameters

  • cartId String cart id (isRequired)
  • attributes Object List of predefined attributes to be stored with cart(affiliate, operator, description, channel)
  • currency String Currency code iso3

ActionsServiceDiscounts

getDiscountApplicability

Check on valid promocode, link or unlink promocode

Parameters

  • promocode string current promocode. (isRequired)
  • cartId string id of current cart. (isRequired)
  • addPromocode boolean add or remove promocode (isRequired)

ActionsServiceLicenses

getLicensesByIds

Get licenses info by ids

Parameters

  • ids array licenses ids (isRequired)
  • locale string current locale

Returns array

ActionsServiceProducts

getProductsByIds

Get product in the user cart

Parameters

  • templateIds array id templates (isRequired)
  • locale string current locale

Returns array

ActionsServiceServices

getCartBannerServices

get onCart service with video

Parameters

  • products Array products in cart(full info products from service products) (The products must have fields: templateId, package_id, propertyValues) (isRequired)
  • productIds Array product ids by which you need to find services (isRequired)
  • locale string current locale

getCartServices

get recommended product services

Parameters

  • product Object full info product from service products(The product must have fields: templateId, package_id, propertyValues * ) (isRequired)
  • locale String current locale

getCartSuggestionServices

get onCart services by channel suggestions

Parameters

  • products Array products in cart(full info products from service products) (The products must have fields: templateId, package_id, propertyValues) (isRequired)
  • productIds Array product ids by which you need to find services (isRequired)
  • locale string current locale

getServiceByIds

get services info

Parameters

  • ids Array id services (isRequired)
  • locale String current locale

ActionsServiceSupport

getSupportByIds

get support info

Parameters

  • ids Array id support (isRequired)
  • locale String current locale

Main

Start

  1. npm i @plasma-platform/cart

  2. in app.jsx: 1. import { CookiesProvider, Cookies } from 'react-cookie'; 2. const cookies = new Cookies(document.cookie); 3. add to main render 4. import { setCartConfig } from '@plasma-platform/cart'; 5. call setCartConfig({...}) with parameters

  3. in your project's store: 1. import { Cookies } from 'react-cookie'; 2. compose(applyMiddleware(thunkMiddleware.withExtraArgument(cookies)))

  4. in your project's reducers: 1. import { cartReducer } from '@plasma-platform/cart'; 2. connect cartReducer (cart: cartReducer)

  5. import and use needed Actions or Selectors in your project(Actions example: getCart -> getCartAction, Selectors example: getMyCartId -> getMyCartIdSelector)

cartReducer

cart reducers

setCartConfig

set init config for cart actions

Parameters

Examples

setCartConfig({
sessionStorage: true,
cookiesRoot: '.templatemonsterdev.com',
centrifugeCartURL: '//centrifugo.templatemonsterdev.com/',
services: {
carts: '//api.templatemonsterdev.com/carts/v2/',
products: '//api.templatemonsterdev.com/products/v2/',
services: '//api.templatemonsterdev.com/services/v1/',
support: '//api.templatemonsterdev.com/support/v1/',
discounts: '//api.templatemonsterdev.com/discounts/v2/',
users: '//api.templatemonsterdev.com/users/v1/',
licenses: '//api.templatemonsterdev.com/licenses/v1/',
},
serviceChannels: {
cart: 'tm2-cart',
cartBanner: 'plasma-cart-banner',
cartSuggestions: 'plasma-oncart-suggestion',
},
dataSessionStorage: true || false,
});

SelectorsServiceCarts

getCartInfo

return general information from cart

Parameters

Returns Object

getMyCartId

return current cart id from store

Parameters

Returns String

getCarts

return all store carts

Parameters

Returns Object

getRecalculateCart

return sign that the cart is recalculate

Parameters

Returns Boolean

fetchingCart

return sign that the cart is fetching

Parameters

Returns Boolean

cartServicePopupInfo

return service info for popup

Parameters

Returns Object

getCartByIdInfo

return cart info by id

Parameters

Returns Object

getCartCount

return number of items in the cart

Parameters

Returns Number

getCartPrice

return price in cart

Parameters

Returns Number

isCartCalculated

return sign if cart calculated

Parameters

Returns Boolean

getCartFinalPrice

return final price in cart

Parameters

Returns Number

getLastOpenedCart

return last opened cart

Parameters

Returns Object

getCartItems

return items in cart

Parameters

Returns Array

getCartItemsIds

return id items in cart

Parameters

Returns Array

getCartDiscounts

return discounts in cart

Parameters

Returns Array

cartAddedOnCartServices

return added id services in cart

Parameters

Returns Array

getIsFirstAddedItemToCart

return sign that firs added item to cart

Parameters

Returns Boolean

getSubscriptionCart

return sign that cart is subscription centrifuge

Parameters

Returns Boolean

getUpdateCartIsFetching

return sign that the cart update is fetching

Parameters

Returns Boolean

SelectorsServiceDiscounts

getDiscountsInfo

return current applicability discount info

Parameters

Returns Object

SelectorsServiceItems

SelectorsServiceLicenses

getLicensesEntities

return all licenses in store

Parameters

Returns Object

getLicensesIds

return all licenses ids in store

Parameters

Returns Array

isFetchingLicenses

return sign that licenses is fetching

Parameters

Returns Boolean

getCurrentLicensesLocale

return current licenses locale

Parameters

Returns String

getLicensesInfoByIds

return full info lisenses by ids

Parameters

  • state Object current store
  • ids Array licenses ids (optional, default [])

Returns Array

SelectorsServiceProducts

getProductsEntities

return all products in store

Parameters

Returns Object

getFetchingLocaleProducts

return sign that current products locale

Parameters

Returns String

isProductsFetching

return sign that products is fetching

Parameters

Returns Boolean

getProductById

return current product info from store

Parameters

  • state Object current store
  • id

Returns Object

getLicensesIdsByTemplateId

return licenses ids by template id

Parameters

  • state Object current store
  • id

Returns Array

SelectorsServiceServices

getAllServicesEntities

return all services in store

Parameters

Returns Object

getProductIdsOnCartBannerService

return id on Cart Banner Services

Parameters

Returns Array

getFetchingLocaleOnCartBannerService

return sign that current on Cart Banner Service locale

Parameters

Returns String

getProductIdsOnCartSuggestionServices

return id on CartSuggestion Services

Parameters

Returns Array

getFetchingLocaleOnCartSuggestionServices

return sign that current on CartSuggestion Services locale

Parameters

Returns String

getFetchingLocaleServices

return sign that current services locale

Parameters

Returns String

getProductIsInitializedOnCartSuggestionServices

return sign that on Cart Suggestion Services is initialized

Parameters

Returns Boolean

getProductIsInitializedOnCartBannerService

return sign that on Cart Banner Service is initialized

Parameters

Returns Boolean

getCartPreviewServicesByTemplateId

return recommended services info by product id

Parameters

Returns Array

getFetchingLocaleServicesByProductId

return sing that current locale services by product id

Parameters

Returns String

getAddedCartServices

return template ids with added service ids

Parameters

Returns Object

getAddedCartServicesByTemplatesId

return added services by product id

Parameters

Returns Array

isFetchingServices

return sing that services is fetching

Parameters

Returns Boolean

isFetchingOnCartSuggestionServices

return sing that on Cart Suggestion Services is fetching

Parameters

Returns Boolean

getOnCartBannerServiceIds

return on Cart Banner Service ids

Parameters

Returns Array

getOnCartSuggestionServicesIds

return on Cart Suggestion Services ids

Parameters

Returns Array

getOnCartBannerService

return on Cart Banner Service info

Parameters

Returns Object

getOnCartSuggestionServices

return on Cart Suggestion Services info

Parameters

Returns Array

SelectorsServiceSupport

getSupportEntities

return all support in store

Parameters

Returns Object

getFetchingLocaleSupport

return sign that current support locale

Parameters

Returns String

isFetchingSupport

return sing that support is fetching

Parameters

Returns Boolean

getSupportById

return support by id from list

Parameters

  • state Object current store
  • id

Returns Boolean