forked from spree/spree
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixing admin order creation/checkout
- Loading branch information
Zac Williams
committed
Sep 24, 2010
1 parent
c1ba4e4
commit b303504
Showing
15 changed files
with
377 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,74 @@ | ||
class Admin::CheckoutController < Admin::BaseController | ||
|
||
helper :checkout | ||
before_filter :load_data | ||
before_filter :load_order | ||
|
||
def update | ||
if @order.update_attributes(params[:order]) | ||
if @order.completed? | ||
redirect_to admin_checkout_url(@order) | ||
else | ||
redirect_to edit_admin_order_shipment_url(@order, @order.shipment) | ||
begin | ||
if @order.update_attributes(object_params) | ||
if @order.next | ||
state_callback(:after) | ||
if @order.state == "complete" | ||
flash[:notice] = I18n.t(:order_processed_successfully) | ||
redirect_to admin_order_path(@order) and return | ||
else | ||
redirect_to admin_checkout_state_path(@order.state) and return | ||
end | ||
end | ||
end | ||
else | ||
render :edit | ||
rescue Spree::GatewayError | ||
flash[:error] = I18n.t(:payment_processing_failed) | ||
redirect_to admin_checkout_state_path('payment') | ||
return | ||
end | ||
render :edit | ||
end | ||
|
||
private | ||
def load_data | ||
@order = Order.find_by_number(params[:number]) | ||
|
||
def object_params | ||
# For payment step, filter order parameters to produce the expected nested attributes for a single payment and its source, discarding attributes for payment methods other than the one selected | ||
if @order.payment? | ||
if params[:payment_source].present? && source_params = params.delete(:payment_source)[params[:order][:payments_attributes].first[:payment_method_id].underscore] | ||
params[:order][:payments_attributes].first[:source_attributes] = source_params | ||
end | ||
if (params[:order][:payments_attributes]) | ||
params[:order][:payments_attributes].first[:amount] = @order.total | ||
end | ||
end | ||
params[:order] | ||
end | ||
|
||
def load_order | ||
@order = current_order | ||
@order.state = params[:state] if params[:state] | ||
state_callback(:before) | ||
end | ||
|
||
def before_address | ||
@order.bill_address ||= Address.new(:country => default_country) | ||
@order.ship_address ||= Address.new(:country => default_country) | ||
end | ||
|
||
def before_delivery | ||
@order.shipping_method ||= (@order.rate_hash.first && @order.rate_hash.first[:shipping_method]) | ||
end | ||
|
||
def before_payment | ||
current_order.payments.destroy_all if request.put? | ||
end | ||
|
||
def after_complete | ||
session[:order_id] = nil | ||
end | ||
|
||
def default_country | ||
Country.find Spree::Config[:default_country_id] | ||
end | ||
|
||
def state_callback(before_or_after = :before) | ||
method_name = :"#{before_or_after}_#{@order.state}" | ||
send(method_name) if respond_to?(method_name, true) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<%= render 'billing_fields', :form => form %> | ||
<%= render 'shipping_fields', :form => form %> | ||
|
||
<p class="form-buttons"> | ||
<%= button t('continue') %> | ||
</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<fieldset id='billing'> | ||
<%= form.fields_for :bill_address do |bill_form| %> | ||
|
||
<legend><%= t("billing_address")%></legend> | ||
|
||
<table> | ||
<tr> | ||
<td> | ||
<%= bill_form.text_field :firstname %><span class="req">*</span> | ||
<%= bill_form.label :firstname, t(:first_name) %> | ||
</td> | ||
<td> | ||
<%= bill_form.text_field :lastname %><span class="req">*</span> | ||
<%= bill_form.label :lastname, t(:last_name) %> | ||
</td> | ||
</tr> | ||
|
||
<tr> | ||
<td> | ||
<%= bill_form.text_field :address1 %><span class="req">*</span> | ||
<%= bill_form.label :address1, t(:street_address) %> | ||
</td> | ||
<td> | ||
<%= bill_form.text_field :address2 %> | ||
<%= bill_form.label :address2, t(:street_address_2) %> | ||
</td> | ||
</tr> | ||
|
||
<tr> | ||
<td> | ||
<%= bill_form.text_field :city %><span class="req">*</span> | ||
<%= bill_form.label :city, t(:city) %> | ||
</td> | ||
<td> | ||
<%= bill_form.text_field :zipcode %><span class="req">*</span> | ||
<%= bill_form.label :zipcode, t(:zip) %> | ||
</td> | ||
</tr> | ||
<% if Spree::Config[:address_requires_state] %> | ||
<tr> | ||
<td> | ||
<span id="bstate"> | ||
<% have_states = !@order.bill_address.country.states.empty? %> | ||
|
||
<noscript> | ||
<%= bill_form.text_field :state_name %> | ||
</noscript> | ||
<% state_elements = [ | ||
bill_form.collection_select(:state_id, @order.bill_address.country.states, | ||
:id, :name, | ||
{:include_blank => true}, | ||
{:class => have_states ? "" : "hidden", | ||
:disabled => !have_states}) + | ||
bill_form.text_field(:state_name, | ||
:class => !have_states ? "" : "hidden", | ||
:disabled => have_states) | ||
].join.gsub('"', "'").gsub("\n", "") | ||
%> | ||
<script type="text/javascript" language="javascript" charset="utf-8"> | ||
// <![CDATA[ | ||
document.write("<%= raw state_elements %>"); | ||
// ]]> | ||
</script> | ||
</span> | ||
<%= bill_form.label :state, t(:state) %> <span class="req">*</span> | ||
</td> | ||
</tr> | ||
<% end %> | ||
|
||
<tr> | ||
<td> | ||
<span id="bcountry"><%= bill_form.collection_select :country_id, available_countries, :id, :name, {} %></span> | ||
<%= bill_form.label :country_id, t(:country) %> | ||
</td> | ||
</tr> | ||
|
||
<tr> | ||
<td> | ||
<%= bill_form.label :phone, t(:phone) %> | ||
<%= bill_form.text_field :phone %><span class="req">*</span> | ||
</td> | ||
<% if Spree::Config[:alternative_billing_phone] %> | ||
<td> | ||
<%= bill_form.label :alternative_phone, t(:alternative_phone) %> | ||
<%= bill_form.text_field :alternative_phone %> | ||
</td> | ||
<% end %> | ||
</tr> | ||
</table> | ||
<% end %> | ||
</fieldset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
|
||
<h3><%= t("customer_details") %></h3> | ||
<fieldset> | ||
<legend><%= t('account') %></legend> | ||
<table class="index"> | ||
<tbody> | ||
<tr> | ||
<td class="lbl-col"><%= form.label :email, t(:email)+':' %></td> | ||
<td class="val-col" colspan="3"><%= form.text_field :email, :class => "fullwidth" %></td> | ||
<td class="lbl-col"><label><%= t('guest_checkout') %>:</label></td> | ||
<td class="val-col" colspan="3"> | ||
<% unless @order.state == "complete" %> | ||
<label class="sub"> | ||
<%= radio_button_tag :guest_checkout, true, @order.user.nil? %> | ||
<%= t("yes") %> | ||
</label> | ||
<label class="sub"> | ||
<%= radio_button_tag :guest_checkout, false, !@order.user.nil?, :disabled => @order.state == "in_progress" %> | ||
<%= t("no") %> | ||
</label> | ||
<%= hidden_field_tag :user_id, @order.user_id %> | ||
<% else %> | ||
<%= @order.user.nil? ? "Yes" : "No" %> | ||
<% end %> | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</fieldset> | ||
|
||
<p class="form-buttons"> | ||
<%= button t('continue') %> | ||
</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<fieldset id="order_details"> | ||
<div class="clear"></div> | ||
<legend><%= t("confirm") %></legend> | ||
<%= render :partial => 'shared/order_details', :locals => {:order => @order} %> | ||
</fieldset> | ||
|
||
<hr /> | ||
|
||
<p class="form-buttons"> | ||
<%= button t('place_order') %> | ||
</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<fieldset id='shipping_method'> | ||
<legend><%= t("shipping_method") %></legend> | ||
|
||
<% @order.rate_hash.each do |shipping_method| %> | ||
<label> | ||
<%= radio_button(:order, :shipping_method_id, shipping_method[:id]) %> | ||
<%= shipping_method[:name] %> <%= number_to_currency shipping_method[:cost] %> | ||
</label><br /> | ||
<% end %> | ||
<% if Spree::Config[:shipping_instructions] && @available_methods.present? %> | ||
<p id="minstrs"> | ||
<%= checkout_form.label :special_instructions, t("shipping_instructions") %><br /> | ||
<%= checkout_form.text_area :special_instructions, :cols => 40, :rows => 7 %> | ||
</p> | ||
<% end %> | ||
|
||
</fieldset> | ||
|
||
<p class="form-buttons"> | ||
<%= button t('continue') %> | ||
</p> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<fieldset id="payment"> | ||
<legend><%= t("payment_information") %></legend> | ||
|
||
<% @order.available_payment_methods.each do |method| %> | ||
<p> | ||
<label> | ||
<%= radio_button_tag "order[payments_attributes][][payment_method_id]", method.id, method == @order.payment_method %> | ||
<%= t(method.name, :scope => :payment_methods, :default => method.name) %> | ||
</label> | ||
</p> | ||
<% end %> | ||
|
||
<ul > | ||
<% @order.available_payment_methods.each do |method| %> | ||
<li> | ||
|
||
<%= render "checkout/payment/#{method.method_type}", :payment_method => method %> | ||
|
||
</li> | ||
<% end %> | ||
</ul> | ||
|
||
</fieldset> | ||
|
||
<p class="form-buttons"> | ||
<%= button t('continue') %> | ||
</p> |
Oops, something went wrong.