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.46k stars 9.28k forks source link

Minicart cannot be used twice in the same page #38958

Open ioweb-gr opened 1 month ago

ioweb-gr commented 1 month ago

Summary

The minicart element can't be used twice in the same page due to harcoded bindings.

For example in Magento_Checkout::js/view/minicart.js you can see that it will hook into [data-block="minicart"] without any possibility to override this.

image

In some other cases when you have a header bar that's displayed on desktop and a different one tht's displayed on mobile you may still experience the issue.

Basically we're only left with trying to move around the minicart using jquery instead of being able to toggle it's visibility per case.

When using two of them, one of them won't be able to display it's dropdown.

Unless I'm missing in which case please correct me, this looks like something that wasn't intended.

Examples

Here's a sample layout that's not really possible without jQuery due to the limitation of the minicart

image

In this case randomly one of the two minicarts won't display it's dropdown.

Proposed solution

The binding element should be decided by the config of the ui component as in other components.

From minicart.phtml you see that the binding is on element [data-block='minicart']

    <script type="text/x-magento-init">
    {
        "[data-block='minicart']": {
            "Magento_Ui/js/core/app": <?= /* @noEscape */ $block->getJsLayout() ?>
        },
        "*": {
            "Magento_Ui/js/block-loader": "<?= $block->escapeJs(
                $block->escapeUrl($block->getViewFileUrl('images/loader-1.gif'))
            ) ?>"
        }
    }
    </script>

In the config of the ui compoment the binding element selector should be possible to configure so that we can use unique identifiers.

An alternative solution would be when there are multiple elements with the same functionality

[data-block='minicart']

It should bind to both of them properly and make sure the dropdown works.

Release note

No response

Triage and priority

m2-assistant[bot] commented 1 month ago

Hi @ioweb-gr. 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:

ananth-iyer commented 1 month ago

@ioweb-gr Did you added new div with [data-block="minicart"]

ioweb-gr commented 1 month ago

@ananth-iyer In the html there are two instances of [data-block="minicart"] one for each minicart block

This is an example http://polr.ioweb.gr/PQLCC

m2-assistant[bot] commented 1 month ago

Hi @engcom-November. 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-November commented 1 month ago

Hello @ioweb-gr,

Thank you for the report and collaboration!

Verified this on 2.4-develop. Added minicart in the footer, when clicking the minicart it opens up at the default location. Please take a look at the screencast: ScreenRecording2024-07-24at6 29 39PM-ezgif com-video-to-gif-converter

Hence Confirming this issue.

Thank you.

github-jira-sync-bot commented 1 month ago

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

m2-assistant[bot] commented 1 month ago

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

ioweb-gr commented 1 month ago

Thank you :) any idea for a quick patch for this? It's a really pestering bug