-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
20434 consider url rewrite when change product visibility attribute 2 3 #20774
Conversation
…roduct attribute visibility via mass action
Hi @VitaliyBoyko. Thank you for your contribution
For more details, please, review the Magento Contributor Assistant documentation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
…consider-url-rewrite-when-change-product-visibility-attribute-2-3
Hi @orlangur |
There was a problem hiding this 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]; |
There was a problem hiding this comment.
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?
$storeId = $event->getStoreId(); | ||
$visibility = $attrData[ProductInterface::VISIBILITY] ?? null; | ||
|
||
if (!$visibility) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this 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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
Hi @sivaschenko, thank you for the review. |
There was a problem hiding this 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); |
There was a problem hiding this comment.
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]
There was a problem hiding this comment.
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!
Hi @sivaschenko |
Hi @sivaschenko, thank you for the review. |
✔️ QA passed |
Hi @VitaliyBoyko, thank you for your contribution! |
] | ||
); | ||
} elseif ($visibility !== Visibility::VISIBILITY_NOT_VISIBLE) { | ||
$product->setVisibility($visibility); |
There was a problem hiding this comment.
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?
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)
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 (*)