0

I'm trying to get admin store configuration (core_config_data) in mincart.js file. Is there any method to get this ? like

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

eg:

config.getBaseUrl or something.. I searched a lot but I couldn't find out anything...
1

You need store configuration values in minicart.js. You can get it like this.

I will just try to get store name in minicart.js.

Add below code in minicart.phtml file

<script>
   window.getStoreName = '<?php /* @escapeNotVerified */ echo $block->getStoreName(); ?>'
</script>

Now for minicart.phtml we can use block Magento\Checkout\Block\Cart\Sidebar so maybe you will need to rewrite it in your custom module. But main thing is that we need to add a function in this class.

Add this in Sidebar.php

public function getStoreName()
{
     return $this->_scopeConfig->getValue(
                'general/store_information/name',
                \Magento\Store\Model\ScopeInterface::SCOPE_STORE
     );
}

Now you can use window.getStoreName in minicart.js to get store name from the admin configuration.

For example - minicart.js

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

    var sidebarInitialized = false,
        addToCartCalls = 0,
        miniCart;

    miniCart = $('[data-block=\'minicart\']');

    console.log(window.getStoreName); // you will have store name here
    ...

This is just an example to get store name so you can change it depending on what configuration value you want.

  • I'm struggling to override minicart.phtml file. So that's the reason I trying to different approach. All I need is I need to get some store config values in content.html. The content.html is loading from mincart.js. – Elavarasan Jan 30 at 15:12

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.