Update validations

This commit is contained in:
Matt-Yorkley
2021-09-06 14:22:28 +01:00
parent c3b52ef00a
commit 71412f8d4b
3 changed files with 13 additions and 13 deletions

View File

@@ -28,6 +28,7 @@ module CheckoutCallbacks
def load_order
@order = current_order
@order.manual_shipping_selection = true
@order.checkout_processing = true
redirect_to(main_app.shop_path) && return if redirect_to_shop?
redirect_to_cart_path && return unless valid_order_line_items?

View File

@@ -24,6 +24,9 @@ module Spree
go_to_state :complete
end
attr_accessor :use_billing
attr_accessor :checkout_processing
token_resource
belongs_to :user, class_name: Spree.user_class.to_s
@@ -79,8 +82,6 @@ module Spree
before_validation :associate_customer, unless: :customer_id?
before_validation :ensure_customer, unless: :customer_is_valid?
attr_accessor :use_billing
before_create :link_by_email
after_create :create_tax_charge!
@@ -137,6 +138,13 @@ module Spree
scope :by_state, lambda { |state| where(state: state) }
scope :not_state, lambda { |state| where.not(state: state) }
def initialize(*_args)
@checkout_processing = nil
@manual_shipping_selection = nil
super
end
# For compatiblity with Calculator::PriceSack
def amount
line_items.inject(0.0) { |sum, li| sum + li.amount }
@@ -625,7 +633,7 @@ module Spree
# Determine if email is required (we don't want validation errors before we hit the checkout)
def require_email
return true unless new_record? || (state == 'cart')
return true unless (new_record? || cart?) && !checkout_processing
end
def ensure_line_items_present

View File

@@ -75,7 +75,6 @@ module Spree
before_transition to: :delivery, do: :create_proposed_shipments
before_transition to: :delivery, do: :ensure_available_shipping_rates
before_transition to: :payment, do: :validate_shipping_method!
before_transition to: :payment, do: :create_tax_charge!
before_transition to: :confirmation, do: :validate_payment_method!
@@ -140,16 +139,8 @@ module Spree
private
def validate_shipping_method!
return unless Flipper.enabled?(:split_checkout)
return if shipping_method.present?
errors.add :shipping_method, I18n.t('split_checkout.errors.select_a_shipping_method')
throw :halt
end
def validate_payment_method!
return unless Flipper.enabled?(:split_checkout)
return unless checkout_processing
return if payments.any?
errors.add :payment_method, I18n.t('split_checkout.errors.select_a_payment_method')