diff --git a/Console/Command/Import.php b/Console/Command/Import.php index 784ad41..1d599d1 100644 --- a/Console/Command/Import.php +++ b/Console/Command/Import.php @@ -30,19 +30,25 @@ class Import extends Command protected $input; protected $output; - + protected $pageNotFoundFactory; + protected $storeRepository; + protected $storeManager; public function __construct( \Magento\Framework\File\Csv $csv, \Magento\Framework\App\State $state, \Magento\Framework\App\Filesystem\DirectoryList $directoryList, - \Experius\PageNotFound\Model\PageNotFoundFactory $pageNotFoundFactory + \Experius\PageNotFound\Model\PageNotFoundFactory $pageNotFoundFactory, + \Magento\Store\Api\StoreRepositoryInterface $storeRepository, + \Magento\Store\Model\StoreManagerInterface $storeManager ){ $this->csv = $csv; $this->state = $state; $this->directoryList = $directoryList; $this->pageNotFoundFactory = $pageNotFoundFactory; + $this->storeRepository = $storeRepository; + $this->storeManager = $storeManager; return parent::__construct(); } @@ -129,9 +135,11 @@ protected function savePageNotFound($fromUrl,$toUrl){ $pageNotFound = $this->pageNotFoundFactory->create(); $pageNotFound->load($fromUrl,'from_url'); + $storeId = $this->getStoreView($fromUrl); $pageNotFound->setFromUrl($fromUrl); $pageNotFound->setToUrl($toUrl); + $pageNotFound->setStoreId($storeId); $pageNotFound->save(); } @@ -193,4 +201,21 @@ private function renderConversion($data) $table->setRows($data); $table->render($data); } + + /** + * @param $fromUrl + * @param $storeId + * @return int + */ + private function getStoreView($fromUrl): int + { + $storeId = $this->storeManager->getDefaultStoreView()->getId(); + foreach ($this->storeRepository->getList() as $store) { + if (str_starts_with($fromUrl, $store->getBaseUrl())) { + $storeId = $store->getId(); + break; + } + } + return $storeId; + } }