Skip to content

Commit

Permalink
Merge pull request #43 from experius/feature/IN23-284
Browse files Browse the repository at this point in the history
Feature/in23 284
  • Loading branch information
DRdevil27 authored Oct 25, 2024
2 parents c43853c + ca5f313 commit d6d6ba1
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions Console/Command/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -193,4 +201,20 @@ private function renderConversion($data)
$table->setRows($data);
$table->render($data);
}

/**
* @param $fromUrl
* @param $storeId
*/
private function getStoreView($fromUrl)
{
$storeId = $this->storeManager->getDefaultStoreView()->getId();
foreach ($this->storeRepository->getList() as $store) {
if (strpos($fromUrl, $store->getBaseUrl(), 0)) {
$storeId = $store->getId();
break;
}
}
return $storeId;
}
}

0 comments on commit d6d6ba1

Please sign in to comment.