Documentation


JSFiddle Demo

Install

  • Get the package:
    bower install ngcart --save
  • Include the ngCart/dist/ngCart.js file in your index.html
  • Include add ngCart as a dependency in your app in the angular.module
    Something like this:
        
    
    
        <script src="bower_components/angular/angular.js"></script>
        <script src="bower_components/ngcart/dist/ngCart.js"></script>
        <script>
            var myApp = angular.module('myApp', ['ngCart']);
        </script>
        ...
    
    
    ...
    
    

Directives

ngcart-addtocart

Renders an 'Add To Cart' Button

<ngcart-addtocart id="{{ item.id }}" name="{{ item.name }}" price="{{ item.price }}" quantity="1" quantity-max="30" data="item"></ngcart-addtocart>
Attribute Description Default
*id Unique identifier for this item. -
*name Text description of item -
*price Numerical value representing the value of the item -
quantity Numerical value representing the quantity of the item to add to cart. If quantityMax is set; this default the quantity dropdown 1
quantity-max If set show a quantity drop-down to this value, else nothing is shown. If item is already in cart, will default to current quantity false
data This can be an object that may store additional information about the item to be uses later e.g. image, options etc. -
*Required Attributes

ngcart-cart

Renders a view of the cart

<ngcart-cart></ngcart-cart>

ngcart-summary

Renders a summary of the content of the cart (Typically used in the header bar of a website)

<ngcart-summary></ngcart-summary>

ngcart-cart

Renders a view of the cart

<ngcart-cart></ngcart-cart>

ngcart-checkout

Renders an 'Checkout' Button

<ngcart-checkout service="http" settings="{ url:'/checkout' }"></ngcart-checkout>
Attribute Description Default
*service Values of either 'log', 'http' or 'paypal' -
settings Object with setting specific to service as described below -
*Required Attributes

log - settings

Sends content of cart to console. Usefull for debugging

No settings required

http - settings

Sends a POST http request with content of cart

Attribute Description Default
*url URL you wish to post the cart to -

paypal - settings

Renders a paypal checkout button

Attribute Description Default
*business Email address to send money to -
*item_number Number to refer to order -
*currency_code Currency for transaction -
no_note Let user add a note to checkout page -

Methods

ngCart

Method Params Return
addItem id (int/string)
name (string)
price (float)
quantity (int)
data (any)
Returns ngCart item just added if successful
getItemById itemId (int/string) Returns ngCart item if found, else false
setShipping shipping: (float) Set currency value of shipping amount (float) Currency value of shipping amount
getShipping - (float) Currency value of shipping amount
setTaxRate tax: (float) Percentage of tax to charge (float) Percentage value of tax rate
getTaxRate (float) Currency value of tax rate
getTax - (float) Currency value of tax amount to charge
getCart - (object) Internal cart object
getItems - (object) Array of ngCartItem's
getTotalItems - (int) Number of items in the cart (regardless of quantity)
getSubTotal - (float) Currency value of cart pre tax or shipping
totalCost - (float) Currency value of cart including tax and shipping
removeItem index: Remove an item in the cart based on its index -
empty() bool: True if all items are removed from cart

ngCartItem

Method Params Return
setId id (int/string) id (int/string)
getId - id (int/string)
setName name (string) name (string)
getName - name (string)
setPrice price (float): must be above 0 price (float)
getPrice - price (float)
setQuantity quantity (int): set to 1 if invalid quantity is set quantity (int)
getQuantity - quantity (int)
setData data: (object) data (object)
getData - data: (object) or false if not set
getTotal - float: quantity * price

Broadcasts

name Params Description
ngCart:itemAdded ngCartItem Item that was added
ngCart:itemRemoved Item was removed from cart
ngCart:change Cart has changed. i.e. item added, removed, a quantity has changed or cart was emptied