magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.54k stars 9.32k forks source link

Product images role issue on multi-store view for duplicate products #37656

Open kushaljindal92 opened 1 year ago

kushaljindal92 commented 1 year ago

Preconditions and environment

Steps to reproduce

Example

  1. Set up a multi-website environment.
  2. Create a product assigned to both websites.
  3. Assign a thumbnail role to the image in the base store.
  4. Assign small_image to the role of the image in another store.
  5. Save the product.
  6. Duplicate the product and you will find the base image role gets assigned but other store roles do not get assigned.

Expected result

Roles in both stores level should be assigned correctly.

Actual result

The role is assigned to the base store only and does not get assigned to another store.

Additional information

No response

Release note

No response

Triage and priority

m2-assistant[bot] commented 1 year ago

Hi @kushaljindal92. Thank you for your report. To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:

m2-assistant[bot] commented 1 year ago

Hi @engcom-Dash. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:


m2-assistant[bot] commented 1 year ago

Hi @engcom-Bravo. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

engcom-Bravo commented 1 year ago

Hi @kushaljindal92,

Thank you for reporting and collaboration.

Verified the issue on Magento 2.4-develop instance and the issue is reproducible.Kindly refer the screenshots.

Steps to reproduce

Screenshot 2023-06-28 at 4 56 37 PM Screenshot 2023-06-28 at 4 57 19 PM

The role is assigned to the base store only and does not get assigned to another store.

Hence Confirming this issue.

Thanks.

github-jira-sync-bot commented 1 year ago

:white_check_mark: Jira issue https://jira.corp.adobe.com/browse/AC-9083 is successfully created for this GitHub issue.

m2-assistant[bot] commented 1 year ago

:white_check_mark: Confirmed by @engcom-Bravo. Thank you for verifying the issue.
Issue Available: @engcom-Bravo, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

darthbit commented 8 months ago

any fix to this? How something like this gets overlooked lmao, its 2024 such a important thing, I have to manually go trough each of my store views and update manually my image roles for each product I duplicate and I have a store with 10 languages...

igorsKolcinsMagebit commented 5 months ago

Any updates?

dmanners commented 5 days ago

Probably not a fix that Magento themselves want to have in the core but we have a work around which involves two plugins. The issue seems to stem from the fact that in the duplicate product process the default store is used and for the images this does not always match. For example if the image and roles are only set on store level then the values will be copied during the eav attribute copy section but not the image roles themselves as \Magento\Catalog\Model\Product\Gallery\CreateHandler::processMediaAttribute will not be able to match the "new_image" with the values on the product as the product values will be null on the default store.

The first plugin in our workaround is an around plugin on \Magento\Catalog\Model\Product\Gallery\CreateHandler::execute. Here we check if the product has the duplicate flag set. When the flag is set then we do not do the normal execute as this is what causes issues.

        if ($product->getIsDuplicate() != true) {
            return $proceed($product, $arguments);
        }
        return $product;

Our second plugin is an after plugin on \Magento\Catalog\Model\Product\Copier::copy. Here we use the default Magento\Catalog\Model\Product\Gallery\CopyHandler to copy the images from the original product to the new one. This means rather than creating new images for each duplicate product we just reference the original product's images on our new product.

        $arguments = [
            'original_link_id' => $product->getId()
        ];
        $this->copyHandler->execute($result, $arguments);
        return $result;

From our test cases this seems to be working and the images have the correct roles, can be updated and deleted as expected.