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

GITHUB-8970: Cannot assign products to categories not under tree root. #11817

Merged
merged 4 commits into from
Nov 3, 2017

Conversation

p-bystritsky
Copy link
Contributor

Description

Added ability to assign products to categories if those products are already assigned to category tree root (id=1).

Fixed Issues (if relevant)

  1. Cannot assign products to categories not under tree root #8970: Cannot assign products to categories not under tree root.

Manual testing scenarios

  1. Create a Product, assign it to any category.
  2. Open your Magento database table "catalog_category_product", locate your Product table entry and change it's "category_id" value to 1.
  3. Assign your Product to some category through admin interface and save it.
  4. "You saved the product." message should appear.

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)

@dmanners dmanners self-assigned this Oct 28, 2017
@dmanners
Copy link
Contributor

@p-bystritsky thanks for this PR. Could you please look at the test failures.

There was 1 failure:
1) Magento\CatalogUrlRewrite\Test\Unit\Model\ProductScopeRewriteGeneratorTest::testGenerationForGlobalScope
Expectation failed for method name is equal to <string:getParentId> when invoked 2 time(s).
Method was expected to be called 2 times, actually called 1 times.

And

1) Magento\Test\Php\LiveCodeTest::testCodeStyle
PHP Code Sniffer detected 2 violation(s): 
FILE: .../app/code/Magento/CatalogUrlRewrite/Model/ProductScopeRewriteGenerator.php
--------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------
 211 | ERROR | [x] Expected 0 spaces after opening bracket; newline found
--------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------

@dmanners dmanners added this to the October 2017 milestone Oct 30, 2017
@dmanners dmanners added Release Line: 2.2 2.2.x bug report Component: Catalog Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release 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 Oct 30, 2017
@dmanners
Copy link
Contributor

@p-bystritsky I do not think this fixes the issue fully. In the case of your fix you will no longer be able to have malfunctioning categories and the save via the admin should still work, which is good, but the core of the issue raised was the usage of list(, $rootCategoryId) = $category->getParentIds(); which is still in place.

As mentioned in the issue #8970 Generally speaking, it is advisable to avoid relying on a specific order of operation, as this may change again in the future. I would suggest that a "nicer" option for now would be to check that $category->getParentIds() returns an array of at least 2 entries and that the 2nd one is the store's root category. This way we cover both the broken category tables and also the miss use of the list option.

Do you think you will be able to make this change?

Copy link
Contributor

@dmanners dmanners left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to remove the usage of list as this has changed between php5 and php7 and as noted Generally speaking, it is advisable to avoid relying on a specific order of operation, as this may change again in the future.

@p-bystritsky
Copy link
Contributor Author

Hello, @dmanners. I'll try to remove list usage with the hint you provided.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report Component: Catalog Progress: accept Release Line: 2.2 Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release 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

Successfully merging this pull request may close these issues.

4 participants