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

[Backport] Don't return categoryId from registry if the product doesn't belong in the current category #20286

Merged
merged 1 commit into from
Jan 18, 2019
Merged

Conversation

GovindaSharma
Copy link
Contributor

Original Pull Request

#19232

Description (*)

I added is_array check to \Magento\Catalog\Model\Product:getCategoryId that check whether the product belongs to the current_category set in registry. This fixes getProductUrl function not returning correct url since there isn't url rewrite for product in that category.

Fixed Issues (if relevant)

  1. Wrong product url from getProductUrl when current category has not product object #17819: Wrong product url from getProductUrl when current category has not product object

Manual testing scenarios (*)

  1. Create two category category1 and category2 with url-keys category-1 and category-2 respectively
  2. Create product with url key product-1, assign it to category1
  3. Add created categories to topmenu (turn on "include to menu" checkbox)
  4. Create custom module Vendor_Module I have example here if you want to get it fast https://github.com/ErikPel/17819-TestScenario
  5. Create template; add it to category layout
  6. In the template get product collection with all products in it
  7. In foreach loop call $product->getCategory() or $product->getProductUrl()
  8. Before getCategory would return the current_category from registry even though the product doesn't belong to the category we are in. And getProductUrl would return http://example.com/catalog/product/view/id/1/s/product-1/category/2 instead of http://example.com/product-1

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

@magento-engcom-team
Copy link
Contributor

Hi @GovindaSharma. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento-engcom-team give me test instance - deploy test instance based on PR changes
  • @magento-engcom-team give me 2.2-develop instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Assistant documentation

@magento-engcom-team magento-engcom-team added this to the Release: 2.2.8 milestone Jan 14, 2019
@magento-engcom-team
Copy link
Contributor

Hi @VladimirZaets, thank you for the review.
ENGCOM-3859 has been created to process this Pull Request

@ghost
Copy link

ghost commented Jan 18, 2019

Hi @GovindaSharma, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

@magento-engcom-team magento-engcom-team merged commit 0247fc3 into magento:2.2-develop Jan 18, 2019
@magento-engcom-team
Copy link
Contributor

Hi @GovindaSharma. Thank you for your contribution.
We will aim to release these changes as part of 2.2.8.
Please check the release notes for final confirmation.

Please, consider to port this solution to 2.3 release line.
You may use Porting tool to port commits automatically.

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

Successfully merging this pull request may close these issues.

4 participants