-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Load product in default store before duplicating #23209
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
Load product in default store before duplicating #23209
Conversation
Hi @JeroenVanLeusden. Thank you for your contribution
For more details, please, review the Magento Contributor Assistant documentation |
4c05b3b
to
3d15811
Compare
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.
Not really happy with reloading the product while we have it already as method parameter. Maybe deprecate the copy() method and create a copyBySku() method?
I also agree, it would be better to pass the already correct product data as copy
method parameter.
So we may try to load the product via repository in case the current_store_id
value of the product is not equal to Store::DEFAULT_STORE_ID
, instead of using the Product Builder in the following controller actions:
\Magento\Catalog\Controller\Adminhtml\Product\Duplicate::execute
\Magento\Catalog\Controller\Adminhtml\Product\Save::execute
The only problem, in my opinion, is that the product entity after loading does not contain all the necessary data. I guess, the bunch of data entries still need to be populated from request.
Thank you!
Hi @dmytro-ch, I can refactor the if ($redirectBack === 'duplicate') {
if ($product->getStoreId() === \Magento\Store\Model\Store::DEFAULT_STORE_ID) {
$product->unsetData('quantity_and_stock_status');
$productToDuplicate = $product;
} else {
$productToDuplicate = $this->productRepository->get(
$product->getSku(),
false,
\Magento\Store\Model\Store::DEFAULT_STORE_ID,
true
);
}
$newProduct = $this->productCopier->copy($productToDuplicate);
$this->messageManager->addSuccessMessage(__('You duplicated the product.'));
} Although i'm not sure what you mean with:
The product is already saved so all the data we need should be there already when fetched using the repository? Also, I've found no reference to |
@JeroenVanLeusden, The new solution looks correct to me.
I mean if you compare the results of
Sure |
1e503ea
to
50bd097
Compare
Hi @dmytro-ch, I've updated the PR, still using the repository to load the product because it duplicates just fine. Are there some additional tests I can do to make sure it's all good? |
Hi @sidolov, thank you for the review.
|
Hi @JeroenVanLeusden during testing PR changes I found issue with product duplicate when different URL Key is set for each store view.
Result: Could you take a look? |
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.
This PR is really closely related to #24505 and looks like changes from this PR could fix issue that described @engcom-Delta.
Could you collaborate with @webkul-paul to fix both these issues?
@@ -6,6 +6,9 @@ | |||
*/ | |||
namespace Magento\Bundle\Controller\Adminhtml\Bundle\Product\Edit; | |||
|
|||
/** | |||
* @deprecated |
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 add description why it became deprecated and add @see
tag with example what we should use instead
@@ -242,6 +242,7 @@ public function getProductSetId() | |||
|
|||
/** | |||
* @return string | |||
* @deprecated |
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 add description why it became deprecated and add @see
tag with example what we should use instead
@@ -9,6 +9,9 @@ | |||
use Magento\Backend\App\Action; | |||
use Magento\Catalog\Controller\Adminhtml\Product; | |||
|
|||
/** | |||
* @deprecated |
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 add description why it became deprecated and add @see
tag with example what we should use instead
@@ -6,6 +6,9 @@ | |||
*/ | |||
namespace Magento\Downloadable\Controller\Adminhtml\Downloadable\Product\Edit; | |||
|
|||
/** | |||
* @deprecated |
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 add description why it became deprecated and add @see
tag with example what we should use instead
@JeroenVanLeusden , I am closing this PR now due to inactivity. |
Hi @JeroenVanLeusden, thank you for your contribution! |
Description (*)
Duplicating a product will use the current scope data as default values instead of copying it from the original product.
Fixed Issues (if relevant)
Manual testing scenarios (*)
Questions or comments
Not really happy with reloading the product while we have it already as method parameter. Maybe deprecate the
copy()
method and create acopyBySku()
method?Will update tests if implementation is approved by Magento.
Contribution checklist (*)