Skip to content

Latest commit

 

History

History
65 lines (54 loc) · 1.74 KB

README.md

File metadata and controls

65 lines (54 loc) · 1.74 KB

cart-lib

A reusable shopping cart library where developers can use to store cart contents for ecommerce websites.

Installation

npm install cart-lib

Dependencies

  • PouchDB (For storing cart contents in browser memory)
  • Lodash (To quickly find cart items)

Sample Usage

// include cart-lib to your app
import {default as Cart} from 'cart-lib';

// initialize cart class
const myCart = new Cart("{db_name <string>}");

// get cart contents
myCart.getCart().then(function(response)=>{
    let cartContents = response.data; // you should be able to get the cart item list, total amount and quantity of your cart
});

Methods

getCart() : gets the whole content of the shopping cart including total value and quantity. Returns a promise
addToCart(<product object>): adds product to cart with <product object> = {
    featured_image: <string>,
    id: <string>,
    price: <string>,
    quantity: <int>,
    title: <string>
}
updateCart(<product object>): update cart item details <product object> = {
    featured_image: <string>,
    id: <string>,
    price: <string>,
    quantity: <int>,
    title: <string>,
    _rev: <string> // generated by pouch db for object reference
    _id: <string> // generated by pouch db for object reference
}
removeProduct(<product object>): remove item from cart <product object> = {
    featured_image: <string>,
    id: <string>,
    price: <string>,
    quantity: <int>,
    title: <string>,
    _rev: <string> // generated by pouch db for object reference
    _id: <string> // generated by pouch db for object reference
}

[GitHub](https://github.com/rigozeta/cart-lib): https://github.com/rigozeta/cart-lib
[NPM](https://www.npmjs.com/package/cart-lib): https://www.npmjs.com/package/cart-lib