Skip to content

bootic/bootic_cart

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bootic.Cart

This JavaScript library allows you to add/remove products from your Bootic shop.

Usage:

Loading the cart

Callback version

Bootic.Cart.load( function (cart) {
	console.log( cart.formatted_total ) // ie. "$100.0"
	console.log( cart.units ) // ie. 10

	cart.forEach( function (cartItem) {
		console.log( cartItem.vendor ) // ie. 'Apple'
	})
})

Event handling

Bootic.Cart.bind('loaded', function () {
	Bootic.Cart.forEach(...)
})

Adding a product

Bootic.Cart.add(123, function (addedItem) {
	console.log( addedItem.vendor ) // ie. 'Apple'
})
Bootic.Cart.bind('added', function (addedItem) {
	console.log( addedItem.vendor ) // ie. 'Apple'
})

Bootic.Cart.add(123)

Removing a product

Bootic.Cart.remove(123, function (removedItem) {
	console.log( removedItem.vendor ) // ie. 'Apple'
})
Bootic.Cart.bind('removed', function (removedItem) {
	console.log( removedItem.vendor ) // ie. 'Apple'
})

Bootic.Cart.remove(123)

More in the source code.

HTML5 Data API

bootic_cart.js will automatically hook itself up to forms with the following attributes:

<form class="add_to_cart" action="{{ add_to_cart_url }}" method="post" data-bootic-cart-add="add" data-bootic-productId="{{ product_item.id }}">
  <input type="hidden" name="cart_item[product_id]" value="{{ product_item.id }}" />
  <input type="submit" value="Add to cart" />
</form><!--/form-->

The following events are triggered on the global Bootic namespace.

templatesLoaded: all templates have been cached from data-template script elements.

Contributing

Use jBundle on dev mode. Learn more.

Jasmine tests in /bootic/bootic_cart/blob/master/test/tests.js

$ jbundle s
$ open test/index.html

Build and minify

$ rake build

Upload to S3

You'll need the BOOTIC_S3_KEY and BOOTIC_S3_SECRET variables in your environment, then:

$ rake release

License

bootic_cart.js

Copyright (c) 2012 Ismael Celis for Bootic S.P.A. (http://bootic.net)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

Ajax cart for Bootic shops

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages