mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-01 02:03:22 +00:00
Add order and current_user to checkout_form_data_adapter where they are required
Also re-add order.state condition to update_result: in some tests, the order state is complete but no completion data (completed?) is present
This commit is contained in:
@@ -40,7 +40,7 @@ class CheckoutController < Spree::StoreController
|
||||
end
|
||||
|
||||
def update
|
||||
params_adapter = CheckoutFormDataAdapter.new(params)
|
||||
params_adapter = CheckoutFormDataAdapter.new(params, @order, spree_current_user)
|
||||
return update_failed unless @order.update_attributes(params_adapter.order_params)
|
||||
|
||||
fire_event('spree.checkout.update')
|
||||
@@ -196,7 +196,7 @@ class CheckoutController < Spree::StoreController
|
||||
end
|
||||
|
||||
def update_result
|
||||
if @order.completed?
|
||||
if @order.state == "complete" || @order.completed?
|
||||
update_succeeded
|
||||
else
|
||||
update_failed
|
||||
|
||||
@@ -4,8 +4,10 @@
|
||||
class CheckoutFormDataAdapter
|
||||
attr_reader :shipping_method_id
|
||||
|
||||
def initialize(params)
|
||||
def initialize(params, order, current_user)
|
||||
@params = params
|
||||
@order = order
|
||||
@current_user = current_user
|
||||
|
||||
move_payment_source_to_payment_attributes!
|
||||
|
||||
@@ -55,7 +57,7 @@ class CheckoutFormDataAdapter
|
||||
|
||||
def move_to_payment_attributes(existing_card_id)
|
||||
credit_card = Spree::CreditCard.find(existing_card_id)
|
||||
if credit_card.try(:user_id).blank? || credit_card.user_id != spree_current_user.try(:id)
|
||||
if credit_card.try(:user_id).blank? || credit_card.user_id != @current_user.try(:id)
|
||||
raise Spree::Core::GatewayError, I18n.t(:invalid_credit_card)
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user