Skip to content

Fix/imposible customize product collection #12770

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

@dvynograd dvynograd commented Dec 15, 2017

Reopen #8485
original description:

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 to this event and loads collection. So it prevents to collection modifications in future customizations.

Following PR is fixing that issue.

For more details see the original thread. #8485 (comment)

@orlangur orlangur added this to the December 2017 milestone Dec 18, 2017
@okorshenko okorshenko modified the milestones: December 2017, January 2018 Jan 8, 2018
/**
* @var CollectionLoader
*/
protected $collectionLoader;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New class parameter should be private as we are trying to avoid using protected.

@@ -82,12 +89,14 @@ public function __construct(
Resolver $layerResolver,
CategoryRepositoryInterface $categoryRepository,
Data $urlHelper,
CollectionLoader $collectionLoader,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New injections should come last in the construct and should also default to null so as to not break backwards compatibility. More information and examples can be found at http://devdocs.magento.com/guides/v2.2/contributor-guide/backward-compatible-development/index.html#adding-a-constructor-parameter

@@ -38,6 +40,7 @@ public function __construct(
\Magento\Catalog\Model\Layer\Resolver $layerResolver,
CategoryRepositoryInterface $categoryRepository,
\Magento\Framework\Url\Helper\Data $urlHelper,
CollectionLoader $collectionLoader,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New injections should come last in the construct and should also default to null so as to not break backwards compatibility. More information and examples can be found at http://devdocs.magento.com/guides/v2.2/contributor-guide/backward-compatible-development/index.html#adding-a-constructor-parameter

@@ -51,6 +54,7 @@ public function __construct(
$layerResolver,
$categoryRepository,
$urlHelper,
$collectionLoader,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New injections should come last in the construct and should also default to null so as to not break backwards compatibility. More information and examples can be found at http://devdocs.magento.com/guides/v2.2/contributor-guide/backward-compatible-development/index.html#adding-a-constructor-parameter

@okorshenko okorshenko modified the milestones: January 2018, February 2018 Feb 7, 2018
@okorshenko okorshenko modified the milestones: February 2018, March 2018 Mar 1, 2018
@orlangur orlangur self-assigned this Mar 13, 2018
@orlangur
Copy link
Contributor

Closing due to inactivity. @dvynograd, feel free to reach me out anytime later if you wish to continue work on this pull request and it will be reopened.

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