-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
magento/magento2#22870: ProductRepository fails to update an existing product with a changed SKU. #22933
Conversation
Hi @p-bystritsky. Thank you for your contribution
For more details, please, review the Magento Contributor Assistant documentation |
$this->productRepository->save($initialProduct); | ||
|
||
$updatedProduct = Bootstrap::getObjectManager()->create(Product::class); | ||
$updatedProduct->load($productId); |
There was a problem hiding this comment.
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:
$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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rogyar updated.
…with a changed SKU.
There was a problem hiding this 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
@ihor-sviziev, thank you. Your suggestions committed. |
There was a problem hiding this 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>
@ihor-sviziev fixed. |
Hi @ihor-sviziev, thank you for the review. |
Hi @rogyar, thank you for the review. |
Hi @p-bystritsky, thank you for your contribution! |
…oduct with a changed SKU. #22933
Description (*)
Fixed Issues (if relevant)
Manual testing scenarios (*)
Contribution checklist (*)