FireGento_FastSimpleImport2 icon indicating copy to clipboard operation
FireGento_FastSimpleImport2 copied to clipboard

Can it generate URI by url_key during importing?

Open andkirby opened this issue 8 years ago • 6 comments

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.

andkirby avatar Feb 15 '17 08:02 andkirby

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.

VincentMarmiesse avatar May 22 '17 15:05 VincentMarmiesse

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

EliasKotlyar avatar May 23 '17 21:05 EliasKotlyar

Hello @EliasKotlyar,

Can I get this update via Composer? It tells me there is no update.

Thanks!

VincentMarmiesse avatar May 23 '17 23:05 VincentMarmiesse

@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)

hostep avatar May 24 '17 07:05 hostep

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 avatar May 24 '17 08:05 EliasKotlyar

@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!

VincentMarmiesse avatar May 24 '17 08:05 VincentMarmiesse