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

Add name to Spree::Address #3458

Merged
merged 3 commits into from
Jan 20, 2020

Conversation

filippoliverani
Copy link
Contributor

@filippoliverani filippoliverani commented Dec 16, 2019

Description
This PR proposes a first step to solve #3234 .

The main idea is to add a new name attribute to Spree::Address and to deprecate firstname, lastname and full_name usage while keeping full backward compatibility.

This PR adds a virtual attribute name that replaces full_name and favors reading form it when accessing Address data. It uses a Spree::Address::Name value object to handle name parsing during deprecation period.

Checklist:

  • I have followed Pull Request guidelines
  • I have added a detailed description into each commit message
  • I have added tests to cover this change (if needed)

@filippoliverani filippoliverani changed the title Add name to address #1 Add name to Spree::Address Dec 16, 2019
@filippoliverani filippoliverani marked this pull request as ready for review December 16, 2019 10:22
Copy link
Member

@kennyadsl kennyadsl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Filippo. I left some comments, let me know your thoughts.

Also, I've found this code into ActiveMerchant. Curious how they do the opposite to split the full name into different parts, do you prefer this way for a specific reason?

Still not sure about the Rubocop fixes merged in the PR. I'd love to keep them but these PRs are very critical and I'd focus their content on the changes only.

core/app/models/spree/address.rb Outdated Show resolved Hide resolved
core/app/models/spree/address.rb Outdated Show resolved Hide resolved
core/app/models/spree/address.rb Outdated Show resolved Hide resolved
core/app/models/spree/address.rb Show resolved Hide resolved
core/app/models/spree/address.rb Outdated Show resolved Hide resolved
core/spec/lib/spree/name_spec.rb Outdated Show resolved Hide resolved
@filippoliverani
Copy link
Contributor Author

@kennyadsl Thanks for the feedback!

Also, I've found this code into ActiveMerchant. Curious how they do the opposite to split the full name into different parts, do you prefer this way for a specific reason?

I just extracted the code used in Spree::CreditCard#first_name to avoid reinventing the wheel, no preferences about one style or the other.

Still not sure about the Rubocop fixes merged in the PR. I'd love to keep them but these PRs are very critical and I'd focus their content on the changes only.

They seemed small enough to me but I can keep only the ones enforced by Hound to reduce changes.

core/lib/spree/name.rb Outdated Show resolved Hide resolved
Copy link
Member

@spaghetticode spaghetticode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@filippoliverani thank you for working on this, I left some minor comments, I think this is a great start!

core/app/models/spree/address.rb Outdated Show resolved Hide resolved
core/lib/spree/name.rb Outdated Show resolved Hide resolved
core/app/models/spree/order.rb Outdated Show resolved Hide resolved
@filippoliverani
Copy link
Contributor Author

@spaghetticode Thank you for your feedback!

Copy link
Member

@spaghetticode spaghetticode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@filippoliverani thank you! Still one small nitpick, otherwise looks good to me 👍

backend/app/views/spree/admin/shared/_address.html.erb Outdated Show resolved Hide resolved
Copy link
Member

@tvdeyen tvdeyen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much. This is a great change and very good work on the backwards compatibility 👏

I do think we should deprecate first_name and last_name as well.

Again, awesome work 🎉

core/app/models/spree/address/name.rb Outdated Show resolved Hide resolved
@@ -163,7 +163,7 @@ def has_payment_profile?
# the object to ActiveMerchant.
# @return [String] the first name on this credit card
def first_name
name.to_s.split(/[[:space:]]/, 2)[0]
Spree::Address::Name.new(name).first_name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should deprecate this method and move the logic into solidus_gateway, respectively into the payment method extensions. Having ActiveMerchant related logic in core seems odd.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could be part of another PR since there are also other (unrelated) methods that we should deprecate under the same motivation. I'd say to keep this as it's minimum since it's already an important/critical change.

@@ -172,7 +172,7 @@ def first_name
# the object to ActiveMerchant.
# @return [String] the last name on this credit card
def last_name
name.to_s.split(/[[:space:]]/, 2)[1]
Spree::Address::Name.new(name).last_name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto deprecate this method.

Copy link
Contributor Author

@filippoliverani filippoliverani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much. This is a great change and very good work on the backwards compatibility 👏

I do think we should deprecate first_name and last_name as well.

Again, awesome work 🎉

Thank you @tvdeyen 🙏

The PR does not include deprecation yet to keep the amount of code changed at minimum. I was thinking to split the whole work into 4-5 PRs to ease the review work, this is a proposed roadmap #3234 (comment).

This is the first non-destructive step to have a unified name attribute.
Spree::Name class is needed to perfortm the conversions that will ease
the transition to name field.
The logic for splitting a name and concatenating name components should
be centralized in a single class.
Copy link
Member

@kennyadsl kennyadsl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @filippoliverani. This is awesome!

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

Successfully merging this pull request may close these issues.

6 participants