1

I managed to hide the chekout button using a custom module. I followed this threads to achieve this. I can hide the checkout button in mini cart now.But i want to add some condition to show the Proceed to Checkout button. Where i want to pass the cart total value to minicart.js file in my custom module.

Below are the steps i tried

(app/code/Ayakil/app/code/Vendor/Module/etc/di.xml/etc/di.xml).

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\Checkout\Model\DefaultConfigProvider" type="Ayakil\MinicartCustomization\Model\DefaultConfigProvider" />
</config>

My DefaultConfigProvider.php ( app/code/Ayakil/MinicartCustomization/Model/DefaultConfigProvider.php )

<?php
namespace Ayakil\MinicartCustomization\Model;

use Magento\Store\Model\ScopeInterface;
use Magento\Framework\Session\SessionManager;

class DefaultConfigProvider extends \Magento\Checkout\Model\DefaultConfigProvider
{
private $coreSession;
public function __construct(
    SessionManager $sessionManager
) {
    $this->coreSession = $sessionManager;    
}

public function getConfig()
{
    $output = parent::getConfig();
    if($this->coreSession->getVIErequestData()){
        $output['session_VIEUserData'] = true;
    }else{
        $output['session_VIEUserData'] = false;
    }

    return $output;
}
}

my minicart-mixin.js file like below.

define([
'uiComponent',
'Magento_Customer/js/customer-data',
'jquery',
'ko',
'underscore',
'sidebar',
'mage/translate',
'mage/dropdown'
], function (Component, customerData, $, ko, _) {
'use strict';

var mixin = {
    isButtonEnable: function () {
        /*You can add your condition here based on your requirements.*/
        console.log(window.checkoutConfig.session_VIEUserData);

        return false;
    }
};

return function (target) {
    return target.extend(mixin);
};
});

In my minicart-mixin.js file if i try to access like console.log(window.checkoutConfig.session_VIEUserData); i am getting an error.

TypeError: window.CheckoutConfig is undefined

My question is how can i pass a variable to minicart-mixin.js and access the data?

7
  • Follow this solution if this will help you link Commented Feb 5, 2020 at 11:28
  • i followed this too, BUt still i am getting the same error.
    – Mujahidh
    Commented Feb 5, 2020 at 11:29
  • You follow all the steps ? Commented Feb 5, 2020 at 11:29
  • yes, i just want to access the varibale in mixin.js?
    – Mujahidh
    Commented Feb 5, 2020 at 11:31
  • 1
    @KishanSavaliya i followed both of your 2 answers and complete that task
    – Mujahidh
    Commented Feb 5, 2020 at 11:31

2 Answers 2

0

If you want to use Cookie value in condition then try to replace your minicart-mixin.js content with below code.

define([
    'uiComponent',
    'Magento_Customer/js/customer-data',
    'jquery',
    'ko',
    'underscore',
    'sidebar',
    'mage/translate',
    'mage/dropdown',
    'jquery/jquery.cookie'
], function (Component, customerData, $, ko, _) {
    'use strict';

    var mixin = {
        isButtonEnable: function () {
            /*You can add your condition here based on your requirements.*/
            var check_cookie = $.cookie('foo');

            if(check_cookie == 'something'){
                return true;
            }else{
                return false;
            }
        }
    };

    return function (target) {
        return target.extend(mixin);
    };
});

Hope this will help you!

0

Try to add just your value and access in js file. Replace this below code in your function :

app/code/Ayakil/MinicartCustomization/etc/frontend/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
   <type name="Magento\Checkout\Model\CompositeConfigProvider">
       <arguments>
           <argument name="configProviders" xsi:type="array">
               <item name="additional_provider" xsi:type="object">Ayakil\MinicartCustomization\Model\DefaultConfigProvider</item>
           </argument>
       </arguments>
   </type>
</config>

and then, modify this below function code in your file :

public function getConfig()
{
    $output = [];
    if($this->coreSession->getVIErequestData()){
        $output['session_VIEUserData'] = true;
    }else{
        $output['session_VIEUserData'] = false;
    }

    return $output;
}
6
  • what do you mean by "your value"? Are you referring to console.log(session_VIEUserData);
    – Mujahidh
    Commented Feb 5, 2020 at 11:20
  • 1
    I mean remove $output = parent::getConfig(); and add $output = []; Commented Feb 5, 2020 at 11:20
  • still same issue
    – Mujahidh
    Commented Feb 5, 2020 at 11:35
  • check my updated answer. Commented Feb 5, 2020 at 11:41
  • how can access this value in mixin.js?
    – Mujahidh
    Commented Feb 5, 2020 at 11:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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