Package Exports
- nodejs-cart-lna
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (nodejs-cart-lna) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Simple shopping cart for node.
var Cart = require('nodejs-cart-lna');
var cart = new Cart(req);
cart.add(productObject); // add productObject to session carts
cart.remove(_id) ;// remove productObject
cart.items ; // propety all item in carts session
cart.update(_id,quantity); // update quantity of item
cart.clear();// clear all items
cart.total_item(); // total quantity in carts sesion
cart.total_amount(); // total amount in carts session
cart.item_amount(_id) ;// sub amount of item in carts session
cart.promo(percent); // apply promotion percent to cart session
cart.item_promo(id,percent); // apply promotion percent of item in cart session
Installation
$ npm install nodejs-cart-lnaExample
var express = require("express");
var router = express.Router();// route
var Product = require('../models/Product'); // product model
var Cart = require('nodejs-cart-lna');
// route add product to carts ssession
router.get('/add-cart/:id',function(req,res){
var cart = new Cart(req);
Product.findOne({_id:req.params.id},function(err,data){
cart.add(data);
return res.redirect('/show-cart'); // chuyển hướng về trang bạn muốn
});
});
// route show product in carts ssession
router.get('/show-cart/',function(req,res){
var cart = new Cart(req);
res.render('show-cart',{
cart:cart
});
});
// route remove product from carts ssession
router.get('/cart-remove/:id',function(req,res){
var cart = new Cart(req);
cart.remove(req.params.id);
return res.redirect('/show-cart'); // chuyển hướng về trang bạn muốn
});
// route update product quantity in carts ssession
router.get('/cart-update/:id',function(req,res){
var cart = new Cart(req);
var quantity = req.query.quantity;
quantity = (isNaN(quantity) || quantity < 1) ? 1 : quantity;
cart.update(req.params.id,quantity);
return res.redirect('/show-cart'); // chuyển hướng về trang bạn muốn
});
module.exports = router;