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

Conversation

dvynograd
Copy link
Contributor

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()]
);

    $this->_getProductCollection()->load();

`

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.

@maghamed maghamed self-requested a review February 9, 2017 12:50
@maghamed maghamed self-assigned this Feb 9, 2017
@@ -1,13 +1,13 @@
<?php
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* Copyright © 2016 Magento. All rights reserved.
Copy link
Contributor

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 ?

Copy link
Contributor Author

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

Copy link
Contributor Author

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>
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?

<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

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?

@okorshenko okorshenko added this to the March 2017 milestone Mar 1, 2017
@okorshenko okorshenko modified the milestones: March 2017, April 2017 Apr 2, 2017
@okorshenko okorshenko modified the milestones: April 2017, May 2017 May 9, 2017
@okorshenko okorshenko modified the milestones: May 2017, June 2017 Jun 1, 2017
@ishakhsuvarov
Copy link
Contributor

@dvynograd
Would you like to continue with this PR? If so, please see review comments.
Thank you

@ishakhsuvarov ishakhsuvarov self-assigned this Jun 8, 2017
@ishakhsuvarov
Copy link
Contributor

@dvynograd I am closing this PR for now due to lack of activity.
Please check the code review comments, update with the latest develop and reopen this ticket if you wish to continue.
Thanks!

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

Successfully merging this pull request may close these issues.

4 participants