# j-ShoppingCart

> j-ShoppingCart: singleton; supports discount

Framework: jcomponent20
Product: jComponent 20 (jcomponent@20)
Language: en
Content-SHA256: 75efbac550362325a9ccdacd9e8dea579b4db66523d1a61f271f07fdfabbabc0
Snapshot: c0700e321579725c5cf4f5ace1ad7d2866d1b4f93c24a63c0b41b6b7998e976c
Sources: components@910ed1a86f6e72b4f031d3ad0dc7844f9fc5cb8e
Review: not-recorded

- singleton
- supports discount
- data are stored in localStorage

__Configuration__:

- `discount {Number}` a discount in percentage (optional, default: `0`)
- `expiration {String}` data expiration (default: `6 days`)

__Output__:

```js
{
	items: [
		{
			name: String,
			price: Number,
			total: Number,
			count: Number,
			date: Date
		}
	],
	price: Number,
	total: Number,
	count: Number
}
```

### Methods

- `instance.add(id, price, count, [name])` adds new product or increase count if the product exists
- `instance.upd(id, [count], [price], [name])` updates product's data
- `instance.buy(id, price, count, [name])` creates/updates product
- `instance.rem(id)` removes product
- `instance.has(id)` checks product
- `instance.read(id)` reads product
- `instance.clear()` clears all products
- `instance.clean()` removes all products with zero count
- `instance.sync(function(array_id_products, meta) {})` create data for synchronization with the server

### Global Events

- `ON('shoppingcart.add', function(item) {})`
- `ON('shoppingcart.upd', function(item) {})`
- `ON('shoppingcart.rem', function(id) {})`
- `ON('shoppingcart.sum', function(data) {})`
- `ON('shoppingcart.clear', function() {})`

Use it with `<ui-component name="shoppingcart">`. When the component is not loaded yet, jComponent downloads it on first use from the address in `DEF.fallback` (the Componentator CDN by default). Author: Peter Širka. Source: the Componentator components repository, MIT license.

```html example.html
<ui-component name="shoppingcart" path="common.shoppingcart"></ui-component>

<script>
	var common = {};
</script>
```
