1

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!

  • Have you checked those files in pub/static for that store view? They're all there or not? – Tailtiu Aug 30 at 13:55
  • No they aren't. I tried copying them to the corresponding location for the store view, but still not working. – Anryol Aug 30 at 14:09
  • Try php bin/magento setup:static-content:deploy <your_locale> -f – Tailtiu Aug 30 at 14:20
  • After a long wait, it's still not working and the module's js files in pub/static are still missing. – Anryol Aug 30 at 14:54
  • May I know if your store view is using default language or not? – Tailtiu Aug 30 at 15:27
0

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 \'"

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.