-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Fix/imposible customize product collection #8485
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
Fix/imposible customize product collection #8485
Conversation
@@ -1,13 +1,13 @@ | |||
<?php | |||
/** | |||
* Copyright © 2013-2017 Magento, Inc. All rights reserved. | |||
* Copyright © 2016 Magento. All rights reserved. |
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.
why did you change copyright ?
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 know will put in back
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.
Fixed
<event name="catalog_block_product_list_collection"> | ||
<observer name="review" instance="Magento\Review\Observer\CatalogBlockProductCollectionBeforeToHtmlObserver" shared="false" /> | ||
<event name="catalog_product_collection_load_after"> | ||
<observer name="review" instance="Magento\Review\Observer\CatalogBlockProductCollectionLoadAfter" shared="false" /> | ||
</event> |
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.
We can't accept such fix because it will lead to general performance degradation of Product Collection load time.
Theoretically it's correctly to treat reviews as a part of Product Aggregation Root, but this behavior should be consistent with how Catalog APIs work (aka ProductRepositoryInterface::get and ProductRepositoryInterface::getList, whether these API calls fill ProductInterface with Reviews or not).
For now Review module doesn't provide Extension attribute for ProductInterface.
So, to prevent inconsistency between ProductCollection::load and ProductRepository::getList as well as not introduce performance degradation we will not add product reviews for all product collection load calls.
Proposed fix for this issue, taking into account Backward Compatibility requirements.
- Add Optional dependency (which by default is equal to NULL) to Magento\Catalog\Block\Product\ListProduct class. With name $collectionLoader
- Class $collectionLoader will have the only public method - load($collection). Which loads collection passed as input parameter.
- Method load of this class could be pluginized and logic which exists now in CatalogBlockProductCollectionBeforeToHtmlObserver, could be added as a plugin for $collectionLoader::load($productCollection)
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.
@dvynograd are there any updates?
<event name="catalog_block_product_list_collection"> | ||
<observer name="review" instance="Magento\Review\Observer\CatalogBlockProductCollectionBeforeToHtmlObserver" shared="false" /> | ||
<event name="catalog_product_collection_load_after"> | ||
<observer name="review" instance="Magento\Review\Observer\CatalogBlockProductCollectionLoadAfter" shared="false" /> | ||
</event> |
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.
@dvynograd are there any updates?
@dvynograd |
@dvynograd I am closing this PR for now due to lack of activity. |
Right now it's impossible to customize product collection on the catalog products list page.
As i can see, Magento supposed to provide this ability in \Magento\Catalog\Block\Product\ListProduct::_beforeToHtml
` $this->_eventManager->dispatch(
'catalog_block_product_list_collection',
['collection' => $this->_getProductCollection()]
);
`
but due to Magento has the observer CatalogBlockProductCollectionBeforeToHtmlObserver wich listen this event and loads collection. So it prevent to collection modifications in future customizations.
Following PR is fixing that issue.