diff --git a/vendor/magento/module-catalog/Model/Layer.php b/vendor/magento/module-catalog/Model/Layer.php index fb94e82..957acb6 100644 --- a/vendor/magento/module-catalog/Model/Layer.php +++ b/vendor/magento/module-catalog/Model/Layer.php @@ -1,20 +1,25 @@ _layerStateFactory = $layerStateFactory; $this->_attributeCollectionFactory = $attributeCollectionFactory; $this->_catalogProduct = $catalogProduct; $this->_storeManager = $storeManager; $this->registry = $registry; $this->categoryRepository = $categoryRepository; $this->collectionProvider = $context->getCollectionProvider(); $this->stateKeyGenerator = $context->getStateKey(); $this->collectionFilter = $context->getCollectionFilter(); + $this->productListHelper = $productListHelper ?: ObjectManager::getInstance()->create(ProductList::class); + $this->request = $request ?: ObjectManager::getInstance()->create(RequestInterface::class);; parent::__construct($data); } /** * Get layer state key * * @return string */ public function getStateKey() { @@ -133,28 +161,47 @@ class Layer extends \Magento\Framework\DataObject return $this->_stateKey; } /** * Retrieve current layer product collection * * @return \Magento\Catalog\Model\ResourceModel\Product\Collection */ public function getProductCollection() { + $page = $this->request->getParam('p') + ? $this->request->getParam('p') + : 1; + $listMode = $this->request->getParam('product_list_mode') + ? $this->request->getParam('product_list_mode') + : $this->productListHelper->getDefaultViewMode(); + $listLimit = $this->request->getParam('product_list_limit') + ? $this->request->getParam('product_list_limit') + : $this->productListHelper->getDefaultLimitPerPageValue($listMode); + $listDirection = $this->request->getParam('product_list_dir') + ? $this->request->getParam('product_list_dir') + : Select::SQL_ASC; + $listOrder = $this->request->getParam('product_list_order') + ? $this->request->getParam('product_list_order') + : $this->productListHelper->getDefaultSortField(); + if (isset($this->_productCollections[$this->getCurrentCategory()->getId()])) { $collection = $this->_productCollections[$this->getCurrentCategory()->getId()]; } else { $collection = $this->collectionProvider->getCollection($this->getCurrentCategory()); $this->prepareProductCollection($collection); $this->_productCollections[$this->getCurrentCategory()->getId()] = $collection; } + $collection->setOrder($listOrder, $listDirection); + $collection->setPage($page, $listLimit); + return $collection; } /** * Initialize product collection * * @param \Magento\Catalog\Model\ResourceModel\Product\Collection $collection * @return \Magento\Catalog\Model\Layer */ public function prepareProductCollection($collection)