one_page_checkout 1.0.0
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.
- data/LICENSE +23 -0
- data/README.md +7 -0
- data/app/views/checkout/edit.html.erb +227 -0
- data/lib/one_page_checkout.rb +72 -0
- data/lib/one_page_checkout_hooks.rb +3 -0
- data/lib/tasks/install.rake +26 -0
- data/lib/tasks/one_page_checkout.rake +1 -0
- metadata +64 -0
data/LICENSE
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Redistribution and use in source and binary forms, with or without modification,
|
2
|
+
are permitted provided that the following conditions are met:
|
3
|
+
|
4
|
+
* Redistributions of source code must retain the above copyright notice,
|
5
|
+
this list of conditions and the following disclaimer.
|
6
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
7
|
+
this list of conditions and the following disclaimer in the documentation
|
8
|
+
and/or other materials provided with the distribution.
|
9
|
+
* Neither the name of the Rails Dog LLC nor the names of its
|
10
|
+
contributors may be used to endorse or promote products derived from this
|
11
|
+
software without specific prior written permission.
|
12
|
+
|
13
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
14
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
15
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
16
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
17
|
+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
18
|
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
19
|
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
20
|
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
21
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
22
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
23
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,227 @@
|
|
1
|
+
<% content_for :head do %>
|
2
|
+
<%= javascript_include_tag 'checkout', '/states' %>
|
3
|
+
<% end %>
|
4
|
+
<div id="checkout">
|
5
|
+
<h1><%= t("checkout")%></h1>
|
6
|
+
<%= render "shared/error_messages", :target => @order %>
|
7
|
+
<%= form_for @order, :url => update_checkout_path(@order.state), :html => { :id => "checkout_form_#{@order.state}" } do |form| %>
|
8
|
+
<legend><%= t("addresses") %></legend>
|
9
|
+
<table width="100%" cellpadding="0" cellspacing="0">
|
10
|
+
<tr><td>
|
11
|
+
<fieldset id='billing'>
|
12
|
+
<%= form.fields_for :bill_address do |bill_form| %>
|
13
|
+
<div class="inner">
|
14
|
+
<p class="field"> </p>
|
15
|
+
<p id="bfname" class="field">
|
16
|
+
<%= bill_form.label :firstname, t(:first_name) %>
|
17
|
+
<%= bill_form.text_field :firstname, :class => 'required' %><span class="req">*</span>
|
18
|
+
</p>
|
19
|
+
<p id="blname" class="field">
|
20
|
+
<%= bill_form.label :lastname, t(:last_name) %>
|
21
|
+
<%= bill_form.text_field :lastname, :class => 'required' %><span class="req">*</span>
|
22
|
+
</p>
|
23
|
+
<p id="baddress" class="field">
|
24
|
+
<%= bill_form.label :address1, t(:street_address) %>
|
25
|
+
<%= bill_form.text_field :address1, :class => 'required' %><span class="req">*</span>
|
26
|
+
</p>
|
27
|
+
<p id="baddress2" class="field">
|
28
|
+
<%= bill_form.label :address2, t(:street_address_2) %>
|
29
|
+
<%= bill_form.text_field :address2 %>
|
30
|
+
</p>
|
31
|
+
<p id="bcity" class="field">
|
32
|
+
<%= bill_form.label :city, t(:city) %>
|
33
|
+
<%= bill_form.text_field :city, :class => 'required' %><span class="req">*</span>
|
34
|
+
</p>
|
35
|
+
<% if Spree::Config[:address_requires_state] %>
|
36
|
+
<p class="field">
|
37
|
+
<span id="bstate">
|
38
|
+
<% have_states = !@order.bill_address.country.states.empty? %>
|
39
|
+
<%= bill_form.label :state, t(:state) %>
|
40
|
+
<noscript>
|
41
|
+
<%= bill_form.text_field :state_name, :class => 'required' %>
|
42
|
+
</noscript>
|
43
|
+
<% state_elements = [
|
44
|
+
bill_form.collection_select(:state_id, @order.bill_address.country.states,
|
45
|
+
:id, :name,
|
46
|
+
{:include_blank => true},
|
47
|
+
{:class => have_states ? "required" : "hidden",
|
48
|
+
:disabled => !have_states}) +
|
49
|
+
bill_form.text_field(:state_name,
|
50
|
+
:class => !have_states ? "required" : "hidden",
|
51
|
+
:disabled => have_states)
|
52
|
+
].join.gsub('"', "'").gsub("\n", "")
|
53
|
+
%>
|
54
|
+
<script type="text/javascript" language="javascript" charset="utf-8">
|
55
|
+
// <![CDATA[
|
56
|
+
document.write("<%= raw state_elements %>");
|
57
|
+
// ]]>
|
58
|
+
</script>
|
59
|
+
</span>
|
60
|
+
<span class="req">*</span>
|
61
|
+
</p>
|
62
|
+
<% end %>
|
63
|
+
<p id="bzip" class="field">
|
64
|
+
<%= bill_form.label :zipcode, t(:zip) %>
|
65
|
+
<%= bill_form.text_field :zipcode, :class => 'required' %><span class="req">*</span>
|
66
|
+
</p>
|
67
|
+
<p id="bcountry" class="field">
|
68
|
+
<%= bill_form.label :country_id, t(:country) %>
|
69
|
+
<span id="bcountry"><%= bill_form.collection_select :country_id, available_countries, :id, :name, {}, {:class => 'required'} %></span>
|
70
|
+
<span class="req">*</span>
|
71
|
+
</p>
|
72
|
+
<p id="bphone" class="field">
|
73
|
+
<%= bill_form.label :phone, t(:phone) %>
|
74
|
+
<%= bill_form.text_field :phone, :class => 'required' %><span class="req">*</span>
|
75
|
+
</p>
|
76
|
+
<% if Spree::Config[:alternative_billing_phone] %>
|
77
|
+
<p id="baltphone">
|
78
|
+
<%= bill_form.label :alternative_phone, t(:alternative_phone) %>
|
79
|
+
<%= bill_form.text_field :alternative_phone %>
|
80
|
+
</p>
|
81
|
+
<% end %>
|
82
|
+
</div>
|
83
|
+
<% end %>
|
84
|
+
</fieldset>
|
85
|
+
</td><td>
|
86
|
+
<fieldset id='shipping'>
|
87
|
+
<%= form.fields_for :ship_address do |ship_form| %>
|
88
|
+
<p class="field checkbox">
|
89
|
+
<label for="order_use_billing" id="use_billing">
|
90
|
+
<%= check_box_tag 'order[use_billing]', '1', (!(@order.bill_address.empty? && @order.ship_address.empty?) && @order.bill_address.eql?(@order.ship_address)) %> <%= t("use_billing_address") %>
|
91
|
+
</label>
|
92
|
+
</p>
|
93
|
+
<div class="inner">
|
94
|
+
<p id="sfname" class="field">
|
95
|
+
<%= ship_form.label :firstname, t(:first_name) %>
|
96
|
+
<%= ship_form.text_field :firstname, :class => 'required' %><span class="req">*</span>
|
97
|
+
</p>
|
98
|
+
<p id="slname" class="field">
|
99
|
+
<%= ship_form.label :lastname, t(:last_name) %>
|
100
|
+
<%= ship_form.text_field :lastname, :class => 'required' %><span class="req">*</span>
|
101
|
+
</p>
|
102
|
+
<p id="saddress" class="field">
|
103
|
+
<%= ship_form.label :address1, t(:street_address) %>
|
104
|
+
<%= ship_form.text_field :address1, :class => 'required' %><span class="req">*</span>
|
105
|
+
</p>
|
106
|
+
<p id="saddress2" class="field">
|
107
|
+
<%= ship_form.label :address2, t(:street_address_2) %>
|
108
|
+
<%= ship_form.text_field :address2 %>
|
109
|
+
</p>
|
110
|
+
<p id="scity" class="field">
|
111
|
+
<%= ship_form.label :city, t(:city) %>
|
112
|
+
<%= ship_form.text_field :city, :class => 'required' %><span class="req">*</span>
|
113
|
+
</p>
|
114
|
+
<% if Spree::Config[:address_requires_state] %>
|
115
|
+
<p class="field">
|
116
|
+
<span id="sstate">
|
117
|
+
<% have_states = !@order.ship_address.country.states.empty? %>
|
118
|
+
<%= ship_form.label :state, t(:state) %>
|
119
|
+
<noscript>
|
120
|
+
<%= ship_form.text_field :state_name, :class => 'required' %>
|
121
|
+
</noscript>
|
122
|
+
<% state_elements = [
|
123
|
+
ship_form.collection_select(:state_id, @order.bill_address.country.states,
|
124
|
+
:id, :name,
|
125
|
+
{:include_blank => true},
|
126
|
+
{:class => have_states ? "required" : "hidden",
|
127
|
+
:disabled => !have_states}) +
|
128
|
+
ship_form.text_field(:state_name,
|
129
|
+
:class => !have_states ? "required" : "hidden",
|
130
|
+
:disabled => have_states)
|
131
|
+
].join.gsub('"', "'").gsub("\n", "")
|
132
|
+
%>
|
133
|
+
<script type="text/javascript" language="javascript" charset="utf-8">
|
134
|
+
// <![CDATA[
|
135
|
+
document.write("<%= raw state_elements %>");
|
136
|
+
// ]]>
|
137
|
+
</script>
|
138
|
+
</span>
|
139
|
+
<span class="req">*</span>
|
140
|
+
</p>
|
141
|
+
<% end %>
|
142
|
+
<p id="szip" class="field">
|
143
|
+
<%= ship_form.label :zipcode, t(:zip) %>
|
144
|
+
<%= ship_form.text_field :zipcode, :class => 'required' %><span class="req">*</span>
|
145
|
+
</p>
|
146
|
+
<p id="scountry" class="field">
|
147
|
+
<%= ship_form.label :country_id, t(:country) %>
|
148
|
+
<span id="scountry"><%= ship_form.collection_select :country_id, available_countries, :id, :name, {}, {:class => 'required'} %></span>
|
149
|
+
<span class="req">*</span>
|
150
|
+
</p>
|
151
|
+
<p id="sphone" class="field">
|
152
|
+
<%= ship_form.label :phone, t(:phone) %>
|
153
|
+
<%= ship_form.text_field :phone, :class => 'required' %><span class="req">*</span>
|
154
|
+
</p>
|
155
|
+
<% if Spree::Config[:alternative_shipping_phone] %>
|
156
|
+
<p id="saltphone">
|
157
|
+
<%= ship_form.label :alternative_phone, t(:alternative_phone) %>
|
158
|
+
<%= ship_form.text_field :alternative_phone %>
|
159
|
+
</p>
|
160
|
+
<% end %>
|
161
|
+
</div>
|
162
|
+
<% end %>
|
163
|
+
</fieldset>
|
164
|
+
</td></tr></table>
|
165
|
+
|
166
|
+
<fieldset id='shipping_method'>
|
167
|
+
<legend><%= t("shipping_method") %></legend>
|
168
|
+
<div class="inner">
|
169
|
+
<div id="methods">
|
170
|
+
<p class="field radios">
|
171
|
+
<% @order.rate_hash.each do |shipping_method| %>
|
172
|
+
<label>
|
173
|
+
<%= radio_button(:order, :shipping_method_id, shipping_method[:id]) %>
|
174
|
+
<%= shipping_method[:name] %> <%= number_to_currency shipping_method[:cost] %>
|
175
|
+
</label><br />
|
176
|
+
<% end %>
|
177
|
+
</p>
|
178
|
+
</div>
|
179
|
+
<% if Spree::Config[:shipping_instructions] && @order.rate_hash.present? %>
|
180
|
+
<p id="minstrs">
|
181
|
+
<%= form.label :special_instructions, t("shipping_instructions") %><br />
|
182
|
+
<%= form.text_area :special_instructions, :cols => 40, :rows => 7 %>
|
183
|
+
</p>
|
184
|
+
<% end %>
|
185
|
+
</div>
|
186
|
+
</fieldset>
|
187
|
+
|
188
|
+
<fieldset id="payment">
|
189
|
+
<legend><%= t("payment_information") %></legend>
|
190
|
+
<%= hook :checkout_payment_step, {:form => form} do %>
|
191
|
+
<% @order.available_payment_methods.each do |method| %>
|
192
|
+
<p>
|
193
|
+
<label>
|
194
|
+
<%= radio_button_tag "order[payments_attributes][][payment_method_id]", method.id, method == @order.payment_method %>
|
195
|
+
<%= t(method.name, :scope => :payment_methods, :default => method.name) %>
|
196
|
+
</label>
|
197
|
+
</p>
|
198
|
+
<% end %>
|
199
|
+
|
200
|
+
<ul id="payment-methods">
|
201
|
+
<% @order.available_payment_methods.each do |method| %>
|
202
|
+
<li id="payment_method_<%= method.id %>"<%= ' class="last"' if method == @order.available_payment_methods.last %>>
|
203
|
+
<fieldset>
|
204
|
+
<%= render "checkout/payment/#{method.method_type}", :payment_method => method %>
|
205
|
+
</fieldset>
|
206
|
+
</li>
|
207
|
+
<% end %>
|
208
|
+
</ul>
|
209
|
+
<br style='clear:both;' />
|
210
|
+
<p>
|
211
|
+
<label><%= t(:coupon_code) %></label><br />
|
212
|
+
<%= form.text_field :coupon_code, :size => 19 %>
|
213
|
+
</p>
|
214
|
+
<% end %>
|
215
|
+
</fieldset>
|
216
|
+
|
217
|
+
<fieldset id="order_details">
|
218
|
+
<div class="clear"></div>
|
219
|
+
<legend><%= t("confirm") %></legend>
|
220
|
+
<%= render :partial => 'shared/order_details', :locals => {:order => @order} %>
|
221
|
+
</fieldset>
|
222
|
+
|
223
|
+
<div class="form-buttons">
|
224
|
+
<input type="submit" class="continue button primary" value="<%=t("place_order") %>"/>
|
225
|
+
</div>
|
226
|
+
<% end %>
|
227
|
+
</div>
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'spree_core'
|
2
|
+
require 'one_page_checkout_hooks'
|
3
|
+
|
4
|
+
module OnePageCheckout
|
5
|
+
class Engine < Rails::Engine
|
6
|
+
|
7
|
+
config.autoload_paths += %W(#{config.root}/lib)
|
8
|
+
|
9
|
+
def self.activate
|
10
|
+
Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
|
11
|
+
Rails.env.production? ? require(c) : load(c)
|
12
|
+
end
|
13
|
+
#Order.send(:include, OrderDecorator)
|
14
|
+
CheckoutController.class_eval do
|
15
|
+
def before_one_page
|
16
|
+
@order.bill_address ||= Address.new(:country => default_country)
|
17
|
+
@order.ship_address ||= Address.new(:country => default_country)
|
18
|
+
@order.shipping_method ||= (@order.rate_hash.first && @order.rate_hash.first[:shipping_method])
|
19
|
+
@order.payments.destroy_all if request.put?
|
20
|
+
end
|
21
|
+
|
22
|
+
# change this to alias / spree
|
23
|
+
def object_params
|
24
|
+
if params[:payment_source].present? && source_params = params.delete(:payment_source)[params[:order][:payments_attributes].first[:payment_method_id].underscore]
|
25
|
+
params[:order][:payments_attributes].first[:source_attributes] = source_params
|
26
|
+
end
|
27
|
+
if (params[:order][:payments_attributes])
|
28
|
+
params[:order][:payments_attributes].first[:amount] = @order.total
|
29
|
+
end
|
30
|
+
params[:order]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
Order.class_eval do
|
35
|
+
state_machines.clear
|
36
|
+
state_machines[:state] = StateMachine::Machine.new(Order, :initial => 'cart', :use_transactions => false) do
|
37
|
+
event :next do
|
38
|
+
transition :from => 'cart', :to => 'one_page'
|
39
|
+
transition :from => 'one_page', :to => 'complete'
|
40
|
+
end
|
41
|
+
event :cancel do
|
42
|
+
transition :to => 'canceled', :if => :allow_cancel?
|
43
|
+
end
|
44
|
+
event :return do
|
45
|
+
transition :to => 'returned', :from => 'awaiting_return'
|
46
|
+
end
|
47
|
+
event :resume do
|
48
|
+
transition :to => 'resumed', :from => 'canceled', :if => :allow_resume?
|
49
|
+
end
|
50
|
+
event :authorize_return do
|
51
|
+
transition :to => 'awaiting_return'
|
52
|
+
end
|
53
|
+
before_transition :to => 'complete' do |order|
|
54
|
+
begin
|
55
|
+
order.process_payments!
|
56
|
+
rescue Spree::GatewayError
|
57
|
+
if Spree::Config[:allow_checkout_on_gateway_error]
|
58
|
+
true
|
59
|
+
else
|
60
|
+
false
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
after_transition :to => 'complete', :do => :finalize!
|
65
|
+
after_transition :to => 'canceled', :do => :after_cancel
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
config.to_prepare &method(:activate).to_proc
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
namespace :one_page_checkout do
|
2
|
+
desc "Copies all migrations and assets (NOTE: This will be obsolete with Rails 3.1)"
|
3
|
+
task :install do
|
4
|
+
Rake::Task['one_page_checkout:install:migrations'].invoke
|
5
|
+
Rake::Task['one_page_checkout:install:assets'].invoke
|
6
|
+
end
|
7
|
+
|
8
|
+
namespace :install do
|
9
|
+
desc "Copies all migrations (NOTE: This will be obsolete with Rails 3.1)"
|
10
|
+
task :migrations do
|
11
|
+
source = File.join(File.dirname(__FILE__), '..', '..', 'db')
|
12
|
+
destination = File.join(Rails.root, 'db')
|
13
|
+
puts "INFO: Mirroring assets from #{source} to #{destination}"
|
14
|
+
Spree::FileUtilz.mirror_files(source, destination)
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "Copies all assets (NOTE: This will be obsolete with Rails 3.1)"
|
18
|
+
task :assets do
|
19
|
+
source = File.join(File.dirname(__FILE__), '..', '..', 'public')
|
20
|
+
destination = File.join(Rails.root, 'public')
|
21
|
+
puts "INFO: Mirroring assets from #{source} to #{destination}"
|
22
|
+
Spree::FileUtilz.mirror_files(source, destination)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
# add custom rake tasks here
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: one_page_checkout
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Saurabh Bhatia
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-11-23 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: spree_core
|
16
|
+
requirement: &78480800 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0.70'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *78480800
|
25
|
+
description:
|
26
|
+
email: saurabh.a.bhatia@gmail.com
|
27
|
+
executables: []
|
28
|
+
extensions: []
|
29
|
+
extra_rdoc_files: []
|
30
|
+
files:
|
31
|
+
- README.md
|
32
|
+
- LICENSE
|
33
|
+
- lib/one_page_checkout_hooks.rb
|
34
|
+
- lib/tasks/install.rake
|
35
|
+
- lib/tasks/one_page_checkout.rake
|
36
|
+
- lib/one_page_checkout.rb
|
37
|
+
- app/views/checkout/edit.html.erb
|
38
|
+
homepage: http://wub.heroku.com
|
39
|
+
licenses: []
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
none: false
|
46
|
+
requirements:
|
47
|
+
- - ! '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 1.8.7
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
requirements:
|
57
|
+
- none
|
58
|
+
rubyforge_project:
|
59
|
+
rubygems_version: 1.8.10
|
60
|
+
signing_key:
|
61
|
+
specification_version: 3
|
62
|
+
summary: Single Page Checkout For SpreeCommerce
|
63
|
+
test_files: []
|
64
|
+
has_rdoc: true
|