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

Wrong parent category url_key in URL #4112

Closed
bh-ref opened this issue Apr 12, 2016 · 19 comments
Closed

Wrong parent category url_key in URL #4112

bh-ref opened this issue Apr 12, 2016 · 19 comments
Labels
Fixed in 2.4.x The issue has been fixed in 2.4-develop branch Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed

Comments

@bh-ref
Copy link
Contributor

bh-ref commented Apr 12, 2016

Preconditions

  • Magento 2.1 and 2.2

Steps to reproduce

We have two frontend storeviews in Magento 2.0.4, a French one and a German one. But the parent category url_key in the URL rewrites is always the German one, for both, the german and the french storeview.

Expected result

Expected URL rewrite for a sub-category:
https://example.com/fr/french-parent-category/french-sub-category/

Expected URL rewrite for a product:
https://example.com/fr/french-parent-category/french-product/

Actual result

Actual URL rewrite for sub-category:
https://example.com/fr/german-parent-category/french-sub-category/

Actual URL rewrite for a product:
https://example.com/fr/german-parent-category/french-product/

@bh-ref bh-ref changed the title Wrong (sub-)category url_key in URL Wrong parent category url_key in URL Apr 12, 2016
@piotrekkaminski
Copy link
Contributor

internal issue MAGETWO-53443

@rganin
Copy link
Contributor

rganin commented May 26, 2016

Issue is not reproducible on 2.0.4, 2.0.7 and 2.1 with following combinations:

  • 1 website (default), 2 store views (default & french),
  • 2 websites (default, french). with one store view each (default - default, french - french)

Please verify that parent category (german-parent-category) in your instance has url-key value overriden on store view level. Please provide more details on the category entities values on different store views.

@bh-ref
Copy link
Contributor Author

bh-ref commented May 26, 2016

Hi @rganin

Thank you for looking into this issue.

All german url-keys are defined on default level (store view: all). The french url-keys are defined in the french store view. (In other words, no german url-keys are defined and/or overriden in the german store view).

@bh-ref
Copy link
Contributor Author

bh-ref commented May 26, 2016

also, just to clarify, we are using this combination: 1 website (default), 2 store views (german (sort order 0) & french (sort order 1)).

@rganin
Copy link
Contributor

rganin commented May 27, 2016

@bh-ref thanks for clarification, I will resume the investigation.

@rganin
Copy link
Contributor

rganin commented May 27, 2016

@bh-ref still cannot reproduce the issue on 2.0.4. Sorry for the silly question but do you have url-key for french store view on parent category? Or do you have some url-related extensions or customizations?

@stevenvdp
Copy link
Contributor

We have a similar problem.

Category configuration:
Default config > url_key = "products"
French store > url_key = "produits"

Product configuration:
Default config > url_key: "awesome_product"
French store > url_key: "un_produit"

The url rewrite will be created after saving the product, but the category path is not store specific.
French store rewrite: products/un_produit

We are using v2.0.6 and have traced down the problem.

Inside app/code/Magento/CatalogUrlRewrite/Model/ProductUrlRewriteGenerator.php:80 the product categories are fetched, but not store specific. Later on it calls generateForSpecificStoreView() and passes the storeId, but the storeId is never used for calculating the category url path inside the following method:

getUrlPathWithSuffix (app/code/Magento/CatalogUrlRewrite/Model/ProductUrlPathGenerator.php:94)

    public function getUrlPathWithSuffix($product, $storeId, $category = null)
    {
        return $this->getUrlPath($product, $category) . $this->getProductUrlSuffix($storeId);
    }

Hope this helps for this case.

@rganin
Copy link
Contributor

rganin commented May 30, 2016

Could reproduce the issue.
@stevenvdp great thanks for your input, proceeding with fix.

@bh-ref
Copy link
Contributor Author

bh-ref commented May 30, 2016

@stevenvdp thank you for diving into it!

@rganin we actually do have some extensions related to url-keys, but they should not interact in that way. But I am happy to test the eventual fix against our extension.

@palamar palamar added the Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development label Jun 22, 2016
@vkorotun vkorotun removed the MX label Aug 4, 2016
@hostep
Copy link
Contributor

hostep commented Dec 2, 2016

We also run into a very similar problem, which happens after trying to create url rewrites in an automated category/product import job.

What seems to fix it, is these two changes (based on the Magento 2.1.2 codebase):

  1. \Magento\CatalogUrlRewrite\Model\ProductUrlRewriteGenerator::generate
diff --git a/app/code/Magento/CatalogUrlRewrite/Model/ProductUrlRewriteGenerator.php b/app/code/Magento/CatalogUrlRewrite/Model/ProductUrlRewriteGenerator.php
index 6539a95..92ae0ec 100644
--- a/app/code/Magento/CatalogUrlRewrite/Model/ProductUrlRewriteGenerator.php
+++ b/app/code/Magento/CatalogUrlRewrite/Model/ProductUrlRewriteGenerator.php
@@ -108,7 +108,8 @@ class ProductUrlRewriteGenerator

         $productCategories = $product->getCategoryCollection()
             ->addAttributeToSelect('url_key')
-            ->addAttributeToSelect('url_path');
+            ->addAttributeToSelect('url_path')
+            ->setStoreId($storeId);

         $urls = $this->isGlobalScope($storeId)
             ? $this->generateForGlobalScope($productCategories)
  1. \Magento\CatalogUrlRewrite\Model\Product\AnchorUrlRewriteGenerator::generate
diff --git a/app/code/Magento/CatalogUrlRewrite/Model/Product/AnchorUrlRewriteGenerator.php b/app/code/Magento/CatalogUrlRewrite/Model/Product/AnchorUrlRewriteGenerator.php
index 972b5c0..8845c7a 100644
--- a/app/code/Magento/CatalogUrlRewrite/Model/Product/AnchorUrlRewriteGenerator.php
+++ b/app/code/Magento/CatalogUrlRewrite/Model/Product/AnchorUrlRewriteGenerator.php
@@ -55,7 +55,7 @@ class AnchorUrlRewriteGenerator
             $anchorCategoryIds = $category->getAnchorsAbove();
             if ($anchorCategoryIds) {
                 foreach ($anchorCategoryIds as $anchorCategoryId) {
-                    $anchorCategory = $this->categoryRepository->get($anchorCategoryId);
+                    $anchorCategory = $this->categoryRepository->get($anchorCategoryId, $storeId);
                     $urls[] = $this->urlRewriteFactory->create()
                         ->setEntityType(ProductUrlRewriteGenerator::ENTITY_TYPE)
                         ->setEntityId($product->getId())

@veloraven
Copy link
Contributor

This issue was fixed for ver. 2.1.
Closed.

@korostii
Copy link
Contributor

Hi @veloraven could you please reference a particular version (2.1.6, 2.1.7, etc.)? Or at least a commit that fixes the issue?

@evilprophet
Copy link

Hi @veloraven you said that this was fixed for 2.1, but I still have this issue on 2.1.10 and 2.2. So where this is fixed?

@magento-engcom-team magento-engcom-team added the Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed label Jan 5, 2018
@peterjaap
Copy link
Contributor

This is still not fixed for the AnchorUrlRewriteGenerator.

This is the patch I'm using in the meantime;

diff --git a/Model/Product/AnchorUrlRewriteGenerator.php b/Model/Product/AnchorUrlRewriteGenerator.php
index a7cc894..c382d5f 100644
--- a/Model/Product/AnchorUrlRewriteGenerator.php
+++ b/Model/Product/AnchorUrlRewriteGenerator.php
@@ -61,7 +61,7 @@ class AnchorUrlRewriteGenerator
             $anchorCategoryIds = $category->getAnchorsAbove();
             if ($anchorCategoryIds) {
                 foreach ($anchorCategoryIds as $anchorCategoryId) {
-                    $anchorCategory = $this->categoryRepository->get($anchorCategoryId);
+                    $anchorCategory = $this->categoryRepository->get($anchorCategoryId, $storeId);
                     $urls[] = $this->urlRewriteFactory->create()
                         ->setEntityType(ProductUrlRewriteGenerator::ENTITY_TYPE)
                         ->setEntityId($product->getId())
-- 
2.14.1

@peterjaap peterjaap reopened this Apr 17, 2018
@peterjaap
Copy link
Contributor

Hm it seems that @hostep already applied this fix but later on it was reverted again.

@hostep
Copy link
Contributor

hostep commented Apr 17, 2018

@peterjaap: it was never accepted, I purposely closed the PR since it caused too many negative side effects, I can't remember which ones though...

But there is a new pending PR which might get merged someday: #14344

@magento-engcom-team magento-engcom-team added Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed and removed Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development bug report labels Jul 5, 2018
@ghost ghost self-assigned this Aug 15, 2018
@ghost
Copy link

ghost commented Aug 15, 2018

This issue is already fixed in Magento 2.2.5 and 2.3-dev version.
default

@ghost ghost closed this as completed Aug 15, 2018
magento-engcom-team pushed a commit that referenced this issue Apr 25, 2019
[borg] MAGETWO-99307: Authorize.net Transaction Fails but Order goes through
@slavvka slavvka added the Fixed in 2.4.x The issue has been fixed in 2.4-develop branch label Mar 17, 2020
@slavvka
Copy link
Member

slavvka commented Mar 17, 2020

@PiroozMB
Copy link

PiroozMB commented Feb 25, 2022

@olga Moyseyenko @veloraven
You are very funny just going around and closing the issues leaving them with no solution :-)
I don't know how you got hired there lol. Is there nothing better to do for you there ?
When people say the issue is not solved ,they really mean it. So don't close the issues like this. Just help to solve them.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fixed in 2.4.x The issue has been fixed in 2.4-develop branch Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed
Projects
None yet
Development

No branches or pull requests