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

Fix #9924, prefill prefix and suffix in checkout shipping address #9925

Merged
merged 5 commits into from
Jun 15, 2017
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 40 additions & 9 deletions app/code/Magento/Checkout/Block/Checkout/AttributeMerger.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,20 +316,19 @@ protected function getMultilineFieldConfig($attributeCode, array $attributeConfi
protected function getDefaultValue($attributeCode)
{
switch ($attributeCode) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't it be better if you return null straight away, at the beginning of the method in case where there is no customer? I guess it should reduce complexity that way, since you would not have to check for customer every time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hahaha, brilliant... I guess programming for 12 hours straight is not paying off ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correction, $this->directoryHelper->getDefaultCountry() doesn't need a customer. Let me draft up a commit.

case 'prefix':
return $this->getDefaultPrefix();
case 'firstname':
if ($this->getCustomer()) {
return $this->getCustomer()->getFirstname();
}
break;
return $this->getDefaultFirstname();
case 'lastname':
if ($this->getCustomer()) {
return $this->getCustomer()->getLastname();
}
break;
return $this->getDefaultLastname();
case 'suffix':
return $this->getDefaultSuffix();
case 'country_id':
return $this->directoryHelper->getDefaultCountry();
default:
return null;
}
return null;
}

/**
Expand Down Expand Up @@ -388,4 +387,36 @@ protected function orderCountryOptions(array $countryOptions)
}
return array_merge($headOptions, $tailOptions);
}

/**
* @return null|string
*/
protected function getDefaultPrefix()
Copy link
Contributor

Choose a reason for hiding this comment

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

Magento does not encourage usage of protected methods.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good to know. Because of plugins right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Because we do not encourage inheritance-based API. So composition in favor of inheritance. It's easier to maintain and reuse.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah yes of course. That makes sense.

{
return $this->getCustomer() ? $this->getCustomer()->getPrefix() : null;
}

/**
* @return null|string
*/
protected function getDefaultFirstname()
{
return $this->getCustomer() ? $this->getCustomer()->getFirstname() : null;
}

/**
* @return null|string
*/
protected function getDefaultLastname()
{
return $this->getCustomer() ? $this->getCustomer()->getLastname() : null;
}

/**
* @return null|string
*/
protected function getDefaultSuffix()
{
return $this->getCustomer() ? $this->getCustomer()->getSuffix() : null;
}
}