mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Refactor Stock::Package#shipping_methods
This commit is contained in:
@@ -79,24 +79,11 @@ module OrderManagement
|
||||
# TODO calculate from first variant?
|
||||
end
|
||||
|
||||
# Returns all existing shipping categories.
|
||||
# It disables the matching of product shipping category with shipping method's category
|
||||
# It allows checkout of products with categories that are not the ship method's categories
|
||||
#
|
||||
# @return [Array<Spree::ShippingCategory>]
|
||||
def shipping_categories
|
||||
Spree::ShippingCategory.all
|
||||
end
|
||||
|
||||
# Skips the methods that are not used by the order's distributor
|
||||
# Returns the shipping methods that are enabled by the order's distributor
|
||||
#
|
||||
# @return [Array<Spree::ShippingMethod>]
|
||||
def shipping_methods
|
||||
available_shipping_methods = shipping_categories.flat_map(&:shipping_methods).uniq.to_a
|
||||
|
||||
available_shipping_methods.keep_if do |shipping_method|
|
||||
ships_with?(order.distributor.shipping_methods.to_a, shipping_method)
|
||||
end
|
||||
order.distributor.shipping_methods.uniq.to_a
|
||||
end
|
||||
|
||||
def inspect
|
||||
@@ -124,17 +111,6 @@ module OrderManagement
|
||||
|
||||
shipment
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Checks whether the given distributor provides the specified shipping method
|
||||
#
|
||||
# @param shipping_methods [Array<Spree::ShippingMethod>]
|
||||
# @param shipping_method [Spree::ShippingMethod]
|
||||
# @return [Boolean]
|
||||
def ships_with?(shipping_methods, shipping_method)
|
||||
shipping_methods.include?(shipping_method)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -171,16 +171,6 @@ module OrderManagement
|
||||
expect(package.shipping_methods).to_not include shipping_method3
|
||||
end
|
||||
end
|
||||
|
||||
describe '#shipping_categories' do
|
||||
it "returns ship categories that are not the ship categories of the order's products" do
|
||||
package
|
||||
other_shipping_category = Spree::ShippingCategory.create(name: "Custom")
|
||||
|
||||
expect(package.shipping_categories).to eq [shipping_method1.shipping_categories.first,
|
||||
other_shipping_category]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user