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

Non-canonical URL being sent for product recaching #12

Closed
quangdo-aligent opened this issue Dec 19, 2023 · 1 comment
Closed

Non-canonical URL being sent for product recaching #12

quangdo-aligent opened this issue Dec 19, 2023 · 1 comment
Assignees

Comments

@quangdo-aligent
Copy link
Contributor

quangdo-aligent commented Dec 19, 2023

For example, products can have a URL like: /occasions-and-events/anniversary/golden-anniversary/decorative-metallic-champagne-gold-placemat-chrtwpm06.html in addition to their canonical URLS (e.g. /decorative-metallic-champagne-gold-placemat-chrtwpm06.html in this case).

It seems like due to the way that the request_path product field is populated in the Product collection, it will always use the URL rewrite with the newest ID that matches the following criteria:

select * from url_rewrite where entity_id=46223 and store_id=1 and redirect_type=0 and entity_type='product' order by url_rewrite_id;
+----------------+-------------+-----------+----------------------------------------------------------------------------------------------------------------+--------------------------------------------+---------------+----------+-------------+------------------+-----------------------+
| url_rewrite_id | entity_type | entity_id | request_path                                                                                                   | target_path                                | redirect_type | store_id | description | is_autogenerated | metadata              |
+----------------+-------------+-----------+----------------------------------------------------------------------------------------------------------------+--------------------------------------------+---------------+----------+-------------+------------------+-----------------------+
|       72115604 | product     |     46223 | decorative-metallic-champagne-gold-placemat-chrtwpm06.html                                                     | catalog/product/view/id/46223              |             0 |        1 | NULL        |                1 | NULL                  |
|       72115607 | product     |     46223 | occasions-and-events/christmas/decorative-metallic-champagne-gold-placemat-chrtwpm06.html                      | catalog/product/view/id/46223/category/277 |             0 |        1 | NULL        |                1 | {"category_id":"277"} |
|       72115610 | product     |     46223 | themed-parties/gangster/decorative-metallic-champagne-gold-placemat-chrtwpm06.html                             | catalog/product/view/id/46223/category/255 |             0 |        1 | NULL        |                1 | {"category_id":"255"} |
|       72115613 | product     |     46223 | coloured-party-supplies/gold/decorative-metallic-champagne-gold-placemat-chrtwpm06.html                        | catalog/product/view/id/46223/category/318 |             0 |        1 | NULL        |                1 | {"category_id":"318"} |
|       72115616 | product     |     46223 | fringe-colours/fringe-gold/decorative-metallic-champagne-gold-placemat-chrtwpm06.html                          | catalog/product/view/id/46223/category/795 |             0 |        1 | NULL        |                1 | {"category_id":"795"} |
|       72115619 | product     |     46223 | occasions-and-events/anniversary/golden-anniversary/decorative-metallic-champagne-gold-placemat-chrtwpm06.html | catalog/product/view/id/46223/category/821 |             0 |        1 | NULL        |                1 | {"category_id":"821"} |
+----------------+-------------+-----------+----------------------------------------------------------------------------------------------------------------+--------------------------------------------+---------------+----------+-------------+------------------+-----------------------+

The relevant part of the code in \Magento\Catalog\Model\ResourceModel\Product\Collection::_addUrlRewrite:
2023-12-19_16-34

The for loop starts from the lowest ID to the highest ID so occasions-and-events/anniversary/golden-anniversary/decorative-metallic-champagne-gold-placemat-chrtwpm06.html would be the final value set as the request_path.

Requirements:

  • We need to be using the canonical URL for re-caching instead of relying on the request_path field of each product due to the way it is being generated.

I'm thinking we probably don't want to use request_path at all and rather rely on the product's URL key.

@jehanben
Copy link

jehanben commented Jan 8, 2024

The changes have been fixed and merged into the main branch.

PR: #13

@jehanben jehanben closed this as completed Jan 8, 2024
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

3 participants