This package has been deprecated

Author message:

No longer maintained.

typescript-cart
TypeScript icon, indicating that this package has built-in type declarations

1.0.12 • Public • Published

typescript-cart

Build Status

Typescript-cart is a small JavaScript/Typescript cart for e-commerce. It has functionality for currencies, VAT and weight.

Installation

With npm

npm install --save typescript-cart

Documentation

Documentation is available here.

Example

An example of the cart.

import {ICart, Cart, IProduct, Currencies, WeightUnits} from "smart-cart";
 
let cart: ICart = new Cart();
 
// Add single item
cart.addItem({
    sku: "001",
    basePrice: 10,
    quantity: 2,
    extra: {
        size: "XL"
    }
});
 
// Add multiple items
cart.addItem([{
    sku: "001",
    basePrice: 10,
    quantity: 2,
    extra: {
        size: "XL"
    }
}, {
    sku: "002",
    basePrice: 2,
    quantity: 5,
    additionPrice: 15,
    extra: {
        withCreamer: true
    }
}]);
 
// Get all products
let products: IProduct[] = cart.getContents();
 
// Add another of product nr 1
products[0].setQuantity(1, true);
 
// Remove product
products[0].remove();
 
// Set currency to display prices (standard is EUR)
cart.setCurrency(Currencies.GBP);
 
// Print price
console.log(cart.getTotalPrice());
 
// Set weight units
cart.setWeightUnitSystem(WeightUnits.GRAM);
 
// Print weight
console.log(cart.getWeight());

Contribute

Make sure to run the tests

npm test

Package Sidebar

Install

npm i typescript-cart

Weekly Downloads

0

Version

1.0.12

License

MIT

Unpacked Size

75.3 kB

Total Files

72

Last publish

Collaborators

  • flaremind