Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can it generate URI by url_key during importing? #43

Open
andkirby opened this issue Feb 15, 2017 · 6 comments
Open

Can it generate URI by url_key during importing? #43

andkirby opened this issue Feb 15, 2017 · 6 comments

Comments

@andkirby
Copy link

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.

@VincentMarmiesse
Copy link
Contributor

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.

@EliasKotlyar
Copy link
Contributor

Hello VincentMarmiesse,

I recently added this feature to the master branch. Its in the commit e14bfdc

Feel free to try it out.

Greetings
Elias

@VincentMarmiesse
Copy link
Contributor

Hello @EliasKotlyar,

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

Thanks!

@hostep
Copy link

hostep commented May 24, 2017

@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: magento/magento2#8396 (I just see a couple of very recent commits referenced at the bottom which should fix it, but not tested yet)

@EliasKotlyar
Copy link
Contributor

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);
}

`

@VincentMarmiesse
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants