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

20434 consider url rewrite when change product visibility attribute 2 3 #20774

Conversation

VitaliyBoyko
Copy link
Contributor

@VitaliyBoyko VitaliyBoyko commented Jan 29, 2019

Description (*)

Has been implemented observing the saving attribute via mass action, creating/deleting URL rewrites appropriately on the product visibility attribute change.
For more details see the issue (#20434).

Fixed Issues (if relevant)

  1. Product URL duplicate when changing visibility via mass action #20434: Product URL duplicate M2.2.6

Manual testing scenarios (*)

CASE 1:

Step 1. Create a product with the following URL (or any of your choice): « mon-produit-de-test » - Visible product (catalog, search)
Step 2. Create a second one with the same values but invisible individually then URL « mon-produit-de-test »
Step 3. Change visibility of the second product to visible via mass action.

The Url Key exist exception should be thrown.

CASE 2:
Step 1. Create a product with the following URL (or any of your choice): « mon-produit-de-test » - Visible product (catalog, search)
Step 2. Set visibility attribute to invisible via product grid mass action

Product URL rewrite should be removed.

CASE 3:
Step 1. Create a product with the following URL (or any of your choice): « mon-produit-de-test » - Not visible
Step 2. Set visibility attribute to visible via product grid mass action

Product URL rewrite should be created.

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)

@magento-engcom-team
Copy link
Contributor

Hi @VitaliyBoyko. 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.3-develop instance - deploy vanilla Magento instance

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

@magento-engcom-team magento-engcom-team added Component: CatalogUrlRewrite Release Line: 2.3 Partner: Atwix Pull Request is created by partner Atwix partners-contribution Pull Request is created by Magento Partner labels Jan 29, 2019
@orlangur orlangur self-assigned this Jan 29, 2019
Copy link
Contributor

@orlangur orlangur left a comment

Choose a reason for hiding this comment

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

@VitaliyBoyko,

The Url Key exist exception should be thrown.

I don't think this is correct.

Exception should only occur when there is conflicting URL Rewrite, for example, when you try to make second product visible - no earlier than that.

@VitaliyBoyko
Copy link
Contributor Author

VitaliyBoyko commented Feb 4, 2019

HI @sidolov @orlangur!
I've removed validation on the product page.
Feel free to check once again.

Thank you for the review!

@VitaliyBoyko
Copy link
Contributor Author

Hi @orlangur
Any updates regarding this one?

Copy link
Member

@sivaschenko sivaschenko left a comment

Choose a reason for hiding this comment

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

Hi @VitaliyBoyko thanks for update!

If the purpose of this observer is to throw an exception about duplicate URLs - I think it's better to keep only validation functionality here and do not persist anything.

Also, I'd move the validation implementation to a separate model and move the observer to backend area (according to best practives https://devdocs.magento.com/guides/v2.3/ext-best-practices/extension-coding/observers-bp.html)

Finally, please consider covering the introduced functionality with at least unit tests.

$visibility = $attrData[ProductInterface::VISIBILITY] ?? null;

if (!$visibility) {
return [$attrData, $productIds, $storeId];
Copy link
Member

Choose a reason for hiding this comment

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

The interface method (\Magento\Framework\Event\ObserverInterface::execute) is void. Why do you need to return this array?

@sivaschenko sivaschenko self-assigned this Feb 12, 2019
$storeId = $event->getStoreId();
$visibility = $attrData[ProductInterface::VISIBILITY] ?? null;

if (!$visibility) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@VitaliyBoyko I don't really get this logic. URL Rewrites for invisible products should still be created so that they can be made visible at any moment without conflict.

Please update description with current/changed behavior.

Copy link
Contributor Author

@VitaliyBoyko VitaliyBoyko Feb 13, 2019

Choose a reason for hiding this comment

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

Hi @orlangur
I've updated the PR description. Hope it is more comprehensive now. You may also check bugs
#10725
#20434 for additional information.
Thank you!

Copy link
Member

@sivaschenko sivaschenko left a comment

Choose a reason for hiding this comment

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

Hi @VitaliyBoyko thanks for the updates! Great test coverage! Please see my review notes, also it'll be great if you can add short method descriptions.

* @param array $productIds
* @return array
*/
protected function getProductsByIds(array $productIds): array
Copy link
Member

Choose a reason for hiding this comment

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

Please change access level to private for this method

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sivaschenko Hi. Thank you. Could you please check once again?

@magento-engcom-team
Copy link
Contributor

Hi @sivaschenko, thank you for the review.
ENGCOM-4357 has been created to process this Pull Request

Copy link
Member

@sivaschenko sivaschenko left a comment

Choose a reason for hiding this comment

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

Hi @VitaliyBoyko, there is a small issue in the pull request, please see my review comment

return;
}

$this->adaptUrlRewritesToVisibility->execute($productIds, $visibility);
Copy link
Member

@sivaschenko sivaschenko Mar 1, 2019

Choose a reason for hiding this comment

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

Please ensure $visibility is an integer: execute method expects the second argument to be an integer, but actually, it is a string in $attrData[ProductInterface::VISIBILITY]

Copy link
Contributor Author

@VitaliyBoyko VitaliyBoyko Mar 6, 2019

Choose a reason for hiding this comment

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

Hi @sivaschenko
I've fixed possible type inconsistency. Thank you!
image

@VitaliyBoyko
Copy link
Contributor Author

Hi @sivaschenko
Should I update something more here?

@magento-engcom-team
Copy link
Contributor

Hi @sivaschenko, thank you for the review.
ENGCOM-4357 has been created to process this Pull Request

@VasylShvorak
Copy link
Contributor

✔️ QA passed

@ghost
Copy link

ghost commented Mar 26, 2019

Hi @VitaliyBoyko, 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.

]
);
} elseif ($visibility !== Visibility::VISIBILITY_NOT_VISIBLE) {
$product->setVisibility($visibility);
Copy link

@eerohakio eerohakio Nov 10, 2020

Choose a reason for hiding this comment

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

Should not touch visibility here as the point of whole model is to adapt the rewrite to visibility changes and not change the visibility?

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

Successfully merging this pull request may close these issues.

8 participants