0

I want to add a class in parent div if minicart/cart is empty and remove same class if minicart/cart has an item(s).I made changes in minicart.phtml. below is my code for that.

<div class="block block-minicart"
data-bind="css: { emptyBag: !!getCartParam('summary_count') == false }
                 data-role="dropdownDialog"
                 data-mage-init='{"dropdownDialog":{
                    "appendTo":"[data-block=minicart]",
                    "triggerTarget":".showcart",
                    "timeout": "2000",
                    "closeOnMouseLeave": false,
                    "closeOnEscape": true,
                    "triggerClass":"active",
                    "parentClass":"active",
                    "buttons":[]}}'>

I have added data-bind="css: { emptyBag: !!getCartParam('summary_count') == false }" peace of code to check if cart is empty or not. but when i check console it's giving me an error of getCartParam is not defined. Please help, I have worked on magento but new in KO so facing problem in that

1

You cannot add the css to this div because it was not init under scope: 'minicart_content'

So a work around as you can add the class to the div id minicart-content-wrapper and add the scope minicart_content to the div class block block-minicart

<?php if ($block->getIsNeedToDisplaySideBar()): ?>
    <div class="block block-minicart"
         data-bind="scope: 'minicart_content'"
         data-role="dropdownDialog"
         data-mage-init='{"dropdownDialog":{
            "appendTo":"[data-block=minicart]",
            "triggerTarget":".showcart",
            "timeout": "2000",
            "closeOnMouseLeave": false,
            "closeOnEscape": true,
            "triggerClass":"active",
            "parentClass":"active",
            "buttons":[]}}'>
        <div id="minicart-content-wrapper" data-bind="css: { emptyBag: !!getCartParam('summary_count') == false }, scope: 'minicart_content'">
            <!-- ko template: getTemplate() --><!-- /ko -->
        </div>
        <?= $block->getChildHtml('minicart.addons') ?>
    </div>
<?php endif ?>

Hope it help

  • yes i got that but is this possible to add class in block block-minicart div..? – Karan Adhikari Dec 6 '18 at 9:11
  • i got the solution, but thanks for your help i really appreciate – Karan Adhikari Dec 6 '18 at 9:25
  • @KaranAdhikari Can you please tell me which solution is work for you ? – Sanjay Gohil Jan 26 at 11:44

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.