diff --git a/app/helpers/enterprises_helper.rb b/app/helpers/enterprises_helper.rb index 64d78e7e93..eaaa4c3e86 100644 --- a/app/helpers/enterprises_helper.rb +++ b/app/helpers/enterprises_helper.rb @@ -14,7 +14,7 @@ module EnterprisesHelper def available_shipping_methods return [] if current_distributor.blank? - shipping_methods = current_distributor.shipping_methods + shipping_methods = current_distributor.shipping_methods.display_on_checkout.to_a applicator = OpenFoodNetwork::TagRuleApplicator.new(current_distributor, "FilterShippingMethods", current_customer.andand.tag_list) applicator.filter!(shipping_methods) diff --git a/app/models/spree/shipping_method_decorator.rb b/app/models/spree/shipping_method_decorator.rb index ba7836899d..0057f8507b 100644 --- a/app/models/spree/shipping_method_decorator.rb +++ b/app/models/spree/shipping_method_decorator.rb @@ -30,6 +30,7 @@ Spree::ShippingMethod.class_eval do } scope :by_name, -> { order('spree_shipping_methods.name ASC') } + scope :display_on_checkout, -> { where("display_on is null OR display_on = ''") } # Return the services (pickup, delivery) that different distributors provide, in the format: # {distributor_id => {pickup: true, delivery: false}, ...} diff --git a/spec/features/consumer/shopping/checkout_spec.rb b/spec/features/consumer/shopping/checkout_spec.rb index 61a89bc6ad..a6135bf88c 100644 --- a/spec/features/consumer/shopping/checkout_spec.rb +++ b/spec/features/consumer/shopping/checkout_spec.rb @@ -229,6 +229,15 @@ feature "As a consumer I want to check out my cart", js: true do end end + it "filters out 'Back office only' shipping methods" do + expect(page).to have_content shipping_with_fee.name + shipping_with_fee.update_attribute :display_on, 'back_end' # Back office only + + visit checkout_path + checkout_as_guest + expect(page).not_to have_content shipping_with_fee.name + end + context "using FilterShippingMethods" do let(:user) { create(:user) } let(:customer) { create(:customer, user: user, enterprise: distributor) } diff --git a/spec/helpers/enterprises_helper_spec.rb b/spec/helpers/enterprises_helper_spec.rb index 6bd6a46dd4..2ad922a259 100644 --- a/spec/helpers/enterprises_helper_spec.rb +++ b/spec/helpers/enterprises_helper_spec.rb @@ -28,6 +28,14 @@ describe EnterprisesHelper, type: :helper do expect(helper.available_shipping_methods).to_not include other_distributor_shipping_method expect(helper.available_shipping_methods).to include distributor_shipping_method end + + it "does not return 'back office only' shipping method" do + backoffice_only_shipping_method = create(:shipping_method, require_ship_address: false, distributors: [distributor], display_on: 'back_end') + + expect(helper.available_shipping_methods).to_not include backoffice_only_shipping_method + expect(helper.available_shipping_methods).to_not include other_distributor_shipping_method + expect(helper.available_shipping_methods).to include distributor_shipping_method + end end context "when FilterShippingMethods tag rules are in effect" do