Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

local-cart

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

local-cart

* **v0.0.1, unstable,** Simple api to store data for shopping carts, wishlists in browser localstorage

  • 0.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
increased by100%
Maintainers
1
Weekly downloads
 
Created
Source

Local cart

  • v0.0.1, unstable, Simple api to store data for shopping carts, wishlists in browser localstorage

Features

  • Local storage with basil.js
  • Cart object is mixed with node native event emmiter

Install

npm install stampit

Instantiate

require('local-cart'); //add cart factory to window object
const myCart = window.cartFactory({
  name: 'myAwesomeShopCart'
})
options
  • name name is used to store data in local storage, to restore cart with previuosly saved data

Methods

addItem(opts)

params
  • id - item identificator in cart
  • count - number of items in cart, if not specified is 1
  • unit_price - price of 1 item in cart
  • data - this is place to store your product model data, api doesn't use it,
var myProductModel = {
    id: 1,
    price:1000,
    title: 'Interesting Book',
    author: 'Jogn Doe'
}

var newCartItemOptions = {
    id: myProductModel.id,
    unit_price: myProductModel.price,
    data: myProductModel
}

myCart.addItem(newCartItemOptions);

Adding product with id that already exists in cart only updates count of an item

myCart.addItem(newCartItemOptions);
console.log(myCart.items); // [Object]
console.log(myCart.getTotalCount); // 1

// add same item again
myCart.addItem(newCartItemOptions);
console.log(myCart.items); // [Object]
console.log(myCart.getTotalCount); // 2

// let's change count property
newCartItemOptions.count = 8;
myCart.addItem(newCartItemOptions);
console.log(myCart.items); // [Object]
console.log(myCart.getTotalCount); // 10

getItem(id)

Returns item with given id

updateItemCount(id, count)

Update count of existing item in cart

deleteItem(id)

Delete item from cart

getTotalPrice()

Total price of all items.

getTotalCount()

Total count of all items.

Events

Cart object is also an event emmiter. By now it emits only one event. See node event emmiter api

  • change - fires when anything in cart is changed, after addItem, deleteItem, updateItemCount methods
myCart.on('change', functon () {
    console.log('items changed');
});

FAQs

Package last updated on 20 Apr 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc