Magento2: Product Collection: Apply limitations event is not triggered when category_id and visibility are not specified

Created on 11 Aug 2017  路  3Comments  路  Source: magento/magento2


Preconditions


  1. Magento 2.1.8
  2. PHP 7.0.20
  3. Mysql 5.7

Steps to reproduce


When creating a Collection of type Magento\Catalog\Model\ResourceModel\Product\Collection without a visibility and category_id filter, the event catalog_product_collection_apply_limitations_after is not triggered.

See: module-catalog/Model/ResourceModel/Product/Collection.php method _applyProductLimitations().

Expected result


The catalog_product_collection_apply_limitations_after event should be triggered.

Actual result


The catalog_product_collection_apply_limitations_after event is not triggered.

Clear Description Format is valid

Most helpful comment

Hi @rakibabu
Unfortunately changing this behavior may break client code which already relies on existing flow. Thus, it is best to leave it as is, given that other methods of achieving the same result exist.

Thank you for collaboration

All 3 comments

@rakibabu thank you for your bug report.
We've created internal ticket MAGETWO-75361 to track progress on the issue.

It always worked this way: https://github.com/OpenMage/magento-mirror/blob/magento-1.9/app/code/core/Mage/Catalog/Model/Resource/Product/Collection.php#L1853 Changing this behavior may lead to undesired consequences for those who relied on old behavior.

Writing new code you shouldn't use event-observers mechanism whenever possible. As far as I see from this implementation, you can easily implement an after plugin for addPriceData, applyFrontendPriceLimitations, addWebsiteFilter or whatever methods you need.

Hi @rakibabu
Unfortunately changing this behavior may break client code which already relies on existing flow. Thus, it is best to leave it as is, given that other methods of achieving the same result exist.

Thank you for collaboration

Was this page helpful?
0 / 5 - 0 ratings