mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Make ship method display on back_end work correcly by making checkout ignore ship methods configured for backoffice only
Adding both unit and feature tests as this is important enough for that
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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}, ...}
|
||||
|
||||
@@ -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) }
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user