6
6
7
7
namespace Magento \PageBuilder \Model \Catalog \Sorting ;
8
8
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
-
15
9
/**
16
10
* Class SortAbstract
17
11
*
@@ -25,47 +19,14 @@ class SortAbstract
25
19
protected $ moduleManager ;
26
20
27
21
/**
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
+ *
48
24
* @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
53
25
*/
54
26
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
60
28
) {
61
29
$ 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);
69
30
}
70
31
71
32
/**
@@ -97,71 +58,4 @@ protected function descOrder(): string
97
58
{
98
59
return \Magento \Framework \DB \Select::SQL_DESC ;
99
60
}
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
- }
167
61
}
0 commit comments