diff --git a/engines/order_management/app/services/order_management/stock/package.rb b/engines/order_management/app/services/order_management/stock/package.rb index d6ebbb35c1..130eabec2e 100644 --- a/engines/order_management/app/services/order_management/stock/package.rb +++ b/engines/order_management/app/services/order_management/stock/package.rb @@ -75,28 +75,13 @@ module OrderManagement end end - def currency - # 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] - 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] def shipping_methods - available_shipping_methods = shipping_categories.flat_map(&:shipping_methods).uniq.to_a + return [] unless order.distributor.present? - 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 +109,6 @@ module OrderManagement shipment end - - private - - # Checks whether the given distributor provides the specified shipping method - # - # @param shipping_methods [Array] - # @param shipping_method [Spree::ShippingMethod] - # @return [Boolean] - def ships_with?(shipping_methods, shipping_method) - shipping_methods.include?(shipping_method) - end end end end diff --git a/engines/order_management/spec/services/order_management/stock/package_spec.rb b/engines/order_management/spec/services/order_management/stock/package_spec.rb index 1a7fbd017a..55d1e9a37f 100644 --- a/engines/order_management/spec/services/order_management/stock/package_spec.rb +++ b/engines/order_management/spec/services/order_management/stock/package_spec.rb @@ -158,20 +158,23 @@ module OrderManagement let(:shipping_method1) { create(:shipping_method, distributors: [enterprise]) } let(:shipping_method2) { create(:shipping_method, distributors: [other_enterprise]) } + let!(:shipping_method3) { + create(:shipping_method, distributors: [enterprise], deleted_at: Time.zone.now) + } - describe '#shipping_methods' do - it 'does not return shipping methods not used by the package\'s order distributor' do + describe "#shipping_methods" do + it "does not return shipping methods not used by the package's order distributor" do expect(package.shipping_methods).to eq [shipping_method1] 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") + it "does not return soft-deleted shipping methods" do + expect(package.shipping_methods).to_not include shipping_method3 + end - expect(package.shipping_categories).to eq [shipping_method1.shipping_categories.first, - other_shipping_category] + it "returns an empty array if distributor is nil" do + allow(order).to receive(:distributor) { nil } + + expect(package.shipping_methods).to eq [] end end end