Skip to content

Commit

Permalink
Make ship method display on back_end work correcly by making checkout…
Browse files Browse the repository at this point in the history
… ignore ship methods configured for backoffice only

Adding both unit and feature tests as this is important enough for that
  • Loading branch information
luisramos0 committed May 8, 2020
1 parent 34d8b19 commit 0a6bd14
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/helpers/enterprises_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def current_customer
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)
Expand Down
1 change: 1 addition & 0 deletions app/models/spree/shipping_method_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
}

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}, ...}
Expand Down
9 changes: 9 additions & 0 deletions spec/features/consumer/shopping/checkout_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,15 @@
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) }
Expand Down
8 changes: 8 additions & 0 deletions spec/helpers/enterprises_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@
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
Expand Down

0 comments on commit 0a6bd14

Please sign in to comment.