diff --git a/vendor/magento/module-page-builder/Model/Catalog/Sorting/Category/Position.php b/vendor/magento/module-page-builder/Model/Catalog/Sorting/Category/Position.php new file mode 100644 index 000000000..490ded496 --- /dev/null +++ b/vendor/magento/module-page-builder/Model/Catalog/Sorting/Category/Position.php @@ -0,0 +1,76 @@ +label = $label; + $this->sortDirection = $sortDirection; + $this->secondarySortDirection = $secondarySortDirection ?? $sortDirection; + } + + /** + * @inheritDoc + */ + public function sort(Collection $collection): Collection + { + $collection->getSelect()->reset(Select::ORDER); + $filters = $collection->getLimitationFilters(); + if ($collection->getStoreId() === Store::DEFAULT_STORE_ID && isset($filters['category_id'])) { + $collection->getSelect()->order("cat_index_position $this->sortDirection"); + } else { + $collection->addAttributeToSort('position', $this->sortDirection); + } + if ($this->secondarySortDirection) { + $collection->addAttributeToSort('entity_id', $this->secondarySortDirection); + } + return $collection; + } + + /** + * @inheritdoc + */ + public function getLabel(): Phrase + { + return __($this->label); + } +} diff --git a/vendor/magento/module-page-builder/Ui/DataProvider/Product/ProductCollection.php b/vendor/magento/module-page-builder/Ui/DataProvider/Product/ProductCollection.php index 1bdda9c00..403a60bcd 100644 --- a/vendor/magento/module-page-builder/Ui/DataProvider/Product/ProductCollection.php +++ b/vendor/magento/module-page-builder/Ui/DataProvider/Product/ProductCollection.php @@ -38,4 +38,34 @@ class ProductCollection extends \Magento\Catalog\Model\ResourceModel\Product\Col $this->_productLimitationFilters->setUsePriceIndex($this->getStoreId() !== Store::DEFAULT_STORE_ID); return $this->_productLimitationPrice(false); } + + /** + * @inheritdoc + */ + protected function _applyZeroStoreProductLimitations() + { + $conditions = [ + 'cat_pro.product_id=e.entity_id', + $this->getConnection()->quoteInto( + 'cat_pro.category_id = ?', + $this->_productLimitationFilters['category_id'], + \Zend_Db::INT_TYPE + ), + ]; + $joinCond = join(' AND ', $conditions); + $fromPart = $this->getSelect()->getPart(\Magento\Framework\DB\Select::FROM); + if (isset($fromPart['cat_pro'])) { + $fromPart['cat_pro']['joinCondition'] = $joinCond; + $this->getSelect()->setPart(\Magento\Framework\DB\Select::FROM, $fromPart); + } else { + $this->getSelect()->joinLeft( + ['cat_pro' => $this->getTable('catalog_category_product')], + $joinCond, + ['cat_index_position' => $this->getConnection()->getIfNullSql('position', '~0')] + ); + } + $this->_joinFields['position'] = ['table' => 'cat_pro', 'field' => 'position']; + + return $this; + } } diff --git a/vendor/magento/module-page-builder/etc/di.xml b/vendor/magento/module-page-builder/etc/di.xml index a3263bf36..e570e90b2 100644 --- a/vendor/magento/module-page-builder/etc/di.xml +++ b/vendor/magento/module-page-builder/etc/di.xml @@ -246,6 +246,7 @@ price + Position @@ -259,10 +260,17 @@ Position + + + Position + \Magento\Framework\DB\Select::SQL_ASC + \Magento\Framework\DB\Select::SQL_DESC + + - Magento\PageBuilder\Model\Catalog\Sorting\Position + Magento\PageBuilder\Model\Catalog\Sorting\Position\Ascending Magento\PageBuilder\Model\Catalog\Sorting\PositionBySku Magento\PageBuilder\Model\Catalog\Sorting\Date\NewestTop Magento\PageBuilder\Model\Catalog\Sorting\Date\OldestTop