Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code readability and (basic) UX improvements #301

Merged
merged 4 commits into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions templates/app/controllers/checkouts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# is warranted.
class CheckoutsController < CheckoutBaseController
before_action :ensure_valid_state
before_action :ensure_valid_payment
before_action :check_registration
before_action :setup_for_current_state

Expand Down Expand Up @@ -101,17 +102,20 @@ def massaged_params
end

def ensure_valid_state
unless skip_state_validation?
if (params[:state] && [email protected]_checkout_step?(params[:state])) ||
(!params[:state] && [email protected]_checkout_step?(@order.state))
@order.state = 'cart'
redirect_to checkout_state_path(@order.checkout_steps.first)
end
end
return if skip_state_validation?
return if @order.has_checkout_step?(params[:state] || @order.state)

@order.state = 'cart'
redirect_to checkout_state_path(@order.checkout_steps.first)
elia marked this conversation as resolved.
Show resolved Hide resolved
end

def ensure_valid_payment
# Fix for https://github.com/spree/spree/issues/4117
# If confirmation of payment fails, redirect back to payment screen
if params[:state] == "confirm" && @order.payment_required? && @order.payments.valid.empty?
return unless params[:state] == "confirm"
return unless @order.payment_required?

if @order.payments.valid.empty?
flash.keep
redirect_to checkout_state_path("payment")
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<%= radio_button_tag(
"order[payments_attributes][][payment_method_id]",
method.id,
method == @order.available_payment_methods.first,
method == methods.first,
kennyadsl marked this conversation as resolved.
Show resolved Hide resolved
id: id
) %>

Expand Down
16 changes: 8 additions & 8 deletions templates/app/views/orders/_order_details.html.erb
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
<div class="order-details">
<div class="order-details__info">
<% if order.has_checkout_step?("address") %>
<%= render(
'orders/address_overview',
address: order.bill_address,
title: t('spree.billing_address')
) %>
<% end %>

<% if order.has_checkout_step?("delivery") %>
<%= render(
'orders/address_overview',
Expand All @@ -22,6 +14,14 @@
) %>
<% end %>

<% if order.has_checkout_step?("address") %>
<%= render(
'orders/address_overview',
address: order.bill_address,
title: t('spree.billing_address')
) %>
<% end %>

<% if order.has_checkout_step?("payment") %>
<%= render(
'orders/payment_info',
Expand Down
19 changes: 10 additions & 9 deletions templates/app/views/orders/_payment_info.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,21 @@
<% order.payments.valid.each do |payment| %>
<% source = payment.source %>

<% if source.is_a?(Spree::CreditCard) %>
<ul class="payment-info__info">
<ul class="payment-info__info">
<% if source.is_a?(Spree::CreditCard) %>
<li>
<% if source.last_digits %>
<%= t('spree.ending_in') %> <%= source.last_digits %>
<% end %>
</li>
<li><%= source.name %></li>
</ul>
<% elsif source.is_a?(Spree::StoreCredit) %>
<%= content_tag(:p, "#{payment.payment_method.name}:") %>
<%= content_tag(:p, payment.display_amount) %>
<% else %>
<%= content_tag(:p, payment.payment_method.name) %>
<% end %>
<% else %>
<li><%= payment.payment_method.name %></li>
<% end %>
<li>
<strong><%= payment.display_amount %></strong>
(<%= t(payment.state, scope: 'spree.payment_states') %>)
</li>
</ul>
<% end %>
</div>