Refactor Stock::Package#shipping_methods

This commit is contained in:
Matt-Yorkley
2021-04-29 18:19:53 +01:00
parent c3c396eaea
commit 3897c3af68
2 changed files with 2 additions and 36 deletions

View File

@@ -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

View File

@@ -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