mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Implement manual shipping method selection
This commit is contained in:
@@ -27,6 +27,7 @@ module CheckoutCallbacks
|
||||
|
||||
def load_order
|
||||
@order = current_order
|
||||
@order.manual_shipping_selection = true
|
||||
|
||||
redirect_to(main_app.shop_path) && return if redirect_to_shop?
|
||||
redirect_to_cart_path && return unless valid_order_line_items?
|
||||
|
||||
@@ -13,6 +13,8 @@ require 'active_support/concern'
|
||||
module OrderShipment
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
attr_accessor :manual_shipping_selection
|
||||
|
||||
def shipment
|
||||
shipments.first
|
||||
end
|
||||
|
||||
@@ -22,17 +22,8 @@ module OrderManagement
|
||||
|
||||
shipping_rates.sort_by! { |r| r.cost || 0 }
|
||||
|
||||
unless shipping_rates.empty?
|
||||
if frontend_only
|
||||
shipping_rates.each do |rate|
|
||||
if rate.shipping_method.frontend?
|
||||
rate.selected = true
|
||||
break
|
||||
end
|
||||
end
|
||||
else
|
||||
shipping_rates.first.selected = true
|
||||
end
|
||||
unless shipping_rates.empty? || order.manual_shipping_selection
|
||||
select_first_shipping_method(shipping_rates, frontend_only)
|
||||
end
|
||||
|
||||
shipping_rates
|
||||
@@ -40,6 +31,21 @@ module OrderManagement
|
||||
|
||||
private
|
||||
|
||||
# Sets the first available shipping method to "selected".
|
||||
# Note: seems like a hangover from Spree, we can probably just remove this at some point.
|
||||
def select_first_shipping_method(shipping_rates, frontend_only)
|
||||
if frontend_only
|
||||
shipping_rates.each do |rate|
|
||||
if rate.shipping_method.frontend?
|
||||
rate.selected = true
|
||||
break
|
||||
end
|
||||
end
|
||||
else
|
||||
shipping_rates.first.selected = true
|
||||
end
|
||||
end
|
||||
|
||||
def shipping_methods(package)
|
||||
shipping_methods = package.shipping_methods
|
||||
shipping_methods.delete_if { |ship_method| !ship_method.calculator.available?(package) }
|
||||
|
||||
Reference in New Issue
Block a user