1

magento 2 how to show minicart in custom Popup ? enter image description here

3 Answers 3

1

This is a sample. You need to modify your way:

app/code/SR/MagentoCommunity/view/frontend/layout/default.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <update handle="checkout_cart_sidebar_item_renderers"/>
    <update handle="checkout_cart_sidebar_item_price_renderers"/>
    <update handle="checkout_cart_sidebar_total_renderers"/>
    <body>
        <referenceContainer name="content">
            <block name="popup_minicart" as="popup_minicart" template="SR_MagentoCommunity::minicart.phtml">
                <arguments>
                    <argument name="jsLayout" xsi:type="array">
                        <item name="types" xsi:type="array"/>
                        <item name="components" xsi:type="array">
                            <item name="minicart_content" xsi:type="array">
                                <item name="component" xsi:type="string">Magento_Checkout/js/view/minicart</item>
                                <item name="config" xsi:type="array">
                                    <item name="template" xsi:type="string">Magento_Checkout/minicart/content</item>
                                </item>
                                <item name="children" xsi:type="array">
                                    <item name="subtotal.container" xsi:type="array">
                                        <item name="component" xsi:type="string">uiComponent</item>
                                        <item name="config" xsi:type="array">
                                            <item name="displayArea" xsi:type="string">subtotalContainer</item>
                                        </item>
                                        <item name="children" xsi:type="array">
                                            <item name="subtotal" xsi:type="array">
                                                <item name="component" xsi:type="string">uiComponent</item>
                                                <item name="config" xsi:type="array">
                                                    <item name="template" xsi:type="string">Magento_Checkout/minicart/subtotal</item>
                                                </item>
                                            </item>
                                        </item>
                                    </item>
                                    <item name="extra_info" xsi:type="array">
                                        <item name="component" xsi:type="string">uiComponent</item>
                                        <item name="config" xsi:type="array">
                                            <item name="displayArea" xsi:type="string">extraInfo</item>
                                        </item>
                                    </item>
                                    <item name="promotion" xsi:type="array">
                                        <item name="component" xsi:type="string">uiComponent</item>
                                        <item name="config" xsi:type="array">
                                            <item name="displayArea" xsi:type="string">promotion</item>
                                        </item>
                                    </item>
                                </item>
                            </item>
                        </item>
                    </argument>
                </arguments>
            </block>
        </referenceContainer>
    </body>
</page>

app/code/SR/MagentoCommunity/view/frontend/templates/minicart.phtml

<?php /** @var $block \Magento\Framework\View\Element\Template */ ?>
<div style="display: none" id="popup-mpdal">
    <div id="minicart-content-wrapper" data-bind="scope: 'minicart_content'">
        <!-- ko template: getTemplate() --><!-- /ko -->
    </div>
</div>
<script>
    window.checkout = <?= /* @escapeNotVerified */ $block->getSerializedConfig() ?>;
</script>
<script type="text/x-magento-init">
    {
        "[data-block='minicart']": {
            "Magento_Ui/js/core/app": <?= /* @escapeNotVerified */ $block->getJsLayout() ?>
        },
        "*": {
            "Magento_Ui/js/block-loader": "<?= /* @escapeNotVerified */ $block->getViewFileUrl('images/loader-1.gif') ?>"
        }
    }
    </script>
<script>
    require(
        [
            'jquery',
            'Magento_Ui/js/modal/modal'
        ],
        function(
            $,
            modal
        ) {
            var options = {
                type: 'popup',
                responsive: true,
                innerScroll: true,
                buttons: [{
                    text: $.mage.__('Continue'),
                    click: function () {
                        this.closeModal();
                        $('#popup-mpdal').hide();
                    }
                }]
            };

            $('#popup-mpdal').show();
            var popup = modal(options, $('#popup-mpdal'));
            $("#popup-mpdal").modal("openModal");
        }
    );
</script>
4
  • ok checking and let you know Apr 12, 2019 at 6:50
  • Here may i customise also content.html ? Apr 12, 2019 at 8:02
  • For customization change <item name="template" xsi:type="string">Magento_Checkout/minicart/content</item> this template inside your module
    – Sohel Rana
    Apr 12, 2019 at 8:32
  • Thank you so much man accepted answer and upvote. Apr 12, 2019 at 10:18
0

avove minicart page working fine, i need spport any one, when clik add to cart button, show minicart page with detils

0
0

Magento 2.3.p2: i wanted to do some changes minicart page, when click add to cart button, minicart popup page open with cart items only

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.