Question

In Magento 2, is there a way to disable a module for a single store view only in front-end, like Magento 1? Because that's what happened to me.

I have this module named Vendor_XXX that loads several js files on checkout page and it's working fine on every store view except 1 certain store view. In that store view, the js files aren't loaded, making XXX not working at all on that store view.

There are several things I checked:

  • Configuration of XXX on that store view: it's enabled.
  • app/etc/config.php: Vendor_XXX is enabled.
  • js files of other modules are loaded just fine for that store view.

Why is my module not working on that store view and how to make it work? Any help is appreciated, Thanks!

Was it helpful?

Solution

The problem lies on the store's language which could contain special characters such as " ' \ /

Let's say you have these code in your phtml template:

<script>
    require([
        'theJsClassYouWantedToLoad',
        'mage/translate'
    ], function (theJsClassYouWantedToLoad, $t) {
        var test = $t('Some random text');
    });
</script>

For your default store with default language, it would become:

var test = 'Some random text';

But for French, it became:

var test = 'Some random text but with special character like '';

Can you see a syntax error in there? When you have syntax error in your js code, you can see the error message by using browser's inspector (console tab), but if the js code is in phtml template, it'll simply be removed. My best bet is that the code in <script></script> is what imported theJsClassYouWantedToLoad for the page, but since it was removed because of a syntax error, your js file won't be loaded. That explains why on other store, your js is loaded just fine, but it doesn't work on French store.

To resolve this, check your translation files, look for lines with special characters and escape them. For example, change this:

"Some random text", "Some random text but with special character like '"

to

"Some random text", "Some random text but with special character like \'"
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top