diff --git a/app/code/Magento/Catalog/Block/Product/ListProduct.php b/app/code/Magento/Catalog/Block/Product/ListProduct.php index 33488ee1c93c4..132d0a6a17e55 100644 --- a/app/code/Magento/Catalog/Block/Product/ListProduct.php +++ b/app/code/Magento/Catalog/Block/Product/ListProduct.php @@ -14,6 +14,7 @@ use Magento\Catalog\Model\Layer\Resolver; use Magento\Catalog\Model\Product; use Magento\Catalog\Model\ResourceModel\Product\Collection; +use Magento\Catalog\Model\Product\ProductList\CollectionLoader; use Magento\Catalog\Pricing\Price\FinalPrice; use Magento\Eav\Model\Entity\Collection\AbstractCollection; use Magento\Framework\App\ActionInterface; @@ -68,12 +69,18 @@ class ListProduct extends AbstractProduct implements IdentityInterface */ protected $categoryRepository; + /** + * @var CollectionLoader + */ + protected $collectionLoader; + /** * @param Context $context * @param PostHelper $postDataHelper * @param Resolver $layerResolver * @param CategoryRepositoryInterface $categoryRepository * @param Data $urlHelper + * @param CollectionLoader $collectionLoader * @param array $data */ public function __construct( @@ -82,12 +89,14 @@ public function __construct( Resolver $layerResolver, CategoryRepositoryInterface $categoryRepository, Data $urlHelper, + CollectionLoader $collectionLoader, array $data = [] ) { $this->_catalogLayer = $layerResolver->get(); $this->_postDataHelper = $postDataHelper; $this->categoryRepository = $categoryRepository; $this->urlHelper = $urlHelper; + $this->collectionLoader = $collectionLoader; parent::__construct( $context, $data @@ -188,7 +197,7 @@ protected function _beforeToHtml() $this->addToolbarBlock($collection); - $collection->load(); + $this->collectionLoader->load($collection); return parent::_beforeToHtml(); } @@ -463,7 +472,7 @@ private function initializeProductCollection() if ($origCategory) { $layer->setCurrentCategory($origCategory); } - + $this->addToolbarBlock($collection); $this->_eventManager->dispatch( diff --git a/app/code/Magento/Catalog/Block/Product/ProductList/Promotion.php b/app/code/Magento/Catalog/Block/Product/ProductList/Promotion.php index 18d07d02b6074..bb7b723d8b86d 100644 --- a/app/code/Magento/Catalog/Block/Product/ProductList/Promotion.php +++ b/app/code/Magento/Catalog/Block/Product/ProductList/Promotion.php @@ -8,6 +8,7 @@ use Magento\Catalog\Api\CategoryRepositoryInterface; use Magento\Catalog\Model\ResourceModel\Product\Collection; use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory; +use Magento\Catalog\Model\Product\ProductList\CollectionLoader; class Promotion extends \Magento\Catalog\Block\Product\ListProduct { @@ -29,6 +30,7 @@ class Promotion extends \Magento\Catalog\Block\Product\ListProduct * @param \Magento\Catalog\Model\Layer\Resolver $layerResolver * @param CategoryRepositoryInterface $categoryRepository * @param \Magento\Framework\Url\Helper\Data $urlHelper + * @param CollectionLoader $collectionLoader * @param CollectionFactory $productCollectionFactory * @param array $data */ @@ -38,6 +40,7 @@ public function __construct( \Magento\Catalog\Model\Layer\Resolver $layerResolver, CategoryRepositoryInterface $categoryRepository, \Magento\Framework\Url\Helper\Data $urlHelper, + CollectionLoader $collectionLoader, CollectionFactory $productCollectionFactory, array $data = [] ) { @@ -48,6 +51,7 @@ public function __construct( $layerResolver, $categoryRepository, $urlHelper, + $collectionLoader, $data ); } diff --git a/app/code/Magento/Catalog/Block/Product/ProductList/Random.php b/app/code/Magento/Catalog/Block/Product/ProductList/Random.php index cf67c6d709fb5..67fbec8489e54 100644 --- a/app/code/Magento/Catalog/Block/Product/ProductList/Random.php +++ b/app/code/Magento/Catalog/Block/Product/ProductList/Random.php @@ -6,6 +6,7 @@ namespace Magento\Catalog\Block\Product\ProductList; use Magento\Catalog\Api\CategoryRepositoryInterface; +use Magento\Catalog\Model\Product\ProductList\CollectionLoader; /** * Catalog product random items block @@ -32,6 +33,7 @@ class Random extends \Magento\Catalog\Block\Product\ListProduct * @param \Magento\Catalog\Model\Layer\Resolver $layerResolver * @param CategoryRepositoryInterface $categoryRepository * @param \Magento\Framework\Url\Helper\Data $urlHelper + * @param CollectionLoader $collectionLoader * @param \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory * @param array $data */ @@ -41,6 +43,7 @@ public function __construct( \Magento\Catalog\Model\Layer\Resolver $layerResolver, CategoryRepositoryInterface $categoryRepository, \Magento\Framework\Url\Helper\Data $urlHelper, + CollectionLoader $collectionLoader, \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory, array $data = [] ) { @@ -51,6 +54,7 @@ public function __construct( $layerResolver, $categoryRepository, $urlHelper, + $collectionLoader, $data ); } diff --git a/app/code/Magento/Catalog/Model/Product/ProductList/CollectionLoader.php b/app/code/Magento/Catalog/Model/Product/ProductList/CollectionLoader.php new file mode 100644 index 0000000000000..ca11b461012ce --- /dev/null +++ b/app/code/Magento/Catalog/Model/Product/ProductList/CollectionLoader.php @@ -0,0 +1,28 @@ +load(); + return $collection; + } +} diff --git a/app/code/Magento/Catalog/Test/Unit/Model/Product/ProductList/CollectionLoaderTest.php b/app/code/Magento/Catalog/Test/Unit/Model/Product/ProductList/CollectionLoaderTest.php new file mode 100644 index 0000000000000..76b7cdce03816 --- /dev/null +++ b/app/code/Magento/Catalog/Test/Unit/Model/Product/ProductList/CollectionLoaderTest.php @@ -0,0 +1,25 @@ +getMockBuilder(\Magento\Catalog\Model\ResourceModel\Product\Collection::class) + ->disableOriginalConstructor() + ->getMock(); + + $mockedCollection->expects($this->once())->method('load'); + + $collectionLoader->load($mockedCollection); + } +} diff --git a/app/code/Magento/Review/Model/Plugin/ProductList/CollectionLoader.php b/app/code/Magento/Review/Model/Plugin/ProductList/CollectionLoader.php new file mode 100644 index 0000000000000..b8a03befd6bb5 --- /dev/null +++ b/app/code/Magento/Review/Model/Plugin/ProductList/CollectionLoader.php @@ -0,0 +1,51 @@ +reviewFactory = $reviewFactory; + } + + /** + * Append review summary before rendering html + * + * @param Loader $subject + * @param AbstractCollection $result + * @return AbstractCollection + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function afterLoad( + Loader $subject, + AbstractCollection $result + ) { + $this->reviewFactory->create()->appendSummary($result); + return $result; + } +} diff --git a/app/code/Magento/Review/Observer/CatalogBlockProductCollectionBeforeToHtmlObserver.php b/app/code/Magento/Review/Observer/CatalogBlockProductCollectionBeforeToHtmlObserver.php deleted file mode 100644 index 6256194cef53b..0000000000000 --- a/app/code/Magento/Review/Observer/CatalogBlockProductCollectionBeforeToHtmlObserver.php +++ /dev/null @@ -1,44 +0,0 @@ -_reviewFactory = $reviewFactory; - } - - /** - * Append review summary before rendering html - * - * @param \Magento\Framework\Event\Observer $observer - * @return $this - */ - 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); - } - - return $this; - } -} diff --git a/app/code/Magento/Review/etc/di.xml b/app/code/Magento/Review/etc/di.xml index ed9a15db03ca9..32aedccdbb81f 100644 --- a/app/code/Magento/Review/etc/di.xml +++ b/app/code/Magento/Review/etc/di.xml @@ -38,4 +38,7 @@ + + + diff --git a/app/code/Magento/Review/etc/frontend/events.xml b/app/code/Magento/Review/etc/frontend/events.xml index bc94277d69709..34ca7f084d57a 100644 --- a/app/code/Magento/Review/etc/frontend/events.xml +++ b/app/code/Magento/Review/etc/frontend/events.xml @@ -9,7 +9,4 @@ - - -