Skip to content

Commit

Permalink
Improve Orders::CreateUserAccount (#12292)
Browse files Browse the repository at this point in the history
  • Loading branch information
damianlegawiec authored Jan 8, 2025
1 parent a285813 commit 248e3c1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
9 changes: 1 addition & 8 deletions core/app/models/spree/order/checkout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -275,14 +275,7 @@ def create_user_record
return if user.present?
return unless signup_for_an_account?

result = Spree::Orders::CreateUserAccount.call(order: self, accepts_email_marketing: accept_marketing?)

if result.success?
self.user = result.value
save

user.send_welcome_email if user.respond_to?(:send_welcome_email)
end
Spree::Orders::CreateUserAccount.call(order: self, accepts_email_marketing: accept_marketing?)
end

def persist_user_credit_card
Expand Down
5 changes: 5 additions & 0 deletions core/app/services/spree/orders/create_user_account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ def call(order:, accepts_email_marketing: false)
assign_bill_address(order, user)

# assign newly created user to the order
# using update_columns to avoid running validations/callbacks
order.update_columns(user_id: user.id, updated_at: Time.current)
order.user = user

# send welcome email
user.send_welcome_email if user.respond_to?(:send_welcome_email)

success(user.reload)
end
Expand Down

0 comments on commit 248e3c1

Please sign in to comment.