Skip to content

Commit d18f582

Browse files
committed
Improve import from AW on multi-store
1 parent 224607a commit d18f582

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

Model/Import/AbstractImport.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,19 @@ abstract class AbstractImport extends \Magento\Framework\Model\AbstractModel
5353
*/
5454
protected $_skippedCategories = [];
5555

56+
/**
57+
* @var \Magento\Store\Model\StoreManagerInterface
58+
*/
59+
protected $_storeManager;
60+
5661
/**
5762
* Initialize dependencies.
5863
*
5964
* @param \Magento\Framework\Model\Context $context
6065
* @param \Magento\Framework\Registry $registry
6166
* @param \Magefan\Blog\Model\PostFactory $postFactory,
6267
* @param \Magefan\Blog\Model\CategoryFactory $categoryFactory,
68+
* @param \Magento\Store\Model\StoreManagerInterface $storeManager,
6369
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
6470
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
6571
* @param array $data
@@ -69,12 +75,14 @@ public function __construct(
6975
\Magento\Framework\Registry $registry,
7076
\Magefan\Blog\Model\PostFactory $postFactory,
7177
\Magefan\Blog\Model\CategoryFactory $categoryFactory,
78+
\Magento\Store\Model\StoreManagerInterface $storeManager,
7279
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
7380
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
7481
array $data = []
7582
) {
7683
$this->_postFactory = $postFactory;
7784
$this->_categoryFactory = $categoryFactory;
85+
$this->_storeManager = $storeManager;
7886

7987
parent::__construct($context, $registry, $resource, $resourceCollection, $data);
8088
}

Model/Import/Aw.php

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ public function execute()
5252
throw new \Exception(__('AheadWorks Blog Extension not detected.'), 1);
5353
}
5454

55+
$storeIds = array_keys($this->_storeManager->getStores(true));
56+
5557
$categories = [];
5658
$oldCategories = [];
5759

@@ -76,8 +78,15 @@ public function execute()
7678
while ($s_data = mysqli_fetch_assoc($s_result)) {
7779
$data['store_ids'][] = $s_data['store_id'];
7880
}
79-
if (empty($data['store_ids'])) {
80-
$data['store_ids'][] = 0;
81+
82+
foreach ($data['store_ids'] as $key => $id) {
83+
if (!in_array($id, $storeIds)) {
84+
unset($data['store_ids'][$key]);
85+
}
86+
}
87+
88+
if (empty($data['store_ids']) || in_array(0, $data['store_ids'])) {
89+
$data['store_ids'] = 0;
8190
}
8291

8392
$data['is_active'] = 1;
@@ -112,7 +121,8 @@ public function execute()
112121
while ($c_data = mysqli_fetch_assoc($c_result)) {
113122
$oldId = $c_data['category_id'];
114123
if (isset($oldCategories[$oldId])) {
115-
$postCategories[] = $oldCategories[$oldId]->getId();
124+
$id = $oldCategories[$oldId]->getId();
125+
$postCategories[$id] = $id;
116126
}
117127
}
118128

@@ -124,8 +134,13 @@ public function execute()
124134
$data['store_ids'][] = $s_data['store_id'];
125135
}
126136

127-
128-
if (empty($data['store_ids'])) {
137+
foreach ($data['store_ids'] as $key => $id) {
138+
if (!in_array($id, $storeIds)) {
139+
unset($data['store_ids'][$key]);
140+
}
141+
}
142+
143+
if (empty($data['store_ids']) || in_array(0, $data['store_ids'])) {
129144
$data['store_ids'] = 0;
130145
}
131146

0 commit comments

Comments
 (0)