Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Ajax cart for Bootic shops

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 dist
Octocat-spinner-32 src
Octocat-spinner-32 test
Octocat-spinner-32 util
Octocat-spinner-32 Gemfile
Octocat-spinner-32 Gemfile.lock
Octocat-spinner-32 JFile
Octocat-spinner-32 README.mkd
Octocat-spinner-32 Rakefile
README.mkd

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.

Something went wrong with that request. Please try again.