@@ -17,12 +17,18 @@ abstract class AbstractCollection extends \Magento\Framework\Model\ResourceModel
17
17
*/
18
18
protected $ storeManager ;
19
19
20
+ /**
21
+ * @var \Magento\Framework\Model\Entity\MetadataPool
22
+ */
23
+ protected $ metadataPool ;
24
+
20
25
/**
21
26
* @param \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory
22
27
* @param \Psr\Log\LoggerInterface $logger
23
28
* @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy
24
29
* @param \Magento\Framework\Event\ManagerInterface $eventManager
25
30
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
31
+ * @param \Magento\Framework\Model\Entity\MetadataPool $metadataPool
26
32
* @param \Magento\Framework\DB\Adapter\AdapterInterface|null $connection
27
33
* @param \Magento\Framework\Model\ResourceModel\Db\AbstractDb|null $resource
28
34
*/
@@ -32,45 +38,47 @@ public function __construct(
32
38
\Magento \Framework \Data \Collection \Db \FetchStrategyInterface $ fetchStrategy ,
33
39
\Magento \Framework \Event \ManagerInterface $ eventManager ,
34
40
\Magento \Store \Model \StoreManagerInterface $ storeManager ,
41
+ \Magento \Framework \Model \Entity \MetadataPool $ metadataPool ,
35
42
\Magento \Framework \DB \Adapter \AdapterInterface $ connection = null ,
36
43
\Magento \Framework \Model \ResourceModel \Db \AbstractDb $ resource = null
37
44
) {
38
- parent ::__construct ($ entityFactory , $ logger , $ fetchStrategy , $ eventManager , $ connection , $ resource );
39
45
$ this ->storeManager = $ storeManager ;
46
+ $ this ->metadataPool = $ metadataPool ;
47
+ parent ::__construct ($ entityFactory , $ logger , $ fetchStrategy , $ eventManager , $ connection , $ resource );
40
48
}
41
49
42
50
/**
43
51
* Perform operations after collection load
44
52
*
45
53
* @param string $tableName
46
- * @param string $columnName
54
+ * @param string|null $linkField
47
55
* @return void
48
56
*/
49
- protected function performAfterLoad ($ tableName , $ columnName )
57
+ protected function performAfterLoad ($ tableName , $ linkField )
50
58
{
51
- $ items = $ this ->getColumnValues ($ columnName );
52
- if (count ($ items )) {
59
+ $ linkedIds = $ this ->getColumnValues ($ linkField );
60
+ if (count ($ linkedIds )) {
53
61
$ connection = $ this ->getConnection ();
54
62
$ select = $ connection ->select ()->from (['cms_entity_store ' => $ this ->getTable ($ tableName )])
55
- ->where ('cms_entity_store. ' . $ columnName . ' IN (?) ' , $ items );
63
+ ->where ('cms_entity_store. ' . $ linkField . ' IN (?) ' , $ linkedIds );
56
64
$ result = $ connection ->fetchPairs ($ select );
57
65
if ($ result ) {
58
66
foreach ($ this as $ item ) {
59
- $ entityId = $ item ->getData ($ columnName );
60
- if (!isset ($ result [$ entityId ])) {
67
+ $ linkedId = $ item ->getData ($ linkField );
68
+ if (!isset ($ result [$ linkedId ])) {
61
69
continue ;
62
70
}
63
- if ($ result [$ entityId ] == 0 ) {
71
+ if ($ result [$ linkedId ] == 0 ) {
64
72
$ stores = $ this ->storeManager ->getStores (false , true );
65
73
$ storeId = current ($ stores )->getId ();
66
74
$ storeCode = key ($ stores );
67
75
} else {
68
- $ storeId = $ result [$ item -> getData ( $ columnName ) ];
76
+ $ storeId = $ result [$ linkedId ];
69
77
$ storeCode = $ this ->storeManager ->getStore ($ storeId )->getCode ();
70
78
}
71
79
$ item ->setData ('_first_store_id ' , $ storeId );
72
80
$ item ->setData ('store_code ' , $ storeCode );
73
- $ item ->setData ('store_id ' , [$ result [$ entityId ]]);
81
+ $ item ->setData ('store_id ' , [$ result [$ linkedId ]]);
74
82
}
75
83
}
76
84
}
@@ -129,18 +137,18 @@ protected function performAddStoreFilter($store, $withAdmin = true)
129
137
* Join store relation table if there is store filter
130
138
*
131
139
* @param string $tableName
132
- * @param string $columnName
140
+ * @param string|null $linkField
133
141
* @return void
134
142
*/
135
- protected function joinStoreRelationTable ($ tableName , $ columnName )
143
+ protected function joinStoreRelationTable ($ tableName , $ linkField )
136
144
{
137
145
if ($ this ->getFilter ('store ' )) {
138
146
$ this ->getSelect ()->join (
139
147
['store_table ' => $ this ->getTable ($ tableName )],
140
- 'main_table. ' . $ columnName . ' = store_table. ' . $ columnName ,
148
+ 'main_table. ' . $ linkField . ' = store_table. ' . $ linkField ,
141
149
[]
142
150
)->group (
143
- 'main_table. ' . $ columnName
151
+ 'main_table. ' . $ linkField
144
152
);
145
153
}
146
154
parent ::_renderFiltersBefore ();
0 commit comments