Skip to content

magento/magento2#22870: ProductRepository fails to update an existing product with a changed SKU. #22933

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

Merged
merged 2 commits into from
Jun 13, 2019

Conversation

p-bystritsky
Copy link
Contributor

Description (*)

Fixed Issues (if relevant)

  1. ProductRepository fails to update an existing product with a changed SKU #22870: ProductRepository fails to update an existing product with a changed SKU.

Manual testing scenarios (*)

  1. See issue description.

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 are green)

@m2-assistant
Copy link

m2-assistant bot commented May 17, 2019

Hi @p-bystritsky. 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.3-develop instance - deploy vanilla Magento instance

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

$this->productRepository->save($initialProduct);

$updatedProduct = Bootstrap::getObjectManager()->create(Product::class);
$updatedProduct->load($productId);
Copy link
Contributor

Choose a reason for hiding this comment

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

Please, avoid using deprecated methods.
For loading a model, use a resource model and product model factory. So in result we have something like:

Suggested change
$updatedProduct->load($productId);
// ProductResource is alias for \Magento\Catalog\Model\ResourceModel\Product
// ProductFactory is alias for \Magento\Catalog\Model\ProductFactory
$productFactory = Bootstrap::getObjectManager()->get(ProductFactory::class)
$updatedProduct = $productFactory->create()
$productResource = Bootstrap::getObjectManager()->get(ProductResource::class)
$productResource->load($updatedProduct, $productId)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rogyar updated.

Copy link
Contributor

@ihor-sviziev ihor-sviziev left a comment

Choose a reason for hiding this comment

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

Hi @p-bystritsky,
In general changes looks good. Could you review my suggestions? We don't need to have code duplication

@ghost ghost assigned ihor-sviziev May 24, 2019
@p-bystritsky
Copy link
Contributor Author

Hi @p-bystritsky,
In general changes looks good. Could you review my suggestions? We don't need to have code duplication

@ihor-sviziev, thank you. Your suggestions committed.

Copy link
Contributor

@ihor-sviziev ihor-sviziev left a comment

Choose a reason for hiding this comment

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

Hi @p-bystritsky,
Could you check failing tests? Looks like your change broke some functionality
PS: very strange that we hadn’t these fails before fixing static tests, it it might be just coincidence

Co-Authored-By: Ihor Sviziev <ihor-sviziev@users.noreply.github.com>
@p-bystritsky
Copy link
Contributor Author

@ihor-sviziev fixed.

@magento-engcom-team
Copy link
Contributor

Hi @ihor-sviziev, thank you for the review.
ENGCOM-5134 has been created to process this Pull Request

@soleksii
Copy link

✔️ QA Passed

Before:

before

After:

after

@Nazar65 Nazar65 self-assigned this May 30, 2019
@magento-engcom-team
Copy link
Contributor

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

@magento-engcom-team magento-engcom-team merged commit d9282d8 into magento:2.3-develop Jun 13, 2019
@m2-assistant
Copy link

m2-assistant bot commented Jun 13, 2019

Hi @p-bystritsky, 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 pushed a commit that referenced this pull request Jun 13, 2019
@magento-engcom-team magento-engcom-team added this to the Release: 2.3.3 milestone Jun 13, 2019
@sidolov sidolov added the Auto-Tests: Covered All changes in Pull Request is covered by auto-tests label Sep 16, 2019
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.

7 participants