Skip to content

#7241: Always add empty option for prefix and/or suffix if optional #11462

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

Merged
merged 7 commits into from
Dec 22, 2017

Conversation

avstudnitz
Copy link
Contributor

@avstudnitz avstudnitz commented Oct 14, 2017

Description

This solves part of #7241. If the prefix and/or suffix field is set to "optional" in the configuration, we automatically add a blank first option if it isn't entered in the "Dropdown Options" configuration field.

Fixed Issues (if relevant)

  1. No option to start with blank option for prefix and suffix in checkout. #7241: No option to start with blank option for prefix and suffix in checkout. (partly fixed)

Manual testing scenarios

  1. Go to Admin panel > Stores > Configuration > Customers > Customer Configuration
  2. Change "Show Prefix" and/or "Show Suffix" to "Optional"
  3. Populate "Prefix Dropdown Options" with : "Ms;Miss;Mrs;Mr;Dr;Atty;Hon;Prof;Pres;VP;MA"
  4. Populate "Suffix Dropdown Options" with : "Jr;Sr;Ph.D.;M.D.;R.N.;Ret."
  5. Click Save.
  6. Switch to the front-end, and add something to your cart.
  7. Go to the checkout page or customer registration page
  8. You'll notice that there is an empty first option for the Prefix and Suffix field.

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

* @return array|bool
*/
protected function _prepareNamePrefixSuffixOptions($options)
private function prepareNamePrefixSuffixOptions($options, $isOptional = false)
Copy link
Contributor

Choose a reason for hiding this comment

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

As part of the BC guidelines you cannot remove a protected method http://devdocs.magento.com/guides/v2.2/contributor-guide/backward-compatible-development/#public-and-protected-method-removal I would suggest that you keep the private method and the internal calls to this private method and then simply add back the protected method that simply calls the private method and mark it as deprecated.

@okorshenko okorshenko modified the milestones: October 2017, November 2017 Nov 1, 2017
@magento-engcom-team magento-engcom-team added bugfix Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release labels Nov 7, 2017
@dmanners
Copy link
Contributor

@avstudnitz do you think you will have some time to continue this PR?

@avstudnitz
Copy link
Contributor Author

Yes, I will, probably next week.

This is due to Backwards Compatibility reasons.
@avstudnitz
Copy link
Contributor Author

I re-added the protected method as you said @dmanners.

@dmanners
Copy link
Contributor

Thanks @avstudnitz I will take another look over this PR for you.

* @param bool $isOptional
* @return array|bool
*
* @deprecated See prepareNamePrefixSuffixOptions
Copy link
Contributor

Choose a reason for hiding this comment

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

You should also be able to use http://docs.phpdoc.org/references/phpdoc/tags/see.html here to link to the new method. Something like the following should work.

@see prepareNamePrefixSuffixOptions()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed, makes sense.

@@ -11,15 +11,19 @@
*/
class Nooptreq implements \Magento\Framework\Option\ArrayInterface
{
const VALUE_NO = '';
Copy link
Contributor

Choose a reason for hiding this comment

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

Sadly while putting this to the 2.2-develop branch and with this class marked as @api we cannot add any new constants. For a PR to 2.3-develop we could add these new constants. For this PR we will have to change this back.

Copy link
Contributor Author

@avstudnitz avstudnitz Dec 1, 2017

Choose a reason for hiding this comment

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

Can you explain why adding new constants is an issue? It doesn't affect backwards compatibility and only improves things, I don't see any disadavantage of that... sounds like a quite arbitrary rule to me, but perhaps it gets clearer if you explain.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @dmanners in general, you are right. But in this particular, we can accept new constants. There are some cases when new constants can break client code, but the chances a very low.
@dmanners @avstudnitz thank you for collaboration

return $this->_prepareNamePrefixSuffixOptions($this->addressHelper->getConfig('prefix_options', $store));
return $this->prepareNamePrefixSuffixOptions(
$this->addressHelper->getConfig('prefix_options', $store),
$this->addressHelper->getConfig('prefix_show', $store) == NooptreqSource::VALUE_OPTIONAL
Copy link
Contributor

Choose a reason for hiding this comment

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

Unfortunately we will need to change this since we cannot add the new constants.

return $this->_prepareNamePrefixSuffixOptions($this->addressHelper->getConfig('suffix_options', $store));
return $this->prepareNamePrefixSuffixOptions(
$this->addressHelper->getConfig('suffix_options', $store),
$this->addressHelper->getConfig('suffix_show', $store) == NooptreqSource::VALUE_OPTIONAL
Copy link
Contributor

Choose a reason for hiding this comment

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

Unfortunately we will need to change this since we cannot add the new constants.

@dmanners
Copy link
Contributor

@avstudnitz have you had anytime to look into this PR further? There is still the part about showing the empty value in the check and also the backwards compatibility changes also. Thanks

@okorshenko okorshenko removed this from the November 2017 milestone Dec 1, 2017
@okorshenko okorshenko added this to the December 2017 milestone Dec 1, 2017
@avstudnitz
Copy link
Contributor Author

@dmanners I made the requested changes. Would be glad about an explanation of the forbidden constants.
This PR doesn't cover preselecting the empty value in the checkout as I wasn't able to do that (see #7241 (comment)). It still improves UX and makes the core better even if it doesn't solve all of #7241.

@dmanners
Copy link
Contributor

dmanners commented Dec 1, 2017

@avstudnitz thank you for the update. I will see if I can get someone to help out with the front-end part, it would be nice to have both together.

With regards to the constant addition. I also agree that it is worth having in this case. Generally speaking because constants are public and the class is marked as @api the public face of the class is changing and people need to be able to rely on this. In this case I will talk with the team and see if we can get it approved.

Could you revert the revert commit and then I can ask from some approval here. Sorry for the pain.

@avstudnitz
Copy link
Contributor Author

Thanks @dmanners, I reverted the commit. I agree that removing or changing public elements of the class would be bad, but I don't see the point for newly added functions or constants because they can be ignored. Would be great if you could get approval for that.

@dmanners
Copy link
Contributor

@avstudnitz still trying to sort out that front end part for you. I will aim to get around to this PR in the next week. Sorry for the delay.

@okorshenko okorshenko removed the 2.2.x label Dec 14, 2017
…fix in checkout.

 - replace usage of empty string for optional value with space so that the knockout.js picks up the optional values
@magento-engcom-team magento-engcom-team added the Fixed in 2.2.x The issue has been fixed in 2.2 release line label Dec 22, 2017
@magento-team magento-team merged commit 3e38118 into magento:2.2-develop Dec 22, 2017
magento-team pushed a commit that referenced this pull request Dec 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report bugfix Component: Customer Fixed in 2.2.x The issue has been fixed in 2.2 release line Progress: accept Release Line: 2.2 Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants