Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling update_attribute on an order saves it prematurely with invalid/blank addresses #300

Open
mike-bourgeous opened this issue Sep 29, 2015 · 1 comment

Comments

@mike-bourgeous
Copy link

Line 11 of checkout_controller_decorator.rb calls update_attribute on an order to set the order's email address, but this saves the order without running validations. This saves blank addresses (all fields nil) into the database, which can conflict with validations performed by other gems.

If possible, we would like to suggest using an alternate means of setting the email address on a guest order that does not cause the order object to be saved without validations, such as simple attribute assignment (order.email = ...).

Thanks.

if params[:order][:email] =~ Devise.email_regexp && current_order.update_attribute(:email, params[:order][:email])

@mike-bourgeous mike-bourgeous changed the title Calling update_attribute on an order prematurely saves it with invalid/blank addresses Calling update_attribute on an order saves it prematurely with invalid/blank addresses Sep 29, 2015
@prsanjay
Copy link

Hi @mike-bourgeous, I have faced this same issue in Spree 3.7 with latest Spree Auth Devise. I have solved this issue by calling reload on current_order like this :

current_order.reload.update_attribute(:email, params[:order][:email])

I believe this way it would detach associated object of address which have been initialized but not saved yet.

Any comments? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants