Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@ecomplus/shopping-cart

ecomplus823MIT2.6.0

Simple vanilla JS library to handle shopping cart object and events

ecomplus, ecommerce, storefront, cart

readme

Shopping Cart

Publish CodeFactor 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

import ecomCart from '@ecomplus/shopping-cart'

ecomCart.on('change', ({ data }) => {
  console.log('Cart was changed!')
  console.log('Current cart data:', data)
})

ecomCart.addItem({
  _id: '12300000000000000000000f',
  product_id: '123a5432109876543210cdef',
  sku: 's-MP_2B4',
  name: 'Mens Pique Polo Shirt',
  quantity: 4,
  price: 42.9,
  keep_item_price: false
})

ecomCart.increaseItemQnt('12300000000000000000000f', 3)

Installation

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

Webpack

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

Node.js

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

CDN

<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.

changelog

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

2.6.0 (2023-11-26)

Features

  • check global ECOM_CART_STORAGE_KEY to optionally change default key (771ad6e)

2.5.9 (2023-01-09)

Bug Fixes

  • deps: accept eventemitter3 v4 and v5 (64cfc63)
  • deps: update dependency eventemitter3 to v5 (#210) (c5557ee)

2.5.8 (2022-10-31)

Bug Fixes

  • force new item (even if repeated) when keep_item_quantity is set (330faa1)

2.5.7 (2022-08-04)

Bug Fixes

2.5.6 (2022-03-25)

Bug Fixes

  • add-item: reassign customizations obj to prevent wrong edits by reference (#158) (51fd0f2)

2.5.5 (2020-11-17)

Bug Fixes

  • parse-product: also check quantity NaN (531959c)
  • parse-product: quantity defaults to product 'min_quantity' or (then) 1 (9daf54e)

2.5.4 (2020-11-16)

Bug Fixes

  • remove-item: fix removing items from kit composition to prevent duplicated removal (513ebf9)

2.5.3 (2020-11-16)

Bug Fixes

  • add-item: prevent adding items with duplicated object id (77cd1a7)
  • remove-item: check variation and quantity to remove same kit items (e7ff2ee)

2.5.2 (2020-11-15)

Bug Fixes

  • add-item: duplicate items from when composing kit units (d34b06e)
  • remove-item: properly decreasing respective kit items quantity (d5b88d5)

2.5.1 (2020-11-14)

Bug Fixes

  • remove-item: check kit product composition to prevent removing all items (2cd461b)

2.5.0 (2020-11-12)

Features

  • remove-item: should also remove same kit items (0c1ac0d)

2.4.1 (2020-11-11)

Bug Fixes

  • add-item: 'canSave' defaults to true (as documented) (9a31751)

2.4.0 (2020-11-11)

Features

  • kit-product: handle add item with kit parent and fix final price (6234abb)

Bug Fixes

  • deps: update all non-major dependencies (2558f2c)

2.3.1 (2020-10-25)

Bug Fixes

  • add-item: when checking current items, skip those with customizations (ad2d8d1)
  • increase-item-qnt: do not change item final price, quantity only (6072131)
  • item-final-price: preset as item price (46817e0)

2.3.0 (2020-10-25)

Features

  • method: add new 'fixItem' method (bf66b4c)

Bug Fixes

  • final-price: consider percentage default type for additions (2ef93a4)
  • handle-item: internal fix item final price with customization additionals (0f59647)

2.2.0 (2020-10-02)

Features

  • parse-product: add new 'parseProduct' method (f99f7a6)

2.1.7 (2020-08-18)

Bug Fixes

  • add-product: fix handling max/min quantities (07e5f80)

2.1.6 (2020-08-12)

Bug Fixes

  • add-product: merge product with variation properties (ca586bd)

2.1.5 (2020-07-02)

Bug Fixes

  • add-product: prevent overwriting original product object (5647d75)

2.1.4 (2020-07-02)

Bug Fixes

  • add-product: parse product quantity to item max quantity (b414537)

2.1.3 (2020-06-30)

Bug Fixes

  • add-item: prevent changing original item object (param) (c78fa77)

2.1.2 (2020-06-29)

Bug Fixes

  • add-item: check if new item id not equal to variation id (483b580)

2.1.1 (2020-01-25)

Bug Fixes

  • reset: fix reseting self.data (by reference) (548de25)

2.1.0 (2020-01-25)

Features

  • reset: add new 'reset' method (09807ca)

2.0.2 (2020-01-07)

2.0.1 (2020-01-02)

2.0.0 (2019-12-26)

⚠ BREAKING CHANGES

  • deps: ecomplus/utils and core-js no more direct dependencies

  • deps: fix pkg dependencies (peer) (4675931)

1.0.0 (2019-11-29)

⚠ BREAKING CHANGES

  • constructor: changed default object exported

Bug Fixes

  • import: 'import * as EventEmitter' (no default export) (ed88be5)
  • methods: fix methods params to support middleware (default events) (93f8d34)
  • constructor: export an instance with .Constructor for new ones (2bf6386)

0.6.3 (2019-11-17)

0.6.2 (2019-09-12)

Bug Fixes

  • remove-item: fix event and self.save() on removeItem method (59d1e3f)

0.6.1 (2019-08-29)

Bug Fixes

  • add-item: fix handling 'addItem' (save) (9ee9ef9)
  • constructor: add each item one by one to fix it if needed (874b000)
  • constructor: fix constructor setup and some methods (e64998a)
  • constructor: setup methods with args correctly (8ae9f53)
  • emitter: emit constructor events on methods (.emit) (4f9f196)
  • methods: handling instance cart object with 'data' (ec856b5)

Features

  • add-item: handling addItem method (e8a09af)
  • add-product: implement 'addProduct' method (3ab6636)
  • clear: add 'clear' method (7752491)
  • emitter: add events emmiter to constructor (6f01886)
  • emitter: emit constructor events on methods (1cde35f)
  • increase-item-qnt: handle 'increaseItemQnt' method (764c007)
  • remove-item: handle 'removeItem' method (03551f1)
  • save: add 'save' method (26206b9)
  • storage: try to preset cart data from storage (eea39e1)

0.6.1-alpha.0 (2019-08-29)

Bug Fixes

  • handle export even if window object is available (3c3372f)
  • prevent fatal error with undefined module (36f4474)