Skip to content

Commit 3f0a990

Browse files
committed
MC-15250: Explicit product sorting in PageBuilder Products Content type
1 parent 10fe63a commit 3f0a990

File tree

3 files changed

+7
-112
lines changed

3 files changed

+7
-112
lines changed

app/code/Magento/PageBuilder/Model/Catalog/Sorting/PriceAbstract.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ abstract protected function getSortDirection();
2626
public function sort(
2727
\Magento\Catalog\Model\ResourceModel\Product\Collection $collection
2828
): \Magento\Catalog\Model\ResourceModel\Product\Collection {
29-
$collection->joinAttribute('price', 'catalog_product/price', 'entity_id', null, 'left');
29+
$collection->joinAttribute('sorting_price', 'catalog_product/price', 'entity_id', null, 'left');
3030
$collection->getSelect()
3131
->reset(Select::ORDER)
32-
->order('price '.$this->getSortDirection());
32+
->order('sorting_price '.$this->getSortDirection());
3333

3434
return $collection;
3535
}

app/code/Magento/PageBuilder/Model/Catalog/Sorting/SortAbstract.php

Lines changed: 3 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@
66

77
namespace Magento\PageBuilder\Model\Catalog\Sorting;
88

9-
use Magento\Catalog\Model\Indexer\Product\Price\DimensionCollectionFactory;
10-
use Magento\Framework\App\ObjectManager;
11-
use Magento\Framework\Indexer\ScopeResolver\IndexScopeResolver;
12-
use Magento\Customer\Model\Indexer\CustomerGroupDimensionProvider;
13-
use Magento\Framework\Indexer\DimensionFactory;
14-
159
/**
1610
* Class SortAbstract
1711
*
@@ -25,47 +19,14 @@ class SortAbstract
2519
protected $moduleManager;
2620

2721
/**
28-
* @var \Magento\Framework\App\Config\ScopeConfigInterface
29-
*/
30-
protected $scopeConfig;
31-
32-
/**
33-
* @var DimensionCollectionFactory
34-
*/
35-
private $dimensionCollectionFactory;
36-
37-
/**
38-
* @var IndexScopeResolver
39-
*/
40-
private $indexScopeResolver;
41-
42-
/**
43-
* @var DimensionFactory|null
44-
*/
45-
private $dimensionFactory;
46-
47-
/**
22+
* SortAbstract constructor.
23+
*
4824
* @param \Magento\Framework\Module\Manager $moduleManager
49-
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
50-
* @param DimensionCollectionFactory|null $dimensionCollectionFactory
51-
* @param IndexScopeResolver|null $indexScopeResolver
52-
* @param DimensionFactory|null $dimensionFactory
5325
*/
5426
public function __construct(
55-
\Magento\Framework\Module\Manager $moduleManager,
56-
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
57-
DimensionCollectionFactory $dimensionCollectionFactory = null,
58-
IndexScopeResolver $indexScopeResolver = null,
59-
DimensionFactory $dimensionFactory = null
27+
\Magento\Framework\Module\Manager $moduleManager
6028
) {
6129
$this->moduleManager = $moduleManager;
62-
$this->scopeConfig = $scopeConfig;
63-
$this->dimensionCollectionFactory = $dimensionCollectionFactory
64-
?: ObjectManager::getInstance()->get(DimensionCollectionFactory::class);
65-
$this->indexScopeResolver = $indexScopeResolver
66-
?: ObjectManager::getInstance()->get(IndexScopeResolver::class);
67-
$this->dimensionFactory = $dimensionFactory
68-
?: ObjectManager::getInstance()->get(DimensionFactory::class);
6930
}
7031

7132
/**
@@ -97,71 +58,4 @@ protected function descOrder(): string
9758
{
9859
return \Magento\Framework\DB\Select::SQL_DESC;
9960
}
100-
101-
/**
102-
* Adding price information
103-
*
104-
* @param \Magento\Catalog\Model\ResourceModel\Product\Collection $collection
105-
* @return void
106-
*/
107-
protected function addPriceData($collection): void
108-
{
109-
$connection = $collection->getConnection();
110-
$select = $collection->getSelect();
111-
$joinCond = join(
112-
' AND ',
113-
['price_index.entity_id = e.entity_id']
114-
);
115-
$select->where('customer_group_id = ?', 0);
116-
117-
$fromPart = $select->getPart(\Magento\Framework\DB\Select::FROM);
118-
119-
if (!isset($fromPart['price_index'])) {
120-
$least = $connection->getLeastSql(['price_index.min_price', 'price_index.tier_price']);
121-
$minimalExpr = $connection->getCheckSql(
122-
'price_index.tier_price IS NOT NULL',
123-
$least,
124-
'price_index.min_price'
125-
);
126-
$specialCheck = $connection->getCheckSql(
127-
'price_index.price <> price_index.final_price',
128-
1,
129-
0
130-
);
131-
$colls = [
132-
'price',
133-
'tax_class_id',
134-
'final_price',
135-
'min_price',
136-
'max_price',
137-
'tier_price',
138-
'special_price' => $specialCheck,
139-
'minimal_price' => $minimalExpr,
140-
];
141-
142-
$where = str_replace('`e`.', '', $select->getPart('where')[0]);
143-
144-
$selects = [];
145-
$dimensionsCollection = iterator_to_array($this->dimensionCollectionFactory->create());
146-
foreach ($dimensionsCollection as $dimensions) {
147-
$unionSelect = clone $connection->select();
148-
if (array_key_exists(CustomerGroupDimensionProvider::DIMENSION_NAME, $dimensions)) {
149-
$dimensions[CustomerGroupDimensionProvider::DIMENSION_NAME]
150-
= $this->dimensionFactory->create(CustomerGroupDimensionProvider::DIMENSION_NAME, 0);
151-
}
152-
$tableName = $this->indexScopeResolver->resolve('catalog_product_index_price', $dimensions);
153-
$selects[] = $unionSelect->from($tableName)->where($where);
154-
}
155-
$selects = array_unique($selects);
156-
$unionPrice = $connection->select()->union($selects);
157-
$select->joinLeft(
158-
['price_index' => $unionPrice],
159-
'price_index.entity_id = e.entity_id',
160-
$colls
161-
);
162-
} else {
163-
$fromPart['price_index']['joinCondition'] = $joinCond;
164-
$select->setPart(\Magento\Framework\DB\Select::FROM, $fromPart);
165-
}
166-
}
16761
}

app/code/Magento/PageBuilder/etc/module.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111
<module name="Magento_Eav"/>
1212
<module name="Magento_Cms"/>
1313
<module name="Magento_Catalog"/>
14+
<module name="Magento_CatalogInventory"/>
1415
<module name="Magento_Backend"/>
1516
<module name="Magento_Ui"/>
1617
<module name="Magento_Theme"/>
1718
<module name="Magento_Search"/>
1819
<module name="Magento_CatalogWidget"/>
1920
</sequence>
2021
</module>
21-
</config>
22+
</config>

0 commit comments

Comments
 (0)