-
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
delete url rewrites for all products of an attribute set when said at… #11290
delete url rewrites for all products of an attribute set when said at… #11290
Conversation
…tribute set is deleted
I'm having some trouble writing the tests for this one. I'm unable to call getAllIds on the product collection I'm passing to the AttributeSetRepository. This is how I'm creating the mock:
Would it be better to dispatch an event before the deletion, and register the necessary product ids for later use after the attribute set is deleted? This would negate the need for a product collection to be passed to the AttributeSetRepository. |
Can you describe why it need to delete URL rewrites in this case? I don't see the reason for this at all. |
The referenced issue describes this fairly well. If you attempt to create a product with the same url key as a product that has been deleted as a result of deleting the attribute set said product belonged to, you'll get an error. |
On 2.2.0 branch products are removed successfully but URL Rewrites for deleted products remain orphaned in database? |
That's correct. The 'catalog_product_delete_after' event isn't dispatched when the attribute set is deleted. Otherwise I would've observed it and deleted the corresponding URL rewrite. |
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.
Probably current implementation is workable but it is not appropriate.
Please change implementation in such a way that it is placed in CatalogUrlRewrite
module and URL Rewrites removal is triggered by corresponding products removal and not attribute set removal. Most likely it will be plugin-interceptor for an appropriate resource model or repository.
After all changes are made and all builds are green, please squash changes into a single commit.
|
||
try | ||
{ | ||
$connection->delete('url_rewrite', ['entity_type = ?' => 'product', 'entity_id IN (?)' => $ids]); |
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.
\Magento\UrlRewrite\Model\UrlPersistInterface::deleteByData
must be used instead.
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.
Yeah, I was looking for a more elegant way of deleting the entries.
try { | ||
$this->attributeSetResource->delete($attributeSet); | ||
$this->eventManager->dispatch('attribute_set_delete_after', ['products' => $productIds]); |
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.
Catalog
must not be referred in Eav
module. New events must not be introduced when it's enough extension points to create a plugin-interceptor.
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.
You're right! I'll get on this later today 👍
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.
I don't think that the removal of an attribute set calls any delete function on a per product level, at least as far as I can tell.
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.
Products are dropped due to foreign keys? Maybe similar constraints should be added for product URL Rewrites?
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.
That isn't possible since there are other url rewrites in the table that relate to different entity types. Or am I just not seeing something that's super obvious?
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.
You are right https://stackoverflow.com/a/28322144/8640867 :) That's our case, needs to be handled on application side, please implement as an interceptor attached to attribute set entity removal.
I've created a new pull request for this #11391 |
…tribute set is deleted
Description
This PR adds an observer and dispatches an event when an attribute set is deleted. The observer then deletes any url rewrites for products that belonged to the deleted attribute set.
Fixed Issues (if relevant)
Manual testing scenarios