Implement manual shipping method selection

This commit is contained in:
Matt-Yorkley
2021-09-01 11:28:55 +01:00
parent ebe2923512
commit 3dd8ed85b4
3 changed files with 20 additions and 11 deletions

View File

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

View File

@@ -13,6 +13,8 @@ require 'active_support/concern'
module OrderShipment
extend ActiveSupport::Concern
attr_accessor :manual_shipping_selection
def shipment
shipments.first
end

View File

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