https://github.com/ecomplus/shopping-cart
Simple JS lib to handle shopping cart object and events
https://github.com/ecomplus/shopping-cart
checkout ecommerce-cart ecomplus javascript-library storefront
Last synced: 10 months ago
JSON representation
Simple JS lib to handle shopping cart object and events
- Host: GitHub
- URL: https://github.com/ecomplus/shopping-cart
- Owner: ecomplus
- License: mit
- Created: 2019-02-07T15:10:54.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2025-03-17T04:51:54.000Z (11 months ago)
- Last Synced: 2025-03-19T11:19:22.662Z (11 months ago)
- Topics: checkout, ecommerce-cart, ecomplus, javascript-library, storefront
- Language: JavaScript
- Homepage: http://developers.e-com.plus/shopping-cart/
- Size: 3.83 MB
- Stars: 12
- Watchers: 3
- Forks: 5
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Shopping Cart
[](https://github.com/ecomplus/shopping-cart/actions?workflow=Publish) [](https://www.codefactor.io/repository/github/ecomplus/shopping-cart) [](https://www.npmjs.org/@ecomplus/shopping-cart) [](https://opensource.org/licenses/MIT)
Simple vanilla JS library to handle shopping cart with common methods following [E-Com Plus cart object model](https://developers.e-com.plus/docs/api/#/store/carts/carts)
[CHANGELOG](https://github.com/ecomplus/shopping-cart/blob/master/CHANGELOG.md)
## 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.
- [Get started](https://developers.e-com.plus/shopping-cart/module-@ecomplus_shopping-cart.html)
- [Class reference](https://developers.e-com.plus/shopping-cart/EcomCart.html)
### Example
```js
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`](https://developers.e-com.plus/utils/) (peer dependency).
#### Webpack
```bash
npm i --save core-js @ecomplus/utils @ecomplus/shopping-cart
```
#### Node.js
```bash
npm i --save @ecomplus/utils @ecomplus/shopping-cart
```
#### CDN
```html
```
When importing from CDN, `EventEmitter3` and `ecomUtils` libraries **must be included separately** and available on window scope.