2

I am working on MiniCart Extension in which I need a coupon code text box in my Minicart. For that I have overridden default.xml in my Custom Module but everytime It returns following error in the console. I think the layout is not able to find discount js however same js is there in the pub directory.

Failed to load the "Magento_SalesRule/js/view/payment/discount" component

This is the code inside default.xml

<?xml version="1.0"?>
<!--
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<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>
        <referenceBlock name="head.components">
            <block class="Magento\Framework\View\Element\Js\Components" name="checkout_page_head_components" template="Magento_Checkout::js/components.phtml"/>
        </referenceBlock>
        <referenceContainer name="header-wrapper">
            <block class="Magento\Checkout\Block\Cart\Sidebar" name="minicart" as="minicart" after="logo" template="Mageants_AjaxShoppingCart::cart/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="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="discount" xsi:type="array">
                                                <item name="component" xsi:type="string">Magento_SalesRule/js/view/payment/discount</item>
                                                <item name="children" xsi:type="array">
                                                    <item name="errors" xsi:type="array">
                                                        <item name="sortOrder" xsi:type="string">0</item>
                                                        <item name="component" xsi:type="string">Magento_SalesRule/js/view/payment/discount-messages</item>
                                                        <item name="displayArea" xsi:type="string">messages</item>
                                                    </item>
                                                </item>
                                            </item>


                                            <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>
                <container name="minicart.addons" label="Mini-cart promotion block"/>
            </block>
        </referenceContainer>
    </body>
</page>

Help will be appreciated. Thank You In Advance.

2

if that's still relevant, here's the answer:

Magento_SalesRule/js/view/payment/discount requires Magento_Checkout/js/model/quote, which asks for window.checkoutConfig.quoteData on line 32:

quoteData = window.checkoutConfig.quoteData,

window.checkoutConfig is not available anywhere except the checkout page - it is set in module-checkout/.../templates/onepage.phtml on line 26:

window.checkoutConfig = <?= /* @escapeNotVerified */ $block->getSerializedCheckoutConfig() ?>;

So, you are getting a TypeError: Cannot read property 'quoteData' of undefined. After that, url-builder produces the same kind of error when trying to read window.checkoutConfig.storeCode. You can see it if you set a breakpoint in require.js on line 883, where it handles such errors. Look at the stack trace printed in the console and click on the function call right before onError (it says check).

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.