From 9dd3a8bc5ac0987a7f7f9a864796103b25a37714 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Mon, 8 Aug 2022 16:59:08 +0200 Subject: [PATCH 1/2] Store all distributors shipping methods to one array --- spec/system/consumer/split_checkout_spec.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/spec/system/consumer/split_checkout_spec.rb b/spec/system/consumer/split_checkout_spec.rb index 5488575bcd..dbbaac2647 100644 --- a/spec/system/consumer/split_checkout_spec.rb +++ b/spec/system/consumer/split_checkout_spec.rb @@ -60,6 +60,9 @@ describe "As a consumer, I want to checkout my order", js: true do let(:shipping_backoffice_only) { create(:shipping_method, require_ship_address: true, name: "Shipping Backoffice Only", display_on: "back_end") } + let(:shipping_methods) { + [free_shipping_with_required_address, free_shipping, shipping_with_fee, free_shipping_without_required_address, tagged_shipping] + } before do allow(Flipper).to receive(:enabled?).with(:split_checkout).and_return(true) @@ -68,7 +71,7 @@ describe "As a consumer, I want to checkout my order", js: true do add_enterprise_fee enterprise_fee set_order order - distributor.shipping_methods.push(free_shipping_with_required_address, free_shipping, shipping_with_fee, free_shipping_without_required_address, tagged_shipping) + distributor.shipping_methods.push(shipping_methods) end context "guest checkout when distributor doesn't allow guest orders" do From 86cb86e8b55419e1f6e8e3bb0794aefd571a8ca7 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Mon, 8 Aug 2022 16:59:37 +0200 Subject: [PATCH 2/2] Add a flash error where no available shipping methods to the customer + update specs as well --- app/controllers/split_checkout_controller.rb | 6 ++++++ config/locales/en.yml | 1 + spec/system/consumer/split_checkout_spec.rb | 17 +++++++++++++++++ 3 files changed, 24 insertions(+) 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"