FireGento_FastSimpleImport2
FireGento_FastSimpleImport2 copied to clipboard
Can it generate URI by url_key during importing?
It looks like it saves url_key during the import but it cannot generate an URI properly.
my-key => my-key.html
It was found for categories.
Here is my workaround (import is done with an external script):
$importerModel = $obj->create('FireGento\FastSimpleImport\Model\Importer');
// Build your categories array
$importerModel->processImport($categoryArray);
$categoryCollection = $obj->create('Magento\Catalog\Model\ResourceModel\Category\Collection');
$urlPersist = $obj->create('Magento\UrlRewrite\Model\UrlPersistInterface');
$categoryUrlRewriteGenerator = $obj->create('Magento\CatalogUrlRewrite\Model\CategoryUrlRewriteGenerator');
$categoryCollection->addAttributeToSelect(['url_path', 'url_key']);
$list = $categoryCollection->load();
foreach($list as $category)
{
$urlPersist->deleteByData([
UrlRewrite::ENTITY_ID => $category->getId(),
UrlRewrite::ENTITY_TYPE => CategoryUrlRewriteGenerator::ENTITY_TYPE,
UrlRewrite::REDIRECT_TYPE => 0
]);
try {
$urlPersist->replace(
$categoryUrlRewriteGenerator->generate($category)
);
}
catch(\Exception $e) {
print_r('<error>Duplicated url for '. $category->getId() .'</error>');
}
}
It's a little dirty because it reindex the URL for all categories, but you could select only the imported categories.
Hello VincentMarmiesse,
I recently added this feature to the master branch. Its in the commit https://github.com/firegento/FireGento_FastSimpleImport2/commit/e14bfdcfd5a4c3cfd4b3f2b2c333a729c962e20f
Feel free to try it out.
Greetings Elias
Hello @EliasKotlyar,
Can I get this update via Composer? It tells me there is no update.
Thanks!
@EliasKotlyar: just curious: did you test it out with categories having different url_key's in different storeviews? Because we ran into a bunch of core Magento2 bugs a couple of months ago, when we were trying to do something similar. For example: we sometimes got the error 'URL key for specified store already exists', or we ran into this: https://github.com/magento/magento2/issues/8396 (I just see a couple of very recent commits referenced at the bottom which should fix it, but not tested yet)
Hello everyone,
@VincentMarmiesse : Please have a look at this Page : http://firegento-fastsimpleimport2.readthedocs.io/en/latest/Installation.html
You will find some instructions how to install the development Version
@hostep : I personally havent tried it, because i didnt had such requirements yet. But i heard of some problems with the urls which can be actually solved using following "Core-Hack"(you can actually turn it into a Plugin):
vendor/magento/module-catalog-url-rewrite/Model/CategoryUrlPathGenerator.php
Insert "$category->setStoreId($storeId);" into the method:
` public function getUrlPathWithSuffix($category, $storeId = null) { if ($storeId === null) { $storeId = $category->getStoreId(); } $category->setStoreId($storeId); return $this->getUrlPath($category) . $this->getCategoryUrlSuffix($storeId); }
`
@EliasKotlyar,
I have been able to get the latest version by using "firegento/fastsimpleimport": "dev-master" in my composer.json and I can confirm you that your modification for the categories URL works like a charm!