Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make "backoffice only" ship methods work and remove option "frontoffice only" #5392

Merged
merged 4 commits into from
May 21, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why to_a?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

otherwise it's a relation and it was not working with it.
I cant remember exactly the error but I think it's related to some magic inside TagRuleApplicator (called just after this).


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