-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Allow to specify if billing address is required for orders #3658
Conversation
core/app/models/spree/order.rb
Outdated
@@ -562,6 +562,13 @@ def ensure_shipping_address | |||
end | |||
end | |||
|
|||
def ensure_billing_address | |||
return if bill_address && bill_address.valid? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/SafeNavigation: Use safe navigation (&.) instead of checking if an object exists before calling the method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I fix this? it is barely used in the project
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's worth fixing as it's the preferred way to do that now that we don't need to support any old Rubies from before that syntax was added.
All payment methods don't necessarily require a billing address. I work with some stores that don't even track billing addresses, so this definitely qualifies as a breaking change that would need to be controlled via configuration. |
Right, giving a second thought, it might be worth delegating this decision to the payment methods, if at least one of them require the address, then make it required before payment step what about something like
Then each payment method is responsible for it |
@softr8 I like the idea on a theoretical level, but I think that may cause problems with stores doing weird stuff (e.g. offering different payment methods depending on some conditions on the order, which may or may not change after the address step). I'd feel more comfortable with having an app-level configuration toggle. If you want to make it super-flexible, you could then also add a method to the order class: def billing_address_required?
Spree::Config.billing_address_required
end That way, it's easy to override the behavior per-order, if needed. @jarednorman what do you think? |
That was exactly my point, get the available payment methods for the order and delegate the validation to them, will try another attempt to see how it looks |
7f8ab99
to
60524b6
Compare
60524b6
to
eb5e93c
Compare
I think @aldesantis's suggestion was to avoid adding the payment method check to core here, but instead have that method delegate to the configuration option so that if you want finer grained control (like if you want to delegate to the payment methods like you have) you can override I like that solution. |
Correct: I think we should avoid doing anything with the payment methods on the order, because it seems too brittle and prone to breaking as a new behavior to introduce in existing stores. Instead, we can use global flag and allow people to override it on |
Alright! I guess I tried to port our implementation for everyone but it is not that common, we have payment methods per zone (pay on delivery for example) and it does not require billing address. |
eb5e93c
to
e43f1b1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'm happy with this.
e43f1b1
to
e115647
Compare
It fills required information using defined relationships and it makes it easier to read when data is removed for scenarios
Spree::Config.billing_address_required now can be used to force billing address to be required and also gives the ability to stores to add custom logic
Can be controlled via Spree::Config.billing_address_required config flag globally or can be overriden at the order model e.g. it can be disabled by default but required if at least one payment method requires billing address
e115647
to
3cab199
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
With the implementation of default bill address, we have found that some legacy users are going thought the checkout process without billing address failing at the confirm step, this change makes sure that billing address is present.
I am not totally sure if this should be controlled via config variable but I'm assuming all payment methods require billing address
Checklist: