Skip to content

Commit

Permalink
Merge pull request #10317 from mkllnk/9056-stuck-in-split-checkout
Browse files Browse the repository at this point in the history
Display checkout error messages to user for convencience
  • Loading branch information
filipefurtad0 authored Jan 25, 2023
2 parents 27e8d89 + 882d7a1 commit 7f3cf74
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 10 deletions.
17 changes: 12 additions & 5 deletions app/controllers/split_checkout_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@ def update
advance_order_state
redirect_to_step
else
flash.now[:error] ||= I18n.t('split_checkout.errors.global')

render status: :unprocessable_entity, operations: cable_car.
replace("#checkout", partial("split_checkout/checkout")).
replace("#flashes", partial("shared/flashes", locals: { flashes: flash }))
render_error
end
rescue Spree::Core::GatewayError => e
flash[:error] = I18n.t(:spree_gateway_error_flash_for_checkout, error: e.message)
Expand All @@ -50,6 +46,17 @@ def update

private

def render_error
flash.now[:error] ||= I18n.t(
'split_checkout.errors.saving_failed',
messages: @order.errors.full_messages.to_sentence
)

render status: :unprocessable_entity, operations: cable_car.
replace("#checkout", partial("split_checkout/checkout")).
replace("#flashes", partial("shared/flashes", locals: { flashes: flash }))
end

def flash_error_when_no_shipping_method_available
flash[:error] = I18n.t('split_checkout.errors.no_shipping_methods_available')
end
Expand Down
11 changes: 10 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ en:
spree/product: Product
spree/shipping_method: Shipping Method
attributes:
spree/order/ship_address:
address1: "Shipping address line 1"
address2: "Shipping address line 2"
city: "Shipping address suburb 1"
country: "Shipping address country"
phone: "Phone number"
firstname: "First name"
lastname: "Last name"
zipcode: "Shipping address postcode"
spree/user:
password: "Password"
password_confirmation: "Password confirmation"
Expand Down Expand Up @@ -1996,7 +2005,7 @@ en:
submit: Complete order
cancel: Back to Payment method
errors:
global: "Saving failed, please update the highlighted fields."
saving_failed: "Saving failed, please update the highlighted fields. %{messages}"
terms_not_accepted: Please accept Terms and Conditions
required: Field cannot be blank
invalid_number: "Please enter a valid phone number"
Expand Down
6 changes: 3 additions & 3 deletions spec/controllers/split_checkout_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
put :update, params: params

expect(response.status).to eq 422
expect(flash[:error]).to eq "Saving failed, please update the highlighted fields."
expect(flash[:error]).to match "Saving failed, please update the highlighted fields."
expect(order.reload.state).to eq "cart"
end
end
Expand Down Expand Up @@ -161,7 +161,7 @@
put :update, params: params

expect(response.status).to eq 422
expect(flash[:error]).to eq "Saving failed, please update the highlighted fields."
expect(flash[:error]).to match "Saving failed, please update the highlighted fields."
expect(order.reload.state).to eq "payment"
end
end
Expand Down Expand Up @@ -271,7 +271,7 @@
put :update, params: params

expect(response.status).to eq 422
expect(flash[:error]).to eq "Saving failed, please update the highlighted fields."
expect(flash[:error]).to match "Saving failed, please update the highlighted fields."
expect(order.reload.state).to eq "confirmation"
end
end
Expand Down
8 changes: 8 additions & 0 deletions spec/models/spree/order_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
let(:user) { build(:user, email: "[email protected]") }
let(:order) { build(:order, user: user) }

describe "#errors" do
it "provides friendly error messages" do
order.ship_address = Spree::Address.new
order.save
expect(order.errors.full_messages).to include "Shipping address line 1 can't be blank"
end
end

context "#products" do
let(:order) { create(:order_with_line_items) }

Expand Down
3 changes: 2 additions & 1 deletion spec/system/consumer/split_checkout_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "system_helper"

describe "As a consumer, I want to checkout my order", js: true do
describe "As a consumer, I want to checkout my order" do
include ShopWorkflow
include SplitCheckoutHelper
include FileHelper
Expand Down Expand Up @@ -294,6 +294,7 @@
click_button "Next - Payment method"

expect(page).to have_content "Saving failed, please update the highlighted fields."
expect(page).to have_content "Shipping address line 1 can't be blank"
expect(page).to have_content "Shipping address same as billing address?"
expect(page).to have_content "Save as default shipping address"
expect(page).to have_checked_field "Shipping address same as billing address?"
Expand Down

0 comments on commit 7f3cf74

Please sign in to comment.