项目作者: ecomplus

项目描述 :
Simple JS lib to handle shopping cart object and events
高级语言: JavaScript
项目地址: git://github.com/ecomplus/shopping-cart.git
创建时间: 2019-02-07T15:10:54Z
项目社区:https://github.com/ecomplus/shopping-cart

开源协议:MIT License

下载


Shopping Cart

Publish CodeFactor @ecomplus/shopping-cart"">npm version license mit

Simple vanilla JS library to handle shopping cart with common methods following E-Com Plus cart object model

CHANGELOG

Usage

The @ecomplus/shopping-cart package can be used to persist and treat shopping cart data on E-Com Plus stores (and not only).

It’s available for both Node.js and browser environments.

Example

  1. import ecomCart from '@ecomplus/shopping-cart'
  2. ecomCart.on('change', ({ data }) => {
  3. console.log('Cart was changed!')
  4. console.log('Current cart data:', data)
  5. })
  6. ecomCart.addItem({
  7. _id: '12300000000000000000000f',
  8. product_id: '123a5432109876543210cdef',
  9. sku: 's-MP_2B4',
  10. name: 'Mens Pique Polo Shirt',
  11. quantity: 4,
  12. price: 42.9,
  13. keep_item_price: false
  14. })
  15. ecomCart.increaseItemQnt('12300000000000000000000f', 3)

Installation

It may require and doesn’t include core-js (optional) and @ecomplus/utils (peer dependency).

Webpack

  1. npm i --save core-js @ecomplus/utils @ecomplus/shopping-cart

Node.js

  1. npm i --save @ecomplus/utils @ecomplus/shopping-cart

CDN

  1. <script src="https://cdn.jsdelivr.net/npm/@ecomplus/shopping-cart/dist/ecom-cart.var.min.js"></script>

When importing from CDN, EventEmitter3 and ecomUtils libraries must be included separately and available on window scope.