Skip to content

Refactor: Fix lack of customizability of the protected variable linkN… #21230

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

Closed
wants to merge 1 commit into from

Conversation

amenk
Copy link
Contributor

@amenk amenk commented Feb 14, 2019

Description (*)

Currently it is not possible to add own custom links to the import

Fixed Issues (if relevant)

See magepal/magento2-link-product#2 (comment)

Manual testing scenarios (*)

No need to test, it's a trivial change by adding an extension point where no was before

Contribution checklist (*)

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

@magento-engcom-team
Copy link
Contributor

Hi @amenk. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento-engcom-team give me test instance - deploy test instance based on PR changes
  • @magento-engcom-team give me 2.2-develop instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Assistant documentation

@Toffelcore
Copy link

Looks good

@orlangur orlangur self-assigned this Feb 14, 2019
*
* @return array
*/
public function getLinkNameToId()
Copy link
Contributor

Choose a reason for hiding this comment

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

Breaking class encapsulation is not a good idea. As this class is pretty legacy I believe the recommended way would be to extend it.

Another possible way is to inject such data via constructor but I'm not sure it makes sense to do such refactoring.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@orlangur thanks for looking into this.

I see breaking class encapsulation as a small problem, because we only add a getter, not a setter.

Extending and rewriting the class would not work well with multiple custom modules (in my case the MagePal module needs to put in the link name; another module we use - FireBear Import Export - already rewrites the class)

Constructor injection might work, but as you say the class seems legacy and I am not sure how to do that. Feel free to propose an alternative way.

Copy link
Contributor

Choose a reason for hiding this comment

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

Another issue with getter is that plugins will be called each time it is called. So, adding such getter is not a proper extension point.

I was suggesting adding a parameter so that links can be specified later via di.xml. This wouldn't improve situation a lot actually.

Instead of this, please move links manipulation logic into a new class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was just following what is done in the class already -- there is also public getAttrSetIdToName which works the same.

But I get the argument that it is not a perfect extension point -- but at least it's a lightweight one.

So shall I refactor the whole links manipulation into a new class now? I was just hoping to make the situation a bit better, and am not sure if I am able to invest lots of time here.

What do you think about merging this one and put a refactoring backlog entry for 2.3.x ? I don't think it makes much sense to do such refactoring in 2.2.x ? Would that be possible?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe the larger scale refactoring can be something I could tackle at the MageFest hackathon :-)

Copy link
Contributor

Choose a reason for hiding this comment

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

@amenk I'll consult with other maintainers in Slack whether such getters addition is something we can live with.

March 5-8th, 2019, not too much time to wait 👍

So shall I refactor the whole links manipulation into a new class now?

Yes, I was thinking of this, most part is in _saveLinks but maybe there are some others.

I don't think it makes much sense to do such refactoring in 2.2.x ? Would that be possible?

Sorry, I missed this PR is targeting 2.2. Currently all changes must be delivered to 2.3.x first, then in case of backward-incompatible refactoring of 2.3 we may think of trade-offs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not easy to contribute :-D

*
* @return array
*/
public function getLinkNameToId()
Copy link
Contributor

Choose a reason for hiding this comment

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

Another issue with getter is that plugins will be called each time it is called. So, adding such getter is not a proper extension point.

I was suggesting adding a parameter so that links can be specified later via di.xml. This wouldn't improve situation a lot actually.

Instead of this, please move links manipulation logic into a new class.

@amenk
Copy link
Contributor Author

amenk commented Mar 8, 2019

I am closing this one and will make a new PR against 2.3-develop

@amenk amenk closed this Mar 8, 2019
@ghost
Copy link

ghost commented Mar 8, 2019

Hi @amenk, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

@amenk
Copy link
Contributor Author

amenk commented Mar 8, 2019

@orlangur As for the refactoring --- will we bump the major module version or do I have to make everything backwards compatible ?

@orlangur
Copy link
Contributor

orlangur commented Mar 8, 2019

@amenk I believe it's bumped automatically during release.

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

Successfully merging this pull request may close these issues.

4 participants