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 product url from getProductUrl when current category has not product object #17819

Closed
OleksiiBulba opened this issue Aug 27, 2018 · 4 comments
Assignees
Labels
Component: Catalog Fixed in 2.2.x The issue has been fixed in 2.2 release line Fixed in 2.3.x The issue has been fixed in 2.3 release line Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release

Comments

@OleksiiBulba
Copy link

OleksiiBulba commented Aug 27, 2018

Preconditions

  1. Install Magento 2.2.4
  2. Create two category category1 and category2 with url-keys category-1 and category-2 respectively
  3. Create product with url key product-1, assign it to category1
  4. Add created categories to topmenu (turn on "include to menu" checkbox)

Steps to reproduce

  1. Create custom module Vendor_Module; run setup:upgrade command
  2. Create template; add it to category layout
  3. In the template get product collection with all products in it
  4. In foreach loop try to get product url:
<?php foreach ($productCollection as $product): ?>
<? /** @var $product \Magento\Catalog\Model\Product */ ?>
<a href="<?= $product->getProductUrl() ?>"><?= $product->getName() ?></a>
<?php endforeach; ?>
  1. Open category2(!) page http://example.com/category-2

Expected result

  1. The product link should be like http://example.com/category-1/product-1

Actual result

  1. The product link is http://example.com/catalog/product/view/id/1/s/product-1/category/2

Possible reason

  1. In the file app/code/Magento/Catalog/Model/Product.php:695 (2.2 branch) product tries to get category from current_category;
  2. In the file app/code/Magento/Catalog/Model/Product/Url.php:163 (2.2 branch) Url model is searching for url rewrite for product1 from category2, but such rewrite does not exist because product1 does not belong to category2

Possible solution

  1. Check if retrieved category has product
  2. Add param to getProductUrl that specifies desired category in product url, for example:
<?php
$product->getProductUrl($category);
// or
$urlModel->getProductUrl($category, $product);
@magento-engcom-team magento-engcom-team added the Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed label Aug 27, 2018
@magento-engcom-team
Copy link
Contributor

Hi @OleksiiBulba. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

  • Summary of the issue
  • Information on your environment
  • Steps to reproduce
  • Expected and actual results

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento-engcom-team give me {$VERSION} instance

where {$VERSION} is version tags (starting from 2.2.0+) or develop branches (2.2-develop +).
For more details, please, review the Magento Contributor Assistant documentation.

@OleksiiBulba do you confirm that you was able to reproduce the issue on vanilla Magento instance following steps to reproduce?

  • yes
  • no

@engcom-backlog-nickolas engcom-backlog-nickolas added Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Component: Catalog Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release labels Aug 28, 2018
@engcom-backlog-nickolas

Hello @OleksiiBulba, thank you for your report.
We've acknowledged the issue and added to our backlog.

@magento-engcom-team
Copy link
Contributor

Hi @OleksiiBulba. Thank you for your report.
The issue has been fixed in #19232 by @ErikPel in 2.3-develop branch
Related commit(s):

The fix will be available with the upcoming 2.3.1 release.

@magento-engcom-team
Copy link
Contributor

Hi @OleksiiBulba. Thank you for your report.
The issue has been fixed in #20286 by @GovindaSharma in 2.2-develop branch
Related commit(s):

The fix will be available with the upcoming 2.2.8 release.

@magento-engcom-team magento-engcom-team added the Fixed in 2.2.x The issue has been fixed in 2.2 release line label Jan 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Catalog Fixed in 2.2.x The issue has been fixed in 2.2 release line Fixed in 2.3.x The issue has been fixed in 2.3 release line Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release
Projects
None yet
Development

No branches or pull requests

4 participants