Skip to content

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

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

use Magento\Framework\Event\ObserverInterface;

class CatalogBlockProductCollectionBeforeToHtmlObserver implements ObserverInterface
class CatalogBlockProductCollectionLoadAfter implements ObserverInterface
{
/**
* Review model
Expand Down Expand Up @@ -35,7 +35,6 @@ public function execute(\Magento\Framework\Event\Observer $observer)
{
$productCollection = $observer->getEvent()->getCollection();
if ($productCollection instanceof \Magento\Framework\Data\Collection) {
$productCollection->load();
$this->_reviewFactory->create()->appendSummary($productCollection);
}

Expand Down
4 changes: 2 additions & 2 deletions app/code/Magento/Review/etc/frontend/events.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<event name="tag_tag_product_collection_load_after">
<observer name="review" instance="Magento\Review\Observer\TagProductCollectionLoadAfterObserver" shared="false" />
</event>
<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>
Copy link
Contributor

@maghamed maghamed Feb 13, 2017

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.

  1. Add Optional dependency (which by default is equal to NULL) to Magento\Catalog\Block\Product\ListProduct class. With name $collectionLoader
  2. Class $collectionLoader will have the only public method - load($collection). Which loads collection passed as input parameter.
  3. 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)

Copy link
Contributor

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?

</config>