diff --git a/vendor/magento/module-visual-merchandiser/Model/Category/Products.php b/vendor/magento/module-visual-merchandiser/Model/Category/Products.php index 3058e3c1788..88656f280df 100644 --- a/vendor/magento/module-visual-merchandiser/Model/Category/Products.php +++ b/vendor/magento/module-visual-merchandiser/Model/Category/Products.php @@ -172,9 +172,7 @@ class Products */ private function applyPositions(Collection $collection, int $categoryId, $productPositions = null) { - $positions = $this->getPositions(); - - if ($positions === false) { + if (!$this->_cache->getPositions($this->_cacheKey)) { if (!is_array($productPositions)) { $collection->getSelect()->where('at_position.category_id = ?', $categoryId); $collection->joinField( @@ -187,15 +185,18 @@ class Products ); $collection->setOrder('position', $collection::SORT_ORDER_ASC); $productPositions = $this->positionResolver->getPositions($categoryId); + $collection->setOrder('entity_id', $collection::SORT_ORDER_DESC); } $this->positions = $productPositions; } else { $collection->getSelect()->reset(Select::WHERE)->reset(Select::HAVING); - $collection->addAttributeToFilter('entity_id', ['in' => array_keys($positions)]); + $collection->addAttributeToFilter('entity_id', ['in' => array_keys($this->getPositions())]); + + return $this->applyCachedChanges($collection); } - return $this->applyCachedChanges($collection); + return $collection; } /**