ForgeComponents
en

Components

j-ShoppingCart

jComponent 20 · jcomponent@20 component Example loaded with jComponent 20
  • 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:

{
	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.

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

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