1.0.12 • Published 6 years ago

typescript-cart v1.0.12

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

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
1.0.12

6 years ago

1.0.11

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago