caboose-store 0.0.11 → 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/app/assets/javascripts/caboose_store/application.js +0 -2
- data/app/assets/javascripts/caboose_store/checkout.js +143 -143
- data/app/assets/javascripts/caboose_store/modules/checkout.js +31 -32
- data/app/assets/javascripts/caboose_store/modules/checkout_step1.js +157 -0
- data/app/assets/javascripts/caboose_store/modules/checkout_step2.js +39 -0
- data/app/assets/javascripts/caboose_store/modules/checkout_step3.js +34 -0
- data/app/assets/javascripts/caboose_store/modules/checkout_step4.js +102 -0
- data/app/assets/templates/caboose_store/checkout/forms/guest.jst.ejs +1 -1
- data/app/assets/templates/caboose_store/checkout/forms/register.jst.ejs +1 -1
- data/app/assets/templates/caboose_store/checkout/forms/signin.jst.ejs +1 -1
- data/app/assets/templates/caboose_store/checkout/line_items.jst.ejs +1 -2
- data/app/assets/templates/caboose_store/checkout/login.jst.ejs +4 -4
- data/app/controllers/caboose_store/checkout_controller.rb +108 -46
- data/app/helpers/caboose_store/checkout_helper.rb +15 -0
- data/app/models/caboose_store/schema.rb +4 -0
- data/app/models/caboose_store/states.rb +66 -0
- data/app/views/caboose_store/cart/index.html.erb +4 -0
- data/app/views/caboose_store/checkout/_confirm.html.erb +61 -0
- data/app/views/caboose_store/checkout/index.html.erb +1 -1
- data/app/views/caboose_store/checkout/relay.html.erb +2 -2
- data/app/views/caboose_store/checkout/relay_old.html.erb +12 -0
- data/app/views/caboose_store/checkout/step_four.html.erb +91 -0
- data/app/views/caboose_store/checkout/step_one.html.erb +46 -11
- data/app/views/caboose_store/checkout/step_one_old.html.erb +13 -0
- data/app/views/caboose_store/checkout/step_three.html.erb +23 -0
- data/app/views/caboose_store/checkout/step_two.html.erb +49 -13
- data/app/views/caboose_store/checkout/step_two_old.html.erb +14 -0
- data/app/views/caboose_store/products/details.html.erb +2 -0
- data/config/routes.rb +10 -7
- data/lib/caboose-store/version.rb +1 -1
- metadata +13 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NjAwYWNkNmZhNjUzOThlZDBkM2ZkOTYyYjFjNzhmMDlhNTNmZDFlNw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NDdiNGQ5ZDEwYjllOTlkMzU0MGIyYTY1MDQ3N2M3ZmU4ZjYyM2YyMA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
N2NlNmY5MjU0ZjhlMzBlMmZlYTZkYjZmMjExOWQwZTY3OTIzZjc4NjI1MmIz
|
10
|
+
YzM2M2FkZmQ3N2NlMjdkMTdlODJiZWFjZTMyMWVlMjA4MTc1MzU5NjQ0YWVh
|
11
|
+
MzM5NmNiNTYzODdmYjJkYWVhYjY3N2VhMDNmYmIxYjljZmU4ODE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NDlkYTI0MGRiMDFkYzM0OTgzYjJhMGY1NjJlM2QzMjEzYjM4YmVmMGNlZDg3
|
14
|
+
MDUwZDMyY2JiMGE1MzU4MGM3NjFmYzUzYmFhMGYxYzdlYmM4MWE3NTJhNzVj
|
15
|
+
YzgyMDY4MTY1OTE0ZWZkNjhjYWNkMDA0NTkzNmY2NzFiZDBiNjg=
|
@@ -6,146 +6,146 @@
|
|
6
6
|
// :: Shipping
|
7
7
|
// :: Payment
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
9
|
+
var CabooseCheckout = function() {
|
10
|
+
var self = this;
|
11
|
+
|
12
|
+
//
|
13
|
+
// Initialize
|
14
|
+
//
|
15
|
+
|
16
|
+
self.initialize = function() {
|
17
|
+
|
18
|
+
// Ensure that a user is logged in
|
19
|
+
//if (!Caboose.loggedIn && window.location.pathname.substring(0, 9) == '/checkout') Caboose.login();
|
20
|
+
console.log('foo');
|
21
|
+
|
22
|
+
// Route to correct method
|
23
|
+
switch (window.location.pathname) {
|
24
|
+
case '/checkout': self.index(); break;
|
25
|
+
case '/checkout/shipping': self.shipping(); break;
|
26
|
+
case '/checkout/billing': self.billing(); break;
|
27
|
+
}
|
28
|
+
};
|
29
|
+
|
30
|
+
//
|
31
|
+
// Index
|
32
|
+
//
|
33
|
+
|
34
|
+
self.index = function() {
|
35
|
+
|
36
|
+
// Ensure use as billing is automatically checked
|
37
|
+
$('#use-as-billing').prop('checked', true);
|
38
|
+
|
39
|
+
// Show/hide the billing form
|
40
|
+
$('#use-as-billing').on('change', function(event) {
|
41
|
+
if ($('#use-as-billing')[0].checked) {
|
42
|
+
$('#billing').hide()
|
43
|
+
} else {
|
44
|
+
$('#billing').show()
|
45
|
+
}
|
46
|
+
});
|
47
|
+
|
48
|
+
// Update address info
|
49
|
+
$('form#address').on('submit', function(event) {
|
50
|
+
event.preventDefault();
|
51
|
+
|
52
|
+
$.ajax({
|
53
|
+
url: '/checkout/address',
|
54
|
+
type: 'put',
|
55
|
+
data: $(event.delegateTarget).serialize(),
|
56
|
+
success: function(response) {
|
57
|
+
if (response.error) $('#message').html("<p class='note error'>" + response.error + "</p>");
|
58
|
+
if (response.redirect) window.location = response.redirect;
|
59
|
+
}
|
60
|
+
});
|
61
|
+
});
|
62
|
+
};
|
63
|
+
|
64
|
+
//
|
65
|
+
// Shipping
|
66
|
+
//
|
67
|
+
|
68
|
+
self.shipping = function() {
|
69
|
+
$('form#shipping-rates').one('submit', function(event) {
|
70
|
+
event.preventDefault();
|
71
|
+
|
72
|
+
var $form = $(event.delegateTarget)
|
73
|
+
, code = $('input[name=shipping_method_code]:checked', $form).val()
|
74
|
+
, name = $('input#shipping-method-' + code + '-name', $form).val()
|
75
|
+
, price = $('input#shipping-method-' + code + '-price', $form).val();
|
76
|
+
|
77
|
+
$.ajax({
|
78
|
+
url: '/checkout/shipping-method',
|
79
|
+
type: 'put',
|
80
|
+
data: {
|
81
|
+
shipping_method: {
|
82
|
+
code: code,
|
83
|
+
name: name,
|
84
|
+
price: price
|
85
|
+
}
|
86
|
+
},
|
87
|
+
success: function(response) {
|
88
|
+
if (response.error) $('#message').html("<p class='note error'>" + response.error + "</p>");
|
89
|
+
if (response.redirect) window.location = response.redirect;
|
90
|
+
}
|
91
|
+
});
|
92
|
+
});
|
93
|
+
};
|
94
|
+
|
95
|
+
//
|
96
|
+
// Billing
|
97
|
+
//
|
98
|
+
|
99
|
+
self.billing = function() {
|
100
|
+
window.relay = function(authorized) {
|
101
|
+
if (authorized) {
|
102
|
+
window.location.replace('/checkout/thanks');
|
103
|
+
} else {
|
104
|
+
window.location.replace('/checkout/error');
|
105
|
+
}
|
106
|
+
};
|
107
|
+
|
108
|
+
$('#billing-expiration-month, #billing-expiration-year').on('change', function(event) {
|
109
|
+
$('input[name=billing-cc-exp]').val($('#billing-expiration-month').val() + $('#billing-expiration-year').val());
|
110
|
+
});
|
111
|
+
|
112
|
+
$('#billing-form').one('submit', function(e) {
|
113
|
+
e.preventDefault();
|
114
|
+
|
115
|
+
// TODO this is a temporary fix.. for some reason the one submit event is getting registered multiple times
|
116
|
+
if ($('#billing-confirmation').length) return false;
|
117
|
+
|
118
|
+
$('input[name=billing-cc-exp]').val($('#billing-expiration-month').val() + $('#billing-expiration-year').val());
|
119
|
+
|
120
|
+
var $form = $(e.delegateTarget)
|
121
|
+
, cc_num = $form.find('input[name=billing-cc-number]').val()
|
122
|
+
, cc_exp = $form.find('input[name=billing-cc-exp]').val()
|
123
|
+
, total = $('input#billing-amount').val()
|
124
|
+
, $confirm = $(document.createElement('div'));
|
125
|
+
|
126
|
+
$confirm.attr('id', 'billing-confirmation');
|
127
|
+
$confirm.append( $('</p>').attr('style', 'margin-bottom: 0').html('<strong>Credit Card Number</strong>: xxxx-xxxx-xxxx-' + cc_num.replace(/\-\ /g, '').substr(-4)) );
|
128
|
+
$confirm.append( $('</p>').attr('style', 'margin-bottom: 0').html('<strong>Expiration Date</strong>: ' + cc_exp.substr(0, 2) + '/' + cc_exp.substr(2, 2)) );
|
129
|
+
$confirm.append( $('</p>').html('<strong>Total</strong>: $' + total) );
|
130
|
+
$confirm.append( $('</p>').attr('style', 'margin: 24px 0').html('<a href="/checkout/billing">Edit billing info</a>') );
|
131
|
+
$confirm.append( $('</p>').html('<input id="submit-billing" type="button" value="Continue >" />') );
|
132
|
+
|
133
|
+
$form.after($confirm);
|
134
|
+
$form.hide();
|
135
|
+
|
136
|
+
$confirm.find('#submit-billing').on('click', function(e) {
|
137
|
+
e.preventDefault();
|
138
|
+
$form.submit();
|
139
|
+
$confirm.after( $('</p>').addClass('loading').text('Authorizing transaction..') );
|
140
|
+
$confirm.hide();
|
141
|
+
});
|
142
|
+
});
|
143
|
+
};
|
144
|
+
|
145
|
+
// Init and return
|
146
|
+
$(document).ready(self.initialize);
|
147
|
+
return self;
|
148
|
+
};
|
149
|
+
|
150
|
+
CabooseStore.Checkout = new CabooseCheckout();
|
151
|
+
|
@@ -3,17 +3,25 @@
|
|
3
3
|
//
|
4
4
|
|
5
5
|
Caboose.Store.Modules.Checkout = (function() {
|
6
|
+
|
7
|
+
// Steps
|
8
|
+
// Step 1: Present non-editable cart and login/register/guest buttons.
|
9
|
+
// Step 2: Present shipping address form.
|
10
|
+
// Step 3: Present shipping options.
|
11
|
+
// Step 4: Present credit card form.
|
12
|
+
// Step 5: Thank you.
|
13
|
+
|
6
14
|
self = {
|
7
15
|
templates: {
|
8
|
-
address:
|
9
|
-
login:
|
10
|
-
payment:
|
11
|
-
lineItems:
|
12
|
-
shipping:
|
16
|
+
address: JST['caboose_store/checkout/address'],
|
17
|
+
login: JST['caboose_store/checkout/login'],
|
18
|
+
payment: JST['caboose_store/checkout/payment'],
|
19
|
+
lineItems: JST['caboose_store/checkout/line_items'],
|
20
|
+
shipping: JST['caboose_store/checkout/shipping'],
|
13
21
|
forms: {
|
14
|
-
signin:
|
22
|
+
signin: JST['caboose_store/checkout/forms/signin'],
|
15
23
|
register: JST['caboose_store/checkout/forms/register'],
|
16
|
-
guest:
|
24
|
+
guest: JST['caboose_store/checkout/forms/guest']
|
17
25
|
}
|
18
26
|
}
|
19
27
|
};
|
@@ -22,15 +30,11 @@ Caboose.Store.Modules.Checkout = (function() {
|
|
22
30
|
// Initialize
|
23
31
|
//
|
24
32
|
|
25
|
-
self.initialize = function() {
|
33
|
+
self.initialize = function() {
|
26
34
|
switch (window.location.pathname.replace(/\/$/, "")) {
|
27
35
|
case '/checkout':
|
28
|
-
case '/checkout/step-one':
|
29
|
-
|
30
|
-
break;
|
31
|
-
case '/checkout/step-two':
|
32
|
-
self.step = 2;
|
33
|
-
break;
|
36
|
+
case '/checkout/step-one': self.step = 1; break;
|
37
|
+
case '/checkout/step-two': self.step = 2; break;
|
34
38
|
}
|
35
39
|
|
36
40
|
self.$checkout = $('#checkout')
|
@@ -50,7 +54,7 @@ Caboose.Store.Modules.Checkout = (function() {
|
|
50
54
|
};
|
51
55
|
|
52
56
|
//
|
53
|
-
// Fetch
|
57
|
+
// Fetch items from the cart
|
54
58
|
//
|
55
59
|
|
56
60
|
self.fetch = function(callback) {
|
@@ -74,29 +78,24 @@ Caboose.Store.Modules.Checkout = (function() {
|
|
74
78
|
//
|
75
79
|
|
76
80
|
self.bindEventHandlers = function() {
|
77
|
-
self.$checkout.on('click', '[data-login-action]', self.loginClickHandler);
|
81
|
+
self.$checkout.on('click' , '[data-login-action]', self.loginClickHandler);
|
78
82
|
self.$checkout.on('submit', '#checkout-login form', self.loginSubmitHandler);
|
79
83
|
self.$checkout.on('change', 'input[type=checkbox][name=use_as_billing]', self.useAsBillingHandler);
|
80
|
-
self.$checkout.on('click', '#checkout-continue button', self.continueHandler);
|
81
|
-
self.$checkout.on('click', '#checkout-complete button', self.completeHandler);
|
84
|
+
self.$checkout.on('click' , '#checkout-continue button', self.continueHandler);
|
85
|
+
self.$checkout.on('click' , '#checkout-complete button', self.completeHandler);
|
82
86
|
self.$checkout.on('change', '#checkout-shipping select', self.shippingChangeHandler);
|
83
87
|
self.$checkout.on('change', '#checkout-payment form#payment select', self.expirationChangeHandler);
|
84
88
|
self.$checkout.on('submit', '#checkout-payment form#payment', self.paymentSubmitHandler);
|
85
89
|
};
|
86
90
|
|
91
|
+
$('.login-choices button').removeClass('selected');
|
87
92
|
self.loginClickHandler = function(event) {
|
88
93
|
$section = self.$login.children('section');
|
89
94
|
|
90
95
|
switch ($(event.target).data('login-action')) {
|
91
|
-
case 'signin':
|
92
|
-
|
93
|
-
|
94
|
-
case 'register':
|
95
|
-
$section.empty().html(self.templates.forms.register());
|
96
|
-
break;
|
97
|
-
case 'continue':
|
98
|
-
$section.empty().html(self.templates.forms.guest());
|
99
|
-
break;
|
96
|
+
case 'signin' : $section.slideUp(400, function() { $section.empty().html(self.templates.forms.signin() ).slideDown() }); $('#signin_button' ).addClass('selected'); break;
|
97
|
+
case 'register': $section.slideUp(400, function() { $section.empty().html(self.templates.forms.register()).slideDown() }); $('#register_button').addClass('selected'); break;
|
98
|
+
case 'continue': $section.slideUp(400, function() { $section.empty().html(self.templates.forms.guest() ).slideDown() }); $('#continue_button').addClass('selected'); break;
|
100
99
|
};
|
101
100
|
};
|
102
101
|
|
@@ -124,7 +123,7 @@ Caboose.Store.Modules.Checkout = (function() {
|
|
124
123
|
}
|
125
124
|
}
|
126
125
|
|
127
|
-
self.fetch();
|
126
|
+
self.fetch(self.render);
|
128
127
|
}
|
129
128
|
});
|
130
129
|
};
|
@@ -223,8 +222,8 @@ Caboose.Store.Modules.Checkout = (function() {
|
|
223
222
|
|
224
223
|
self.render = function() {
|
225
224
|
var renderFunctions = [];
|
226
|
-
|
227
|
-
if (self.step == 1) {
|
225
|
+
|
226
|
+
if (self.step == 1) {
|
228
227
|
renderFunctions.push(self.renderLineItems);
|
229
228
|
renderFunctions.push(self.renderLogin);
|
230
229
|
renderFunctions.push(self.renderAddress);
|
@@ -255,7 +254,7 @@ Caboose.Store.Modules.Checkout = (function() {
|
|
255
254
|
if (self.loggedIn) self.$login.remove();
|
256
255
|
if (self.loggedIn || !self.$login.length) return false;
|
257
256
|
self.$login.html(self.templates.login());
|
258
|
-
if (!self.order.email) self.$login.find('button[data-login-action="signin"]').click();
|
257
|
+
//if (!self.order.email) self.$login.find('button[data-login-action="signin"]').click();
|
259
258
|
if (callback) callback();
|
260
259
|
};
|
261
260
|
|
@@ -299,7 +298,7 @@ Caboose.Store.Modules.Checkout = (function() {
|
|
299
298
|
, value = serializedField.split('=')[1];
|
300
299
|
|
301
300
|
self.$payment.find('form [name="' + name + '"]').val(value);
|
302
|
-
});
|
301
|
+
});
|
303
302
|
}
|
304
303
|
|
305
304
|
self.expirationChangeHandler();
|