mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-28 21:07:16 +00:00
This ensures that Spree's shipping methods take into account the ones the order's distributor uses. This reimplements what `#available_to_order_with_distributor_check?` used to do and it doesn't work with Spree 2.0.4.
34 lines
939 B
Ruby
34 lines
939 B
Ruby
# Extends Spree's Package implementation to skip shipping methods that are not
|
|
# valid for OFN.
|
|
#
|
|
# It requires the following configuration in config/initializers/spree.rb:
|
|
#
|
|
# Spree.config do |config|
|
|
# ...
|
|
# config.package_factory = Stock::Package
|
|
# end
|
|
#
|
|
module Stock
|
|
class Package < Spree::Stock::Package
|
|
# Skips the methods that are not used by the order's distributor
|
|
#
|
|
# @return [Array<Spree::ShippingMethod>]
|
|
def shipping_methods
|
|
super.delete_if do |shipping_method|
|
|
!ships_with?(order.distributor, shipping_method)
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
# Checks whether the given distributor provides the specified shipping method
|
|
#
|
|
# @param distributor [Spree::Enterprise]
|
|
# @param shipping_method [Spree::ShippingMethod]
|
|
# @return [Boolean]
|
|
def ships_with?(distributor, shipping_method)
|
|
distributor.shipping_methods.include?(shipping_method)
|
|
end
|
|
end
|
|
end
|