Skip to content

Commit a9b5ff9

Browse files
committed
Fix for Store View field in Admin Panel on post & category grids
1 parent cec5a58 commit a9b5ff9

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

Model/ResourceModel/Category/Collection.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ protected function _construct()
6969
public function addFieldToFilter($field, $condition = null)
7070
{
7171
if ($field === 'store_id' || $field === 'store_ids') {
72-
return $this->addStoreFilter($condition, false);
72+
return $this->addStoreFilter($condition);
7373
}
7474

7575
return parent::addFieldToFilter($field, $condition);
@@ -147,7 +147,15 @@ protected function _afterLoad()
147147
$connection = $this->getConnection();
148148
$select = $connection->select()->from(['cps' => $this->getTable('magefan_blog_category_store')])
149149
->where('cps.category_id IN (?)', $items);
150-
$result = $connection->fetchPairs($select);
150+
151+
$result = [];
152+
foreach ($connection->fetchAll($select) as $item) {
153+
if (!isset($result[$item['category_id']])) {
154+
$result[$item['category_id']] = [];
155+
}
156+
$result[$item['category_id']][] = $item['store_id'];
157+
}
158+
151159
if ($result) {
152160
foreach ($this as $item) {
153161
$categoryId = $item->getData('category_id');
@@ -161,7 +169,7 @@ protected function _afterLoad()
161169
$storeId = $result[$item->getData('category_id')];
162170
}
163171
$item->setData('_first_store_id', $storeId);
164-
$item->setData('store_ids', [$result[$categoryId]]);
172+
$item->setData('store_ids', $result[$categoryId]);
165173
}
166174
}
167175

Model/ResourceModel/Post/Collection.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ protected function _construct()
8080
public function addFieldToFilter($field, $condition = null)
8181
{
8282
if ($field === 'store_id' || $field === 'store_ids') {
83-
return $this->addStoreFilter($condition, false);
83+
return $this->addStoreFilter($condition);
8484
}
8585

8686
return parent::addFieldToFilter($field, $condition);
@@ -258,7 +258,14 @@ protected function _afterLoad()
258258
->from(['cps' => $tableName])
259259
->where('cps.post_id IN (?)', $items);
260260

261-
$result = $connection->fetchPairs($select);
261+
$result = [];
262+
foreach ($connection->fetchAll($select) as $item) {
263+
if (!isset($result[$item['post_id']])) {
264+
$result[$item['post_id']] = [];
265+
}
266+
$result[$item['post_id']][] = $item['store_id'];
267+
}
268+
262269
if ($result) {
263270
foreach ($this as $item) {
264271
$postId = $item->getData('post_id');
@@ -272,7 +279,7 @@ protected function _afterLoad()
272279
$storeId = $result[$item->getData('post_id')];
273280
}
274281
$item->setData('_first_store_id', $storeId);
275-
$item->setData('store_ids', [$result[$postId]]);
282+
$item->setData('store_ids', $result[$postId]);
276283
}
277284
}
278285

0 commit comments

Comments
 (0)