Skip to content
Browse files

Merge pull request #251 from wojodesign/3.0.x.dev

3.0.5
  • Loading branch information...
2 parents b531e88 + 1e4f8b5 commit bc8eacb50664731d2e1ea0726ca524748908ca78 @brettwejrowski brettwejrowski committed Jun 12, 2012
Showing with 160 additions and 102 deletions.
  1. +5 −4 README.md
  2. +58 −46 simpleCart.js
  3. +46 −45 simpleCart.min.js
  4. +51 −7 test/test.core.js
View
9 README.md
@@ -14,10 +14,11 @@ Dual licensed under the MIT or GPL licenses.
If you would like to use an older version, you can use a different branch or see them in the
downloads area
-v3.0.4 changelog
- - added .on alias for .bind
- - allowing for multiple event bindings at once with space separated list
- - fixed check to bug with switched currency and shipping
+v3.0.5 changelog
+ - moved beforeCheckout event and form sending inside of .checkout() to keep dry
+ - added price, shipping, tax formatting for paypal checkout
+ - added .submit method to ELEMENT
+ - fixed mootools .get and .live bugs
## Quick Start
View
104 simpleCart.js
@@ -2,17 +2,16 @@
Copyright (c) 2012 Brett Wejrowski
wojodesign.com
- simplecartjs.com
+ simplecartjs.org
http://github.com/wojodesign/simplecart-js
- VERSION 3.0.4
+ VERSION 3.0.5
Dual licensed under the MIT or GPL licenses.
~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~*/
/*jslint browser: true, unparam: true, white: true, nomen: true, regexp: true, maxerr: 50, indent: 4 */
(function (window, document) {
- //"use strict";
/*global HTMLElement */
var typeof_string = typeof "",
@@ -883,7 +882,16 @@
if (settings.checkout.type.toLowerCase() === 'custom' && isFunction(settings.checkout.fn)) {
settings.checkout.fn.call(simpleCart,settings.checkout);
} else if (isFunction(simpleCart.checkout[settings.checkout.type])) {
- simpleCart.checkout[settings.checkout.type].call(simpleCart,settings.checkout);
+ var checkoutData = simpleCart.checkout[settings.checkout.type].call(simpleCart,settings.checkout);
+
+ // if the checkout method returns data, try to send the form
+ if( checkoutData.data && checkoutData.action && checkoutData.method ){
+ // if no one has any objections, send the checkout form
+ if( false !== simpleCart.trigger('beforeCheckout', [checkoutData.data]) ){
+ simpleCart.generateAndSendForm( checkoutData );
+ }
+ }
+
} else {
simpleCart.error("No Valid Checkout Method Specified");
}
@@ -921,8 +929,8 @@
, currency_code : simpleCart.currency().code
, business : opts.email
, rm : opts.method === "GET" ? "0" : "2"
- , tax_cart : simpleCart.tax()
- , handling_cart : simpleCart.shipping()
+ , tax_cart : (simpleCart.tax()*1).toFixed(2)
+ , handling_cart : (simpleCart.shipping()*1).toFixed(2)
, charset : "utf-8"
},
action = opts.sandbox ? "https://www.sandbox.paypal.com/cgi-bin/webscr" : "https://www.paypal.com/cgi-bin/webscr",
@@ -948,7 +956,7 @@
// basic item data
data["item_name_" + counter] = item.get("name");
data["quantity_" + counter] = item.quantity();
- data["amount_" + counter] = item.price();
+ data["amount_" + counter] = (item.price()*1).toFixed(2);
data["item_number_" + counter] = item.get("item_number") || counter;
@@ -975,13 +983,14 @@
data["option_index_"+ x] = Math.min(10, optionCount);
});
- simpleCart.trigger('beforeCheckout', [data]);
- simpleCart.generateAndSendForm({
+ // return the data for the checkout form
+ return {
action : action
, method : method
, data : data
- });
+ };
+
},
@@ -1035,13 +1044,13 @@
data['item_description_' + counter] = options_list.join(", ");
});
- simpleCart.trigger('beforeCheckout', [data]);
-
- simpleCart.generateAndSendForm({
+ // return the data for the checkout form
+ return {
action : action
, method : method
, data : data
- });
+ };
+
},
@@ -1104,14 +1113,12 @@
data['item_description_' + counter] = options_list.join(", ");
});
- simpleCart.trigger('beforeCheckout', [data]);
-
- simpleCart.generateAndSendForm({
+ // return the data for the checkout form
+ return {
action : action
, method : method
, data : data
- });
-
+ };
},
@@ -1172,14 +1179,12 @@
data = simpleCart.extend(data,opts.extra_data);
}
- simpleCart.trigger('beforeCheckout', [data]);
-
- simpleCart.generateAndSendForm({
+ // return the data for the checkout form
+ return {
action : action
, method : method
, data : data
- });
-
+ };
}
@@ -1395,7 +1400,7 @@
},
attr: function (attr, val) {
if (isUndefined(val)) {
- return this.el.get(attr);
+ return this.el[0] && this.el[0].get(attr);
}
this.el.set(attr, val);
@@ -1419,7 +1424,9 @@
},
each: function (callback) {
if (isFunction(callback)) {
- simpleCart.each(this.el, callback);
+ simpleCart.each(this.el, function( e, i, c) {
+ callback.call( i, i, e, c );
+ });
}
return this;
},
@@ -1439,11 +1446,8 @@
live: function ( event,callback) {
var selector = this.selector;
if (isFunction(callback)) {
- simpleCart.$(document).el.addEvent(event, function (e) {
- var target = simpleCart.$(e.target);
- if (target.match(selector)) {
- callback.call(target, e);
- }
+ simpleCart.$("body").el.addEvent(event + ":relay(" + selector + ")", function (e, el) {
+ callback.call(el, e);
});
}
},
@@ -1465,8 +1469,10 @@
tag: function () {
return this.el[0].tagName;
},
-
-
+ submit: function (){
+ this.el[0].submit();
+ return this;
+ },
create: function (selector) {
this.el = $engine(selector);
}
@@ -1479,7 +1485,7 @@
if (isUndefined(text)) {
return this.el[0].innerHTML;
}
- this.each(function (e) {
+ this.each(function (i,e) {
$(e).update(text);
});
return this;
@@ -1494,15 +1500,15 @@
if (isUndefined(val)) {
return this.el[0].readAttribute(attr);
}
- this.each(function (e) {
+ this.each(function (i,e) {
$(e).writeAttribute(attr, val);
});
return this;
},
append: function (item) {
- this.each(function (e) {
+ this.each(function (i,e) {
if (item.el) {
- item.each(function (e2) {
+ item.each(function (i2,e2) {
$(e).appendChild(e2);
});
} else if (isElement(item)) {
@@ -1512,38 +1518,40 @@
return this;
},
remove: function () {
- this.each(function (e) {
+ this.each(function (i, e) {
$(e).remove();
});
return this;
},
addClass: function (klass) {
- this.each(function (e) {
+ this.each(function (i, e) {
$(e).addClassName(klass);
});
return this;
},
removeClass: function (klass) {
- this.each(function (e) {
+ this.each(function (i, e) {
$(e).removeClassName(klass);
});
return this;
},
each: function (callback) {
if (isFunction(callback)) {
- simpleCart.each(this.el, callback);
+ simpleCart.each(this.el, function( e, i, c) {
+ callback.call( i, i, e, c );
+ });
}
return this;
},
click: function (callback) {
if (isFunction(callback)) {
- this.each(function (e) {
+ this.each(function (i, e) {
$(e).observe(_CLICK_, function (ev) {
callback.call(e,ev);
});
});
} else if (isUndefined(callback)) {
- this.each(function (e) {
+ this.each(function (i, e) {
$(e).fire(_CLICK_);
});
}
@@ -1574,7 +1582,9 @@
tag: function () {
return this.el.tagName;
},
-
+ submit: function() {
+ this.el[0].submit();
+ },
create: function (selector) {
if (isString(selector)) {
@@ -1588,7 +1598,7 @@
},
- "jQuery" : {
+ "jQuery": {
passthrough: function (action, val) {
if (isUndefined(val)) {
return this.el[action]();
@@ -1655,7 +1665,9 @@
descendants: function () {
return simpleCart.$(this.el.find("*"));
},
-
+ submit: function() {
+ return this.el.submit();
+ },
create: function (selector) {
this.el = $engine(selector);
View
91 simpleCart.min.js
@@ -1,51 +1,52 @@
-(function(m,f){var p="string",i=function(d,f){return typeof d===f},d=function(d){return i(d,"undefined")},h=function(d){return i(d,"function")},v=function(d){return"object"===typeof HTMLElement?d instanceof HTMLElement:"object"===typeof d&&1===d.nodeType&&"string"===typeof d.nodeName},z=function(n){function B(a){return b.extend({attr:"",label:"",view:"attr",text:"",className:"",hide:!1},a||{})}function C(){if(!b.isReady){try{f.documentElement.doScroll("left")}catch(a){setTimeout(C,1);return}b.init()}}
+(function(m,f){var p="string",i=function(e,f){return typeof e===f},e=function(e){return i(e,"undefined")},h=function(e){return i(e,"function")},v=function(e){return"object"===typeof HTMLElement?e instanceof HTMLElement:"object"===typeof e&&1===e.nodeType&&"string"===typeof e.nodeName},z=function(n){function B(a){return b.extend({attr:"",label:"",view:"attr",text:"",className:"",hide:!1},a||{})}function C(){if(!b.isReady){try{f.documentElement.doScroll("left")}catch(a){setTimeout(C,1);return}b.init()}}
var q={MooTools:"$$",Prototype:"$$",jQuery:"*"},l=0,o={},u=n||"simpleCart",w={},n={},n={},s=m.localStorage,j=m.console||{msgs:[],log:function(a){j.msgs.push(a)}},A={USD:{code:"USD",symbol:"$",name:"US Dollar"},AUD:{code:"AUD",symbol:"$",name:"Australian Dollar"},BRL:{code:"BRL",symbol:"R$",name:"Brazilian Real"},CAD:{code:"CAD",symbol:"$",name:"Canadian Dollar"},CZK:{code:"CZK",symbol:" Kč",name:"Czech Koruna",after:!0},DKK:{code:"DKK",symbol:"DKK ",name:"Danish Krone"},
EUR:{code:"EUR",symbol:"€",name:"Euro"},HKD:{code:"HKD",symbol:"$",name:"Hong Kong Dollar"},HUF:{code:"HUF",symbol:"Ft",name:"Hungarian Forint"},ILS:{code:"ILS",symbol:"₪",name:"Israeli New Sheqel"},JPY:{code:"JPY",symbol:"¥",name:"Japanese Yen"},MXN:{code:"MXN",symbol:"$",name:"Mexican Peso"},NOK:{code:"NOK",symbol:"NOK ",name:"Norwegian Krone"},NZD:{code:"NZD",symbol:"$",name:"New Zealand Dollar"},PLN:{code:"PLN",symbol:"PLN ",name:"Polish Zloty"},GBP:{code:"GBP",
symbol:"£",name:"Pound Sterling"},SGD:{code:"SGD",symbol:"$",name:"Singapore Dollar"},SEK:{code:"SEK",symbol:"SEK ",name:"Swedish Krona"},CHF:{code:"CHF",symbol:"CHF ",name:"Swiss Franc"},THB:{code:"THB",symbol:"฿",name:"Thai Baht"},BTC:{code:"BTC",symbol:" BTC",name:"Bitcoin",accuracy:4,after:!0}},k={checkout:{type:"PayPal",email:"you@yours.com"},currency:"USD",language:"english-us",cartStyle:"div",cartColumns:[{attr:"name",label:"Name"},{attr:"price",label:"Price",view:"currency"},
-{view:"decrement",label:!1},{attr:"quantity",label:"Qty"},{view:"increment",label:!1},{attr:"total",label:"SubTotal",view:"currency"},{view:"remove",text:"Remove",label:!1}],excludeFromCheckout:["thumb"],shippingFlatRate:0,shippingQuantityRate:0,shippingTotalRate:0,shippingCustom:null,taxRate:0,taxShipping:!1,data:{}},b=function(a){if(h(a))return b.ready(a);if(i(a,"object"))return b.extend(k,a)},x,y;b.extend=function(a,e){var c;d(e)&&(e=a,a=b);for(c in e)Object.prototype.hasOwnProperty.call(e,c)&&
-(a[c]=e[c]);return a};b.extend({copy:function(a){a=z(a);a.init();return a}});b.extend({isReady:!1,add:function(a,e){var c=new b.Item(a||{}),g=!0,r=!0===e?e:!1;if(!r&&(g=b.trigger("beforeAdd",[c]),!1===g))return!1;(g=b.has(c))?(g.increment(c.quantity()),c=g):o[c.id()]=c;b.update();r||b.trigger("afterAdd",[c,d(g)]);return c},each:function(a,e){var c,g=0,r,d,t;if(h(a))d=a,t=o;else if(h(e))d=e,t=a;else return;for(c in t)if(Object.prototype.hasOwnProperty.call(t,c)){r=d.call(b,t[c],g,c);if(!1===r)break;
-g+=1}},find:function(a){var e=[];if(i(o[a],"object"))return o[a];if(i(a,"object"))return b.each(function(c){var g=!0;b.each(a,function(a,b,e){i(a,p)?a.match(/<=.*/)?(a=parseFloat(a.replace("<=","")),c.get(e)&&parseFloat(c.get(e))<=a||(g=!1)):a.match(/</)?(a=parseFloat(a.replace("<","")),c.get(e)&&parseFloat(c.get(e))<a||(g=!1)):a.match(/>=/)?(a=parseFloat(a.replace(">=","")),c.get(e)&&parseFloat(c.get(e))>=a||(g=!1)):a.match(/>/)?(a=parseFloat(a.replace(">","")),c.get(e)&&parseFloat(c.get(e))>a||
-(g=!1)):c.get(e)&&c.get(e)===a||(g=!1):c.get(e)&&c.get(e)===a||(g=!1);return g});g&&e.push(c)}),e;d(a)&&b.each(function(a){e.push(a)});return e},items:function(){return this.find()},has:function(a){var e=!1;b.each(function(b){b.equals(a)&&(e=b)});return e},empty:function(){var a={};b.each(function(b){!1===b.remove(!0)&&(a[b.id()]=b)});o=a;b.update()},quantity:function(){var a=0;b.each(function(b){a+=b.quantity()});return a},total:function(){var a=0;b.each(function(b){a+=b.total()});return a},grandTotal:function(){return b.total()+
-b.tax()+b.shipping()},update:function(){b.save();b.trigger("update")},init:function(){b.load();b.update();b.ready()},$:function(a){return new b.ELEMENT(a)},$create:function(a){return b.$(f.createElement(a))},setupViewTool:function(){var a,e=m,c;for(c in q)if(Object.prototype.hasOwnProperty.call(q,c)&&m[c]&&(a=q[c].replace("*",c).split("."),(a=a.shift())&&(e=e[a]),"function"===typeof e)){x=e;b.extend(b.ELEMENT._,w[c]);break}},ids:function(){var a=[];b.each(function(b){a.push(b.id())});return a},save:function(){b.trigger("beforeSave");
-var a={};b.each(function(e){a[e.id()]=b.extend(e.fields(),e.options())});s.setItem(u+"_items",JSON.stringify(a));b.trigger("afterSave")},load:function(){o={};var a=s.getItem(u+"_items");if(a){try{b.each(JSON.parse(a),function(a){b.add(a,!0)})}catch(e){b.error("Error Loading data: "+e)}b.trigger("load")}},ready:function(a){h(a)?b.isReady?a.call(b):b.bind("ready",a):d(a)&&!b.isReady&&(b.trigger("ready"),b.isReady=!0)},error:function(a){var e="";i(a,p)?e=a:i(a,"object")&&i(a.message,p)&&(e=a.message);
-try{j.log("simpleCart(js) Error: "+e)}catch(c){}b.trigger("error",a)}});b.extend({tax:function(){var a=k.taxShipping?b.total()+b.shipping():b.total(),e=b.taxRate()*a;b.each(function(a){a.get("tax")?e+=a.get("tax"):a.get("taxRate")&&(e+=a.get("taxRate")*a.total())});return parseFloat(e)},taxRate:function(){return k.taxRate||0},shipping:function(a){if(h(a))b({shippingCustom:a});else{var e=k.shippingQuantityRate*b.quantity()+k.shippingTotalRate*b.total()+k.shippingFlatRate;h(k.shippingCustom)&&(e+=k.shippingCustom.call(b));
-b.each(function(a){e+=parseFloat(a.get("shipping")||0)});return parseFloat(e)}}});y={attr:function(a,b){return a.get(b.attr)||""},currency:function(a,e){return b.toCurrency(a.get(e.attr)||0)},link:function(a,b){return"<a href='"+a.get(b.attr)+"'>"+b.text+"</a>"},decrement:function(a,b){return"<a href='javascript:;' class='"+u+"_decrement'>"+(b.text||"-")+"</a>"},increment:function(a,b){return"<a href='javascript:;' class='"+u+"_increment'>"+(b.text||"+")+"</a>"},image:function(a,b){return"<img src='"+
-a.get(b.attr)+"'/>"},input:function(a,b){return"<input type='text' value='"+a.get(b.attr)+"' class='"+u+"_input'/>"},remove:function(a,b){return"<a href='javascript:;' class='"+u+"_remove'>"+(b.text||"X")+"</a>"}};b.extend({writeCart:function(a){var e=k.cartStyle.toLowerCase(),c="table"===e,g=c?"tr":"div",r=c?"th":"div",d=c?"td":"div",t=b.$create(e),e=b.$create(g).addClass("headerRow"),f,h;b.$(a).html(" ").append(t);t.append(e);c=0;for(h=k.cartColumns.length;c<h;c+=1)f=B(k.cartColumns[c]),a="item-"+
-(f.attr||f.view||f.label||f.text||"cell")+" "+f.className,f=f.label||"",e.append(b.$create(r).addClass(a).html(f));b.each(function(a,e){b.createCartRow(a,e,g,d,t)});return t},createCartRow:function(a,e,c,g,r){var e=b.$create(c).addClass("itemRow row-"+e+" "+(e%2?"even":"odd")).attr("id","cartItem_"+a.id()),d,f,j;r.append(e);r=0;for(c=k.cartColumns.length;r<c;r+=1)d=B(k.cartColumns[r]),f="item-"+(d.attr||(i(d.view,p)?d.view:d.label||d.text||"cell"))+" "+d.className,j=a,j=(h(d.view)?d.view:i(d.view,
-p)&&h(y[d.view])?y[d.view]:y.attr).call(b,j,d),f=b.$create(g).addClass(f).html(j),e.append(f);return e}});b.Item=function(a){function e(){i(c.price,p)&&(c.price=parseFloat(c.price.replace(b.currency().decimal,".").replace(/[^0-9\.]+/ig,"")));isNaN(c.price)&&(c.price=0);0>c.price&&(c.price=0);i(c.quantity,p)&&(c.quantity=parseInt(c.quantity.replace(b.currency().delimiter,""),10));isNaN(c.quantity)&&(c.quantity=1);0>=c.quantity&&g.remove()}var c={},g=this;i(a,"object")&&b.extend(c,a);l+=1;for(c.id=
-c.id||"SCI-"+l;!d(o[c.id]);)l+=1,c.id="SCI-"+l;g.get=function(a,b){var e=!b;return d(a)?a:h(c[a])?c[a].call(g):!d(c[a])?c[a]:h(g[a])&&e?g[a].call(g):!d(g[a])&&e?g[a]:c[a]};g.set=function(a,b){d(a)||(c[a.toLowerCase()]=b,("price"===a.toLowerCase()||"quantity"===a.toLowerCase())&&e());return g};g.equals=function(a){for(var b in c)if(Object.prototype.hasOwnProperty.call(c,b)&&"quantity"!==b&&"id"!==b&&a.get(b)!==c[b])return!1;return!0};g.options=function(){var a={};b.each(c,function(e,c,d){var f=!0;
-b.each(g.reservedFields(),function(a){a===d&&(f=!1);return f});f&&(a[d]=g.get(d))});return a};e()};b.Item._=b.Item.prototype={increment:function(a){a=parseInt(a||1,10);this.quantity(this.quantity()+a);return 1>this.quantity()?(this.remove(),null):this},decrement:function(a){return this.increment(-parseInt(a||1,10))},remove:function(a){if(!1===b.trigger("beforeRemove",[o[this.id()]]))return!1;delete o[this.id()];a||b.update();return null},reservedFields:function(){return"quantity id item_number price name shipping tax taxRate".split(" ")},
-fields:function(){var a={},e=this;b.each(e.reservedFields(),function(b){e.get(b)&&(a[b]=e.get(b))});return a},quantity:function(a){return d(a)?parseInt(this.get("quantity",!0)||1,10):this.set("quantity",a)},price:function(a){return d(a)?parseFloat(this.get("price",!0).toString().replace(b.currency().symbol,"").replace(b.currency().delimiter,"")||1):this.set("price",parseFloat(a.toString().replace(b.currency().symbol,"").replace(b.currency().delimiter,"")))},id:function(){return this.get("id",!1)},
-total:function(){return this.quantity()*this.price()}};b.extend({checkout:function(){"custom"===k.checkout.type.toLowerCase()&&h(k.checkout.fn)?k.checkout.fn.call(b,k.checkout):h(b.checkout[k.checkout.type])?b.checkout[k.checkout.type].call(b,k.checkout):b.error("No Valid Checkout Method Specified")},extendCheckout:function(a){return b.extend(b.checkout,a)},generateAndSendForm:function(a){var e=b.$create("form");e.attr("style","display:none;");e.attr("action",a.action);e.attr("method",a.method);b.each(a.data,
-function(a,g,d){e.append(b.$create("input").attr("type","hidden").attr("name",d).val(a))});b.$("body").append(e);e.el.submit();e.remove()}});b.extendCheckout({PayPal:function(a){if(!a.email)return b.error("No email provided for PayPal checkout");var e={cmd:"_cart",upload:"1",currency_code:b.currency().code,business:a.email,rm:"GET"===a.method?"0":"2",tax_cart:b.tax(),handling_cart:b.shipping(),charset:"utf-8"},c=a.sandbox?"https://www.sandbox.paypal.com/cgi-bin/webscr":"https://www.paypal.com/cgi-bin/webscr",
-g="GET"===a.method?"GET":"POST";a.success&&(e["return"]=a.success);a.cancel&&(e.cancel_return=a.cancel);b.each(function(a,c){var g=c+1,d=a.options(),f=0,h;e["item_name_"+g]=a.get("name");e["quantity_"+g]=a.quantity();e["amount_"+g]=a.price();e["item_number_"+g]=a.get("item_number")||g;b.each(d,function(a,c,d){if(c<10){h=true;b.each(k.excludeFromCheckout,function(a){a===d&&(h=false)});if(h){f=f+1;e["on"+c+"_"+g]=d;e["os"+c+"_"+g]=a}}});e["option_index_"+c]=Math.min(10,f)});b.trigger("beforeCheckout",
-[e]);b.generateAndSendForm({action:c,method:g,data:e})},GoogleCheckout:function(a){if(!a.merchantID)return b.error("No merchant id provided for GoogleCheckout");if("USD"!==b.currency().code&&"GBP"!==b.currency().code)return b.error("Google Checkout only accepts USD and GBP");var e={ship_method_name_1:"Shipping",ship_method_price_1:b.shipping(),ship_method_currency_1:b.currency().code,_charset_:""},c="https://checkout.google.com/api/checkout/v2/checkoutForm/Merchant/"+a.merchantID,a="GET"===a.method?
-"GET":"POST";b.each(function(a,c){var d=c+1,f=[],h;e["item_name_"+d]=a.get("name");e["item_quantity_"+d]=a.quantity();e["item_price_"+d]=a.price();e["item_currency_ "+d]=b.currency().code;e["item_tax_rate"+d]=a.get("taxRate")||b.taxRate();b.each(a.options(),function(a,e,c){h=!0;b.each(k.excludeFromCheckout,function(a){a===c&&(h=!1)});h&&f.push(c+": "+a)});e["item_description_"+d]=f.join(", ")});b.trigger("beforeCheckout",[e]);b.generateAndSendForm({action:c,method:a,data:e})},AmazonPayments:function(a){if(!a.merchant_signature)return b.error("No merchant signature provided for Amazon Payments");
-if(!a.merchant_id)return b.error("No merchant id provided for Amazon Payments");if(!a.aws_access_key_id)return b.error("No AWS access key id provided for Amazon Payments");var e={aws_access_key_id:a.aws_access_key_id,merchant_signature:a.merchant_signature,currency_code:b.currency().code,tax_rate:b.taxRate(),weight_unit:a.weight_unit||"lb"},c=(a.sandbox?"https://sandbox.google.com/checkout/":"https://checkout.google.com/")+"cws/v2/Merchant/"+a.merchant_id+"/checkoutForm",g="GET"===a.method?"GET":
-"POST";b.each(function(c,g){var d=g+1,f=[];e["item_title_"+d]=c.get("name");e["item_quantity_"+d]=c.quantity();e["item_price_"+d]=c.price();e["item_sku_ "+d]=c.get("sku")||c.id();e["item_merchant_id_"+d]=a.merchant_id;c.get("weight")&&(e["item_weight_"+d]=c.get("weight"));k.shippingQuantityRate&&(e["shipping_method_price_per_unit_rate_"+d]=k.shippingQuantityRate);b.each(c.options(),function(a,e,c){var d=true;b.each(k.excludeFromCheckout,function(a){a===c&&(d=false)});d&&(c!=="weight"&&c!=="tax")&&
-f.push(c+": "+a)});e["item_description_"+d]=f.join(", ")});b.trigger("beforeCheckout",[e]);b.generateAndSendForm({action:c,method:g,data:e})},SendForm:function(a){if(!a.url)return b.error("URL required for SendForm Checkout");var e={currency:b.currency().code,shipping:b.shipping(),tax:b.tax(),taxRate:b.taxRate(),itemCount:b.find({}).length},c=a.url,d="GET"===a.method?"GET":"POST";b.each(function(a,c){var d=c+1,g=[],f;e["item_name_"+d]=a.get("name");e["item_quantity_"+d]=a.quantity();e["item_price_"+
-d]=a.price();b.each(a.options(),function(a,e,c){f=!0;b.each(k.excludeFromCheckout,function(a){a===c&&(f=!1)});f&&g.push(c+": "+a)});e["item_options_"+d]=g.join(", ")});a.success&&(e["return"]=a.success);a.cancel&&(e.cancel_return=a.cancel);a.extra_data&&(e=b.extend(e,a.extra_data));b.trigger("beforeCheckout",[e]);b.generateAndSendForm({action:c,method:d,data:e})}});n={bind:function(a,e){if(!h(e))return this;this._events||(this._events={});var c=a.split(/ +/);b.each(c,function(a){this._events[a]===
-true?e.apply(this):d(this._events[a])?this._events[a]=[e]:this._events[a].push(e)});return this},trigger:function(a,b){var c=!0,g,f;this._events||(this._events={});if(!d(this._events[a])&&h(this._events[a][0])){g=0;for(f=this._events[a].length;g<f;g+=1)c=this._events[a][g].apply(this,b||[])}return!1===c?!1:!0}};n.on=n.bind;b.extend(n);b.extend(b.Item._,n);n={beforeAdd:null,afterAdd:null,load:null,beforeSave:null,afterSave:null,update:null,ready:null,checkoutSuccess:null,checkoutFail:null,beforeCheckout:null,
-beforeRemove:null};b(n);b.each(n,function(a,e,c){b.bind(c,function(){h(k[c])&&k[c].apply(this,arguments)})});b.extend({toCurrency:function(a,e){var c=parseFloat(a),d=e||{},d=b.extend(b.extend({symbol:"$",decimal:".",delimiter:",",accuracy:2,after:!1},b.currency()),d),f=c.toFixed(d.accuracy).split("."),c=f[1],f=f[0],f=b.chunk(f.reverse(),3).join(d.delimiter.reverse()).reverse();return(!d.after?d.symbol:"")+f+(c?d.decimal+c:"")+(d.after?d.symbol:"")},chunk:function(a,b){"undefined"===typeof b&&(b=2);
-return a.match(RegExp(".{1,"+b+"}","g"))||[]}});String.prototype.reverse=function(){return this.split("").reverse().join("")};b.extend({currency:function(a){if(i(a,p)&&!d(A[a]))k.currency=a;else if(i(a,"object"))A[a.code]=a,k.currency=a.code;else return A[k.currency]}});b.extend({bindOutlets:function(a){b.each(a,function(a,c,d){b.bind("update",function(){b.setOutlet("."+u+"_"+d,a)})})},setOutlet:function(a,e){var c=e.call(b,a);i(c,"object")&&c.el?b.$(a).html(" ").append(c):d(c)||b.$(a).html(c)},bindInputs:function(a){b.each(a,
-function(a){b.setInput("."+u+"_"+a.selector,a.event,a.callback)})},setInput:function(a,e,c){b.$(a).live(e,c)}});b.ELEMENT=function(a){this.create(a);this.selector=a||null};b.extend(w,{MooTools:{text:function(a){return this.attr("text",a)},html:function(a){return this.attr("html",a)},val:function(a){return this.attr("value",a)},attr:function(a,b){if(d(b))return this.el.get(a);this.el.set(a,b);return this},remove:function(){this.el.dispose();return null},addClass:function(a){this.el.addClass(a);return this},
-removeClass:function(a){this.el.removeClass(a);return this},append:function(a){this.el.adopt(a.el);return this},each:function(a){h(a)&&b.each(this.el,a);return this},click:function(a){h(a)?this.each(function(b){b.addEvent("click",function(c){a.call(b,c)})}):d(a)&&this.el.fireEvent("click");return this},live:function(a,e){var c=this.selector;h(e)&&b.$(f).el.addEvent(a,function(a){var d=b.$(a.target);d.match(c)&&e.call(d,a)})},match:function(a){return this.el.match(a)},parent:function(){return b.$(this.el.getParent())},
-find:function(a){return b.$(this.el.getElements(a))},closest:function(a){return b.$(this.el.getParent(a))},descendants:function(){return this.find("*")},tag:function(){return this.el[0].tagName},create:function(a){this.el=x(a)}},Prototype:{text:function(a){if(d(a))return this.el[0].innerHTML;this.each(function(b){$(b).update(a)});return this},html:function(a){return this.text(a)},val:function(a){return this.attr("value",a)},attr:function(a,b){if(d(b))return this.el[0].readAttribute(a);this.each(function(c){$(c).writeAttribute(a,
-b)});return this},append:function(a){this.each(function(b){a.el?a.each(function(a){$(b).appendChild(a)}):v(a)&&$(b).appendChild(a)});return this},remove:function(){this.each(function(a){$(a).remove()});return this},addClass:function(a){this.each(function(b){$(b).addClassName(a)});return this},removeClass:function(a){this.each(function(b){$(b).removeClassName(a)});return this},each:function(a){h(a)&&b.each(this.el,a);return this},click:function(a){h(a)?this.each(function(b){$(b).observe("click",function(c){a.call(b,
-c)})}):d(a)&&this.each(function(a){$(a).fire("click")});return this},live:function(a,b){if(h(b)){var c=this.selector;f.observe(a,function(a,d){d===x(a).findElement(c)&&b.call(d,a)})}},parent:function(){return b.$(this.el.up())},find:function(a){return b.$(this.el.getElementsBySelector(a))},closest:function(a){return b.$(this.el.up(a))},descendants:function(){return b.$(this.el.descendants())},tag:function(){return this.el.tagName},create:function(a){i(a,p)?this.el=x(a):v(a)&&(this.el=[a])}},jQuery:{passthrough:function(a,
-b){if(d(b))return this.el[a]();this.el[a](b);return this},text:function(a){return this.passthrough("text",a)},html:function(a){return this.passthrough("html",a)},val:function(a){return this.passthrough("val",a)},append:function(a){this.el.append(a.el||a);return this},attr:function(a,b){if(d(b))return this.el.attr(a);this.el.attr(a,b);return this},remove:function(){this.el.remove();return this},addClass:function(a){this.el.addClass(a);return this},removeClass:function(a){this.el.removeClass(a);return this},
-each:function(a){return this.passthrough("each",a)},click:function(a){return this.passthrough("click",a)},live:function(a,b){x(f).delegate(this.selector,a,b);return this},parent:function(){return b.$(this.el.parent())},find:function(a){return b.$(this.el.find(a))},closest:function(a){return b.$(this.el.closest(a))},tag:function(){return this.el[0].tagName},descendants:function(){return b.$(this.el.find("*"))},create:function(a){this.el=x(a)}}});b.ELEMENT._=b.ELEMENT.prototype;b.ready(b.setupViewTool);
-b.ready(function(){b.bindOutlets({total:function(){return b.toCurrency(b.total())},quantity:function(){return b.quantity()},items:function(a){b.writeCart(a)},tax:function(){return b.toCurrency(b.tax())},taxRate:function(){return b.taxRate().toFixed()},shipping:function(){return b.toCurrency(b.shipping())},grandTotal:function(){return b.toCurrency(b.grandTotal())}});b.bindInputs([{selector:"checkout",event:"click",callback:function(){b.checkout()}},{selector:"empty",event:"click",callback:function(){b.empty()}},
-{selector:"increment",event:"click",callback:function(){b.find(b.$(this).closest(".itemRow").attr("id").split("_")[1]).increment();b.update()}},{selector:"decrement",event:"click",callback:function(){b.find(b.$(this).closest(".itemRow").attr("id").split("_")[1]).decrement();b.update()}},{selector:"remove",event:"click",callback:function(){b.find(b.$(this).closest(".itemRow").attr("id").split("_")[1]).remove()}},{selector:"input",event:"change",callback:function(){var a=b.$(this),e=a.parent(),c=e.attr("class").split(" ");
-b.each(c,function(c){c.match(/item-.+/i)&&(c=c.split("-")[1],b.find(e.closest(".itemRow").attr("id").split("_")[1]).set(c,a.val()),b.update())})}},{selector:"shelfItem .item_add",event:"click",callback:function(){var a={};b.$(this).closest("."+u+"_shelfItem").descendants().each(function(e,c){var d=b.$(c);d.attr("class")&&(d.attr("class").match(/item_.+/)&&!d.attr("class").match(/item_add/))&&b.each(d.attr("class").split(" "),function(b){var c,e;if(b.match(/item_.+/)){b=b.split("_")[1];c="";switch(d.tag().toLowerCase()){case "input":case "textarea":case "select":e=
-d.attr("type");if(!e||("checkbox"===e.toLowerCase()||"radio"===e.toLowerCase())&&d.attr("checked")||"text"===e.toLowerCase())c=d.val();break;case "img":c=d.attr("src");break;default:c=d.text()}null!==c&&""!==c&&(a[b.toLowerCase()]=a[b.toLowerCase()]?a[b.toLowerCase()]+", "+c:c)}})});b.add(a)}}])});f.addEventListener?m.DOMContentLoaded=function(){f.removeEventListener("DOMContentLoaded",DOMContentLoaded,!1);b.init()}:f.attachEvent&&(m.DOMContentLoaded=function(){"complete"===f.readyState&&(f.detachEvent("onreadystatechange",
-DOMContentLoaded),b.init())});(function(){if(f.readyState==="complete")return setTimeout(b.init,1);if(f.addEventListener){f.addEventListener("DOMContentLoaded",DOMContentLoaded,false);m.addEventListener("load",b.init,false)}else if(f.attachEvent){f.attachEvent("onreadystatechange",DOMContentLoaded);m.attachEvent("onload",b.init);var a=false;try{a=m.frameElement===null}catch(e){}f.documentElement.doScroll&&a&&C()}})();return b};m.simpleCart=z()})(window,document);var JSON;JSON||(JSON={});
-(function(){function m(d){return 10>d?"0"+d:d}function f(f){d.lastIndex=0;return d.test(f)?'"'+f.replace(d,function(d){var f=z[d];return"string"===typeof f?f:"\\u"+("0000"+d.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+f+'"'}function p(d,i){var q,l,o,m,w=h,s,j=i[d];j&&"object"===typeof j&&"function"===typeof j.toJSON&&(j=j.toJSON(d));"function"===typeof n&&(j=n.call(i,d,j));switch(typeof j){case "string":return f(j);case "number":return isFinite(j)?""+j:"null";case "boolean":case "null":return""+
+{view:"decrement",label:!1},{attr:"quantity",label:"Qty"},{view:"increment",label:!1},{attr:"total",label:"SubTotal",view:"currency"},{view:"remove",text:"Remove",label:!1}],excludeFromCheckout:["thumb"],shippingFlatRate:0,shippingQuantityRate:0,shippingTotalRate:0,shippingCustom:null,taxRate:0,taxShipping:!1,data:{}},b=function(a){if(h(a))return b.ready(a);if(i(a,"object"))return b.extend(k,a)},x,y;b.extend=function(a,d){var c;e(d)&&(d=a,a=b);for(c in d)Object.prototype.hasOwnProperty.call(d,c)&&
+(a[c]=d[c]);return a};b.extend({copy:function(a){a=z(a);a.init();return a}});b.extend({isReady:!1,add:function(a,d){var c=new b.Item(a||{}),g=!0,r=!0===d?d:!1;if(!r&&(g=b.trigger("beforeAdd",[c]),!1===g))return!1;(g=b.has(c))?(g.increment(c.quantity()),c=g):o[c.id()]=c;b.update();r||b.trigger("afterAdd",[c,e(g)]);return c},each:function(a,d){var c,g=0,r,e,t;if(h(a))e=a,t=o;else if(h(d))e=d,t=a;else return;for(c in t)if(Object.prototype.hasOwnProperty.call(t,c)){r=e.call(b,t[c],g,c);if(!1===r)break;
+g+=1}},find:function(a){var d=[];if(i(o[a],"object"))return o[a];if(i(a,"object"))return b.each(function(c){var g=!0;b.each(a,function(a,b,d){i(a,p)?a.match(/<=.*/)?(a=parseFloat(a.replace("<=","")),c.get(d)&&parseFloat(c.get(d))<=a||(g=!1)):a.match(/</)?(a=parseFloat(a.replace("<","")),c.get(d)&&parseFloat(c.get(d))<a||(g=!1)):a.match(/>=/)?(a=parseFloat(a.replace(">=","")),c.get(d)&&parseFloat(c.get(d))>=a||(g=!1)):a.match(/>/)?(a=parseFloat(a.replace(">","")),c.get(d)&&parseFloat(c.get(d))>a||
+(g=!1)):c.get(d)&&c.get(d)===a||(g=!1):c.get(d)&&c.get(d)===a||(g=!1);return g});g&&d.push(c)}),d;e(a)&&b.each(function(a){d.push(a)});return d},items:function(){return this.find()},has:function(a){var d=!1;b.each(function(b){b.equals(a)&&(d=b)});return d},empty:function(){var a={};b.each(function(b){!1===b.remove(!0)&&(a[b.id()]=b)});o=a;b.update()},quantity:function(){var a=0;b.each(function(b){a+=b.quantity()});return a},total:function(){var a=0;b.each(function(b){a+=b.total()});return a},grandTotal:function(){return b.total()+
+b.tax()+b.shipping()},update:function(){b.save();b.trigger("update")},init:function(){b.load();b.update();b.ready()},$:function(a){return new b.ELEMENT(a)},$create:function(a){return b.$(f.createElement(a))},setupViewTool:function(){var a,d=m,c;for(c in q)if(Object.prototype.hasOwnProperty.call(q,c)&&m[c]&&(a=q[c].replace("*",c).split("."),(a=a.shift())&&(d=d[a]),"function"===typeof d)){x=d;b.extend(b.ELEMENT._,w[c]);break}},ids:function(){var a=[];b.each(function(b){a.push(b.id())});return a},save:function(){b.trigger("beforeSave");
+var a={};b.each(function(d){a[d.id()]=b.extend(d.fields(),d.options())});s.setItem(u+"_items",JSON.stringify(a));b.trigger("afterSave")},load:function(){o={};var a=s.getItem(u+"_items");if(a){try{b.each(JSON.parse(a),function(a){b.add(a,!0)})}catch(d){b.error("Error Loading data: "+d)}b.trigger("load")}},ready:function(a){h(a)?b.isReady?a.call(b):b.bind("ready",a):e(a)&&!b.isReady&&(b.trigger("ready"),b.isReady=!0)},error:function(a){var d="";i(a,p)?d=a:i(a,"object")&&i(a.message,p)&&(d=a.message);
+try{j.log("simpleCart(js) Error: "+d)}catch(c){}b.trigger("error",a)}});b.extend({tax:function(){var a=k.taxShipping?b.total()+b.shipping():b.total(),d=b.taxRate()*a;b.each(function(a){a.get("tax")?d+=a.get("tax"):a.get("taxRate")&&(d+=a.get("taxRate")*a.total())});return parseFloat(d)},taxRate:function(){return k.taxRate||0},shipping:function(a){if(h(a))b({shippingCustom:a});else{var d=k.shippingQuantityRate*b.quantity()+k.shippingTotalRate*b.total()+k.shippingFlatRate;h(k.shippingCustom)&&(d+=k.shippingCustom.call(b));
+b.each(function(a){d+=parseFloat(a.get("shipping")||0)});return parseFloat(d)}}});y={attr:function(a,b){return a.get(b.attr)||""},currency:function(a,d){return b.toCurrency(a.get(d.attr)||0)},link:function(a,b){return"<a href='"+a.get(b.attr)+"'>"+b.text+"</a>"},decrement:function(a,b){return"<a href='javascript:;' class='"+u+"_decrement'>"+(b.text||"-")+"</a>"},increment:function(a,b){return"<a href='javascript:;' class='"+u+"_increment'>"+(b.text||"+")+"</a>"},image:function(a,b){return"<img src='"+
+a.get(b.attr)+"'/>"},input:function(a,b){return"<input type='text' value='"+a.get(b.attr)+"' class='"+u+"_input'/>"},remove:function(a,b){return"<a href='javascript:;' class='"+u+"_remove'>"+(b.text||"X")+"</a>"}};b.extend({writeCart:function(a){var d=k.cartStyle.toLowerCase(),c="table"===d,g=c?"tr":"div",r=c?"th":"div",e=c?"td":"div",t=b.$create(d),d=b.$create(g).addClass("headerRow"),f,h;b.$(a).html(" ").append(t);t.append(d);c=0;for(h=k.cartColumns.length;c<h;c+=1)f=B(k.cartColumns[c]),a="item-"+
+(f.attr||f.view||f.label||f.text||"cell")+" "+f.className,f=f.label||"",d.append(b.$create(r).addClass(a).html(f));b.each(function(a,d){b.createCartRow(a,d,g,e,t)});return t},createCartRow:function(a,d,c,g,r){var d=b.$create(c).addClass("itemRow row-"+d+" "+(d%2?"even":"odd")).attr("id","cartItem_"+a.id()),e,f,j;r.append(d);r=0;for(c=k.cartColumns.length;r<c;r+=1)e=B(k.cartColumns[r]),f="item-"+(e.attr||(i(e.view,p)?e.view:e.label||e.text||"cell"))+" "+e.className,j=a,j=(h(e.view)?e.view:i(e.view,
+p)&&h(y[e.view])?y[e.view]:y.attr).call(b,j,e),f=b.$create(g).addClass(f).html(j),d.append(f);return d}});b.Item=function(a){function d(){i(c.price,p)&&(c.price=parseFloat(c.price.replace(b.currency().decimal,".").replace(/[^0-9\.]+/ig,"")));isNaN(c.price)&&(c.price=0);0>c.price&&(c.price=0);i(c.quantity,p)&&(c.quantity=parseInt(c.quantity.replace(b.currency().delimiter,""),10));isNaN(c.quantity)&&(c.quantity=1);0>=c.quantity&&g.remove()}var c={},g=this;i(a,"object")&&b.extend(c,a);l+=1;for(c.id=
+c.id||"SCI-"+l;!e(o[c.id]);)l+=1,c.id="SCI-"+l;g.get=function(a,b){var d=!b;return e(a)?a:h(c[a])?c[a].call(g):!e(c[a])?c[a]:h(g[a])&&d?g[a].call(g):!e(g[a])&&d?g[a]:c[a]};g.set=function(a,b){e(a)||(c[a.toLowerCase()]=b,("price"===a.toLowerCase()||"quantity"===a.toLowerCase())&&d());return g};g.equals=function(a){for(var b in c)if(Object.prototype.hasOwnProperty.call(c,b)&&"quantity"!==b&&"id"!==b&&a.get(b)!==c[b])return!1;return!0};g.options=function(){var a={};b.each(c,function(d,c,e){var f=!0;
+b.each(g.reservedFields(),function(a){a===e&&(f=!1);return f});f&&(a[e]=g.get(e))});return a};d()};b.Item._=b.Item.prototype={increment:function(a){a=parseInt(a||1,10);this.quantity(this.quantity()+a);return 1>this.quantity()?(this.remove(),null):this},decrement:function(a){return this.increment(-parseInt(a||1,10))},remove:function(a){if(!1===b.trigger("beforeRemove",[o[this.id()]]))return!1;delete o[this.id()];a||b.update();return null},reservedFields:function(){return"quantity id item_number price name shipping tax taxRate".split(" ")},
+fields:function(){var a={},d=this;b.each(d.reservedFields(),function(b){d.get(b)&&(a[b]=d.get(b))});return a},quantity:function(a){return e(a)?parseInt(this.get("quantity",!0)||1,10):this.set("quantity",a)},price:function(a){return e(a)?parseFloat(this.get("price",!0).toString().replace(b.currency().symbol,"").replace(b.currency().delimiter,"")||1):this.set("price",parseFloat(a.toString().replace(b.currency().symbol,"").replace(b.currency().delimiter,"")))},id:function(){return this.get("id",!1)},
+total:function(){return this.quantity()*this.price()}};b.extend({checkout:function(){if("custom"===k.checkout.type.toLowerCase()&&h(k.checkout.fn))k.checkout.fn.call(b,k.checkout);else if(h(b.checkout[k.checkout.type])){var a=b.checkout[k.checkout.type].call(b,k.checkout);a.data&&a.action&&a.method&&!1!==b.trigger("beforeCheckout",[a.data])&&b.generateAndSendForm(a)}else b.error("No Valid Checkout Method Specified")},extendCheckout:function(a){return b.extend(b.checkout,a)},generateAndSendForm:function(a){var d=
+b.$create("form");d.attr("style","display:none;");d.attr("action",a.action);d.attr("method",a.method);b.each(a.data,function(a,g,e){d.append(b.$create("input").attr("type","hidden").attr("name",e).val(a))});b.$("body").append(d);d.el.submit();d.remove()}});b.extendCheckout({PayPal:function(a){if(!a.email)return b.error("No email provided for PayPal checkout");var d={cmd:"_cart",upload:"1",currency_code:b.currency().code,business:a.email,rm:"GET"===a.method?"0":"2",tax_cart:(1*b.tax()).toFixed(2),
+handling_cart:(1*b.shipping()).toFixed(2),charset:"utf-8"},c=a.sandbox?"https://www.sandbox.paypal.com/cgi-bin/webscr":"https://www.paypal.com/cgi-bin/webscr",g="GET"===a.method?"GET":"POST";a.success&&(d["return"]=a.success);a.cancel&&(d.cancel_return=a.cancel);b.each(function(a,c){var g=c+1,e=a.options(),f=0,h;d["item_name_"+g]=a.get("name");d["quantity_"+g]=a.quantity();d["amount_"+g]=(a.price()*1).toFixed(2);d["item_number_"+g]=a.get("item_number")||g;b.each(e,function(a,c,e){if(c<10){h=true;
+b.each(k.excludeFromCheckout,function(a){a===e&&(h=false)});if(h){f=f+1;d["on"+c+"_"+g]=e;d["os"+c+"_"+g]=a}}});d["option_index_"+c]=Math.min(10,f)});return{action:c,method:g,data:d}},GoogleCheckout:function(a){if(!a.merchantID)return b.error("No merchant id provided for GoogleCheckout");if("USD"!==b.currency().code&&"GBP"!==b.currency().code)return b.error("Google Checkout only accepts USD and GBP");var d={ship_method_name_1:"Shipping",ship_method_price_1:b.shipping(),ship_method_currency_1:b.currency().code,
+_charset_:""},c="https://checkout.google.com/api/checkout/v2/checkoutForm/Merchant/"+a.merchantID,a="GET"===a.method?"GET":"POST";b.each(function(a,c){var e=c+1,f=[],h;d["item_name_"+e]=a.get("name");d["item_quantity_"+e]=a.quantity();d["item_price_"+e]=a.price();d["item_currency_ "+e]=b.currency().code;d["item_tax_rate"+e]=a.get("taxRate")||b.taxRate();b.each(a.options(),function(a,d,c){h=!0;b.each(k.excludeFromCheckout,function(a){a===c&&(h=!1)});h&&f.push(c+": "+a)});d["item_description_"+e]=f.join(", ")});
+return{action:c,method:a,data:d}},AmazonPayments:function(a){if(!a.merchant_signature)return b.error("No merchant signature provided for Amazon Payments");if(!a.merchant_id)return b.error("No merchant id provided for Amazon Payments");if(!a.aws_access_key_id)return b.error("No AWS access key id provided for Amazon Payments");var d={aws_access_key_id:a.aws_access_key_id,merchant_signature:a.merchant_signature,currency_code:b.currency().code,tax_rate:b.taxRate(),weight_unit:a.weight_unit||"lb"},c=(a.sandbox?
+"https://sandbox.google.com/checkout/":"https://checkout.google.com/")+"cws/v2/Merchant/"+a.merchant_id+"/checkoutForm",g="GET"===a.method?"GET":"POST";b.each(function(c,g){var e=g+1,f=[];d["item_title_"+e]=c.get("name");d["item_quantity_"+e]=c.quantity();d["item_price_"+e]=c.price();d["item_sku_ "+e]=c.get("sku")||c.id();d["item_merchant_id_"+e]=a.merchant_id;c.get("weight")&&(d["item_weight_"+e]=c.get("weight"));k.shippingQuantityRate&&(d["shipping_method_price_per_unit_rate_"+e]=k.shippingQuantityRate);
+b.each(c.options(),function(a,d,c){var g=true;b.each(k.excludeFromCheckout,function(a){a===c&&(g=false)});g&&(c!=="weight"&&c!=="tax")&&f.push(c+": "+a)});d["item_description_"+e]=f.join(", ")});return{action:c,method:g,data:d}},SendForm:function(a){if(!a.url)return b.error("URL required for SendForm Checkout");var d={currency:b.currency().code,shipping:b.shipping(),tax:b.tax(),taxRate:b.taxRate(),itemCount:b.find({}).length},c=a.url,g="GET"===a.method?"GET":"POST";b.each(function(a,c){var g=c+1,
+e=[],f;d["item_name_"+g]=a.get("name");d["item_quantity_"+g]=a.quantity();d["item_price_"+g]=a.price();b.each(a.options(),function(a,d,c){f=!0;b.each(k.excludeFromCheckout,function(a){a===c&&(f=!1)});f&&e.push(c+": "+a)});d["item_options_"+g]=e.join(", ")});a.success&&(d["return"]=a.success);a.cancel&&(d.cancel_return=a.cancel);a.extra_data&&(d=b.extend(d,a.extra_data));return{action:c,method:g,data:d}}});n={bind:function(a,d){if(!h(d))return this;this._events||(this._events={});var c=a.split(/ +/);
+b.each(c,function(a){this._events[a]===true?d.apply(this):e(this._events[a])?this._events[a]=[d]:this._events[a].push(d)});return this},trigger:function(a,b){var c=!0,g,f;this._events||(this._events={});if(!e(this._events[a])&&h(this._events[a][0])){g=0;for(f=this._events[a].length;g<f;g+=1)c=this._events[a][g].apply(this,b||[])}return!1===c?!1:!0}};n.on=n.bind;b.extend(n);b.extend(b.Item._,n);n={beforeAdd:null,afterAdd:null,load:null,beforeSave:null,afterSave:null,update:null,ready:null,checkoutSuccess:null,
+checkoutFail:null,beforeCheckout:null,beforeRemove:null};b(n);b.each(n,function(a,d,c){b.bind(c,function(){h(k[c])&&k[c].apply(this,arguments)})});b.extend({toCurrency:function(a,d){var c=parseFloat(a),g=d||{},g=b.extend(b.extend({symbol:"$",decimal:".",delimiter:",",accuracy:2,after:!1},b.currency()),g),e=c.toFixed(g.accuracy).split("."),c=e[1],e=e[0],e=b.chunk(e.reverse(),3).join(g.delimiter.reverse()).reverse();return(!g.after?g.symbol:"")+e+(c?g.decimal+c:"")+(g.after?g.symbol:"")},chunk:function(a,
+b){"undefined"===typeof b&&(b=2);return a.match(RegExp(".{1,"+b+"}","g"))||[]}});String.prototype.reverse=function(){return this.split("").reverse().join("")};b.extend({currency:function(a){if(i(a,p)&&!e(A[a]))k.currency=a;else if(i(a,"object"))A[a.code]=a,k.currency=a.code;else return A[k.currency]}});b.extend({bindOutlets:function(a){b.each(a,function(a,c,e){b.bind("update",function(){b.setOutlet("."+u+"_"+e,a)})})},setOutlet:function(a,d){var c=d.call(b,a);i(c,"object")&&c.el?b.$(a).html(" ").append(c):
+e(c)||b.$(a).html(c)},bindInputs:function(a){b.each(a,function(a){b.setInput("."+u+"_"+a.selector,a.event,a.callback)})},setInput:function(a,d,c){b.$(a).live(d,c)}});b.ELEMENT=function(a){this.create(a);this.selector=a||null};b.extend(w,{MooTools:{text:function(a){return this.attr("text",a)},html:function(a){return this.attr("html",a)},val:function(a){return this.attr("value",a)},attr:function(a,b){if(e(b))return this.el[0]&&this.el[0].get(a);this.el.set(a,b);return this},remove:function(){this.el.dispose();
+return null},addClass:function(a){this.el.addClass(a);return this},removeClass:function(a){this.el.removeClass(a);return this},append:function(a){this.el.adopt(a.el);return this},each:function(a){h(a)&&b.each(this.el,function(b,c,e){a.call(c,c,b,e)});return this},click:function(a){h(a)?this.each(function(b){b.addEvent("click",function(c){a.call(b,c)})}):e(a)&&this.el.fireEvent("click");return this},live:function(a,d){var c=this.selector;h(d)&&b.$("body").el.addEvent(a+":relay("+c+")",function(a,b){d.call(b,
+a)})},match:function(a){return this.el.match(a)},parent:function(){return b.$(this.el.getParent())},find:function(a){return b.$(this.el.getElements(a))},closest:function(a){return b.$(this.el.getParent(a))},descendants:function(){return this.find("*")},tag:function(){return this.el[0].tagName},submit:function(){this.el[0].submit();return this},create:function(a){this.el=x(a)}},Prototype:{text:function(a){if(e(a))return this.el[0].innerHTML;this.each(function(b,c){$(c).update(a)});return this},html:function(a){return this.text(a)},
+val:function(a){return this.attr("value",a)},attr:function(a,b){if(e(b))return this.el[0].readAttribute(a);this.each(function(c,e){$(e).writeAttribute(a,b)});return this},append:function(a){this.each(function(b,c){a.el?a.each(function(a,b){$(c).appendChild(b)}):v(a)&&$(c).appendChild(a)});return this},remove:function(){this.each(function(a,b){$(b).remove()});return this},addClass:function(a){this.each(function(b,c){$(c).addClassName(a)});return this},removeClass:function(a){this.each(function(b,c){$(c).removeClassName(a)});
+return this},each:function(a){h(a)&&b.each(this.el,function(b,c,e){a.call(c,c,b,e)});return this},click:function(a){h(a)?this.each(function(b,c){$(c).observe("click",function(b){a.call(c,b)})}):e(a)&&this.each(function(a,b){$(b).fire("click")});return this},live:function(a,b){if(h(b)){var c=this.selector;f.observe(a,function(a,e){e===x(a).findElement(c)&&b.call(e,a)})}},parent:function(){return b.$(this.el.up())},find:function(a){return b.$(this.el.getElementsBySelector(a))},closest:function(a){return b.$(this.el.up(a))},
+descendants:function(){return b.$(this.el.descendants())},tag:function(){return this.el.tagName},submit:function(){this.el[0].submit()},create:function(a){i(a,p)?this.el=x(a):v(a)&&(this.el=[a])}},jQuery:{passthrough:function(a,b){if(e(b))return this.el[a]();this.el[a](b);return this},text:function(a){return this.passthrough("text",a)},html:function(a){return this.passthrough("html",a)},val:function(a){return this.passthrough("val",a)},append:function(a){this.el.append(a.el||a);return this},attr:function(a,
+b){if(e(b))return this.el.attr(a);this.el.attr(a,b);return this},remove:function(){this.el.remove();return this},addClass:function(a){this.el.addClass(a);return this},removeClass:function(a){this.el.removeClass(a);return this},each:function(a){return this.passthrough("each",a)},click:function(a){return this.passthrough("click",a)},live:function(a,b){x(f).delegate(this.selector,a,b);return this},parent:function(){return b.$(this.el.parent())},find:function(a){return b.$(this.el.find(a))},closest:function(a){return b.$(this.el.closest(a))},
+tag:function(){return this.el[0].tagName},descendants:function(){return b.$(this.el.find("*"))},submit:function(){return this.el.submit()},create:function(a){this.el=x(a)}}});b.ELEMENT._=b.ELEMENT.prototype;b.ready(b.setupViewTool);b.ready(function(){b.bindOutlets({total:function(){return b.toCurrency(b.total())},quantity:function(){return b.quantity()},items:function(a){b.writeCart(a)},tax:function(){return b.toCurrency(b.tax())},taxRate:function(){return b.taxRate().toFixed()},shipping:function(){return b.toCurrency(b.shipping())},
+grandTotal:function(){return b.toCurrency(b.grandTotal())}});b.bindInputs([{selector:"checkout",event:"click",callback:function(){b.checkout()}},{selector:"empty",event:"click",callback:function(){b.empty()}},{selector:"increment",event:"click",callback:function(){b.find(b.$(this).closest(".itemRow").attr("id").split("_")[1]).increment();b.update()}},{selector:"decrement",event:"click",callback:function(){b.find(b.$(this).closest(".itemRow").attr("id").split("_")[1]).decrement();b.update()}},{selector:"remove",
+event:"click",callback:function(){b.find(b.$(this).closest(".itemRow").attr("id").split("_")[1]).remove()}},{selector:"input",event:"change",callback:function(){var a=b.$(this),d=a.parent(),c=d.attr("class").split(" ");b.each(c,function(c){c.match(/item-.+/i)&&(c=c.split("-")[1],b.find(d.closest(".itemRow").attr("id").split("_")[1]).set(c,a.val()),b.update())})}},{selector:"shelfItem .item_add",event:"click",callback:function(){var a={};b.$(this).closest("."+u+"_shelfItem").descendants().each(function(d,
+c){var e=b.$(c);e.attr("class")&&(e.attr("class").match(/item_.+/)&&!e.attr("class").match(/item_add/))&&b.each(e.attr("class").split(" "),function(b){var c,d;if(b.match(/item_.+/)){b=b.split("_")[1];c="";switch(e.tag().toLowerCase()){case "input":case "textarea":case "select":d=e.attr("type");if(!d||("checkbox"===d.toLowerCase()||"radio"===d.toLowerCase())&&e.attr("checked")||"text"===d.toLowerCase())c=e.val();break;case "img":c=e.attr("src");break;default:c=e.text()}null!==c&&""!==c&&(a[b.toLowerCase()]=
+a[b.toLowerCase()]?a[b.toLowerCase()]+", "+c:c)}})});b.add(a)}}])});f.addEventListener?m.DOMContentLoaded=function(){f.removeEventListener("DOMContentLoaded",DOMContentLoaded,!1);b.init()}:f.attachEvent&&(m.DOMContentLoaded=function(){"complete"===f.readyState&&(f.detachEvent("onreadystatechange",DOMContentLoaded),b.init())});(function(){if(f.readyState==="complete")return setTimeout(b.init,1);if(f.addEventListener){f.addEventListener("DOMContentLoaded",DOMContentLoaded,false);m.addEventListener("load",
+b.init,false)}else if(f.attachEvent){f.attachEvent("onreadystatechange",DOMContentLoaded);m.attachEvent("onload",b.init);var a=false;try{a=m.frameElement===null}catch(d){}f.documentElement.doScroll&&a&&C()}})();return b};m.simpleCart=z()})(window,document);var JSON;JSON||(JSON={});
+(function(){function m(e){return 10>e?"0"+e:e}function f(f){e.lastIndex=0;return e.test(f)?'"'+f.replace(e,function(e){var f=z[e];return"string"===typeof f?f:"\\u"+("0000"+e.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+f+'"'}function p(e,i){var q,l,o,m,w=h,s,j=i[e];j&&"object"===typeof j&&"function"===typeof j.toJSON&&(j=j.toJSON(e));"function"===typeof n&&(j=n.call(i,e,j));switch(typeof j){case "string":return f(j);case "number":return isFinite(j)?""+j:"null";case "boolean":case "null":return""+
j;case "object":if(!j)return"null";h+=v;s=[];if("[object Array]"===Object.prototype.toString.apply(j)){m=j.length;for(q=0;q<m;q+=1)s[q]=p(q,j)||"null";o=0===s.length?"[]":h?"[\n"+h+s.join(",\n"+h)+"\n"+w+"]":"["+s.join(",")+"]";h=w;return o}if(n&&"object"===typeof n){m=n.length;for(q=0;q<m;q+=1)"string"===typeof n[q]&&(l=n[q],(o=p(l,j))&&s.push(f(l)+(h?": ":":")+o))}else for(l in j)Object.prototype.hasOwnProperty.call(j,l)&&(o=p(l,j))&&s.push(f(l)+(h?": ":":")+o);o=0===s.length?"{}":h?"{\n"+h+s.join(",\n"+
h)+"\n"+w+"}":"{"+s.join(",")+"}";h=w;return o}}"function"!==typeof Date.prototype.toJSON&&(Date.prototype.toJSON=function(){return isFinite(this.valueOf())?this.getUTCFullYear()+"-"+m(this.getUTCMonth()+1)+"-"+m(this.getUTCDate())+"T"+m(this.getUTCHours())+":"+m(this.getUTCMinutes())+":"+m(this.getUTCSeconds())+"Z":null},String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(){return this.valueOf()});var i=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
-d=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,h,v,z={"\u0008":"\\b","\t":"\\t","\n":"\\n","\u000c":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},n;"function"!==typeof JSON.stringify&&(JSON.stringify=function(d,f,i){var l;v=h="";if(typeof i==="number")for(l=0;l<i;l=l+1)v=v+" ";else typeof i==="string"&&(v=i);if((n=f)&&typeof f!=="function"&&(typeof f!=="object"||typeof f.length!=="number"))throw Error("JSON.stringify");return p("",
-{"":d})});"function"!==typeof JSON.parse&&(JSON.parse=function(d,f){function h(d,i){var l,m,j=d[i];if(j&&typeof j==="object")for(l in j)Object.prototype.hasOwnProperty.call(j,l)&&(m=h(j,l),m!==void 0?j[l]=m:delete j[l]);return f.call(d,i,j)}var l,d=""+d;i.lastIndex=0;i.test(d)&&(d=d.replace(i,function(d){return"\\u"+("0000"+d.charCodeAt(0).toString(16)).slice(-4)}));if(/^[\],:{}\s]*$/.test(d.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,"@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,
-"]").replace(/(?:^|:|,)(?:\s*\[)+/g,"")))return l=eval("("+d+")"),typeof f==="function"?h({"":l},""):l;throw new SyntaxError("JSON.parse");})})();
-(function(){if(!this.localStorage)if(this.globalStorage)try{this.localStorage=this.globalStorage}catch(m){}else{var f=document.createElement("div");f.style.display="none";document.getElementsByTagName("head")[0].appendChild(f);if(f.addBehavior){f.addBehavior("#default#userdata");var p=this.localStorage={length:0,setItem:function(d,h){f.load("localStorage");d=i(d);f.getAttribute(d)||this.length++;f.setAttribute(d,h);f.save("localStorage")},getItem:function(d){f.load("localStorage");d=i(d);return f.getAttribute(d)},
-removeItem:function(d){f.load("localStorage");d=i(d);f.removeAttribute(d);f.save("localStorage");this.length=0},clear:function(){f.load("localStorage");for(var d=0;attr=f.XMLDocument.documentElement.attributes[d++];)f.removeAttribute(attr.name);f.save("localStorage");this.length=0},key:function(d){f.load("localStorage");return f.XMLDocument.documentElement.attributes[d]}},i=function(d){return d.replace(/[^-._0-9A-Za-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u37f-\u1fff\u200c-\u200d\u203f\u2040\u2070-\u218f]/g,
+e=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,h,v,z={"\u0008":"\\b","\t":"\\t","\n":"\\n","\u000c":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},n;"function"!==typeof JSON.stringify&&(JSON.stringify=function(e,f,i){var l;v=h="";if(typeof i==="number")for(l=0;l<i;l=l+1)v=v+" ";else typeof i==="string"&&(v=i);if((n=f)&&typeof f!=="function"&&(typeof f!=="object"||typeof f.length!=="number"))throw Error("JSON.stringify");return p("",
+{"":e})});"function"!==typeof JSON.parse&&(JSON.parse=function(e,f){function h(e,i){var l,m,j=e[i];if(j&&typeof j==="object")for(l in j)Object.prototype.hasOwnProperty.call(j,l)&&(m=h(j,l),m!==void 0?j[l]=m:delete j[l]);return f.call(e,i,j)}var l,e=""+e;i.lastIndex=0;i.test(e)&&(e=e.replace(i,function(e){return"\\u"+("0000"+e.charCodeAt(0).toString(16)).slice(-4)}));if(/^[\],:{}\s]*$/.test(e.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,"@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,
+"]").replace(/(?:^|:|,)(?:\s*\[)+/g,"")))return l=eval("("+e+")"),typeof f==="function"?h({"":l},""):l;throw new SyntaxError("JSON.parse");})})();
+(function(){if(!this.localStorage)if(this.globalStorage)try{this.localStorage=this.globalStorage}catch(m){}else{var f=document.createElement("div");f.style.display="none";document.getElementsByTagName("head")[0].appendChild(f);if(f.addBehavior){f.addBehavior("#default#userdata");var p=this.localStorage={length:0,setItem:function(e,h){f.load("localStorage");e=i(e);f.getAttribute(e)||this.length++;f.setAttribute(e,h);f.save("localStorage")},getItem:function(e){f.load("localStorage");e=i(e);return f.getAttribute(e)},
+removeItem:function(e){f.load("localStorage");e=i(e);f.removeAttribute(e);f.save("localStorage");this.length=0},clear:function(){f.load("localStorage");for(var e=0;attr=f.XMLDocument.documentElement.attributes[e++];)f.removeAttribute(attr.name);f.save("localStorage");this.length=0},key:function(e){f.load("localStorage");return f.XMLDocument.documentElement.attributes[e]}},i=function(e){return e.replace(/[^-._0-9A-Za-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u37f-\u1fff\u200c-\u200d\u203f\u2040\u2070-\u218f]/g,
"-")};f.load("localStorage");p.length=f.XMLDocument.documentElement.attributes.length}}})();
View
58 test/test.core.js
@@ -77,6 +77,18 @@ test("adding and removing items", function(){
});
same( item3.price() , 36 , "Price with dollar sign in front is parsed correctly");
+
+
+ simpleCart.empty();
+
+ var item4 = simpleCart.add({
+ name: "RaceCar",
+ quantity: 1.4342
+ });
+
+ same( item4.quantity() , 1 , "Item quantity parsed as INT and not decimal");
+ same( simpleCart.quantity(), 1 , "SimpleCart quantity parsed as INT and not decimal");
+
});
test("editing items", function(){
@@ -252,7 +264,6 @@ test("editing items", function(){
item.set("special_value" , "hullo");
-
});
@@ -272,9 +283,7 @@ test("editing items", function(){
simpleCart.bind( 'afterAdd' , function( item ){
afteradd_not_called = false;
});
-
-
-
+
simpleCart.load();
ok( beforeadd_not_called , "beforeAdd event is not called on load" );
@@ -381,7 +390,6 @@ test("editing items", function(){
shippingCustom: null
});
same( simpleCart.shipping() , 7 , "Item shipping prototype function works");
-
});
test("tax works", function(){
@@ -435,6 +443,44 @@ test("editing items", function(){
});
+ test("tax and shipping send to paypal", function(){
+
+ simpleCart({
+ taxRate: 0.5
+ });
+
+ simpleCart.shipping(function(){
+ return 5.55555;
+ });
+
+ simpleCart.empty();
+ simpleCart.add({
+ name: "cool thing with weird price",
+ price: 111.1111111111
+ });
+
+ simpleCart({
+ checkout: {
+ type: "PayPal",
+ email: "you@yours.com"
+ }
+ });
+
+ simpleCart.bind( "beforeCheckout" , function(data){
+
+ same( data.amount_1 , ( data.amount_1*1).toFixed(2) , "Item price is correctly formatted before going to paypal");
+ same( data.tax_cart , ( data.tax_cart*1 ).toFixed(2) , "Tax is correctly formated before going to paypal");
+ same( data.handling_cart , ( data.handling_cart*1 ).toFixed(2) ,"Shipping is correctly formated before going to paypal" );
+
+ return false;
+ });
+
+
+ simpleCart.checkout();
+
+ });
+
+
module('simpleCart.find');
test("simpleCart.find() function works", function(){
@@ -463,7 +509,6 @@ test("editing items", function(){
});
- module('simpleCart UI updates');
test("basic outlets work", function(){
var item = simpleCart.add({
@@ -493,7 +538,6 @@ test("editing items", function(){
});
- module('simpleCart UI updates');
test("basic outlets work", function(){
var item = simpleCart.add({

0 comments on commit bc8eacb

Please sign in to comment.
Something went wrong with that request. Please try again.