diff --git a/app/controllers/split_checkout_controller.rb b/app/controllers/split_checkout_controller.rb index 26e6c3bcae..b7e558cb61 100644 --- a/app/controllers/split_checkout_controller.rb +++ b/app/controllers/split_checkout_controller.rb @@ -23,6 +23,8 @@ class SplitCheckoutController < ::BaseController redirect_to_step_based_on_order unless params[:step] check_step if params[:step] recalculate_tax if params[:step] == "summary" + + flash_error_when_no_shipping_method_available if available_shipping_methods.none? end def update @@ -47,6 +49,10 @@ class SplitCheckoutController < ::BaseController private + def flash_error_when_no_shipping_method_available + flash[:error] = I18n.t('split_checkout.errors.no_shipping_methods_available') + end + def clear_invalid_payments @order.payments.with_state(:invalid).delete_all end diff --git a/config/locales/en.yml b/config/locales/en.yml index 7d8a6f473f..be87cc9fab 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1903,6 +1903,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 diff --git a/spec/system/consumer/split_checkout_spec.rb b/spec/system/consumer/split_checkout_spec.rb index dbbaac2647..ab6568c2f0 100644 --- a/spec/system/consumer/split_checkout_spec.rb +++ b/spec/system/consumer/split_checkout_spec.rb @@ -142,6 +142,23 @@ describe "As a consumer, I want to checkout my order", js: true do 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"