Skip to content

Commit

Permalink
Add a flash error where no available shipping methods to the customer
Browse files Browse the repository at this point in the history
+ update specs as well
  • Loading branch information
jibees committed Aug 8, 2022
1 parent d8f5223 commit cf0bd39
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/controllers/split_checkout_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ class SplitCheckoutController < ::BaseController

def edit
redirect_to_step_based_on_order unless params[:step]

return if available_shipping_methods.any?

flash[:error] = I18n.t('split_checkout.errors.no_shipping_methods_available')
end

def update
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1898,6 +1898,7 @@ en:
invalid_email: "Please enter a valid email address"
select_a_shipping_method: Select a shipping method
select_a_payment_method: Select a payment method
no_shipping_methods_available: Checkout is not possible due to absence of shipping options. Please contact the shop owner.
order_paid: PAID
order_not_paid: NOT PAID
order_total: Total order
Expand Down
17 changes: 17 additions & 0 deletions spec/system/consumer/split_checkout_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,23 @@
expect_to_be_on_first_step
end

context "when no shipping methods are available" do
before do
shipping_methods.each { |sm| sm.update(tag_list: "hidden") }
end

it "should display an error message" do
create(:filter_shipping_methods_tag_rule,
enterprise: distributor,
is_default: true,
preferred_shipping_method_tags: "hidden",
preferred_matched_shipping_methods_visibility: 'hidden')

visit checkout_path
expect(page).to have_content "Checkout is not possible due to absence of shipping options. Please contact the shop owner."
end
end

it "should display error when fields are empty" do
click_on "Checkout as guest"
click_button "Next - Payment method"
Expand Down

0 comments on commit cf0bd39

Please sign in to comment.