>3 Ways to Complete Magento 2 Disable Module Requests

3 Ways to Complete Magento 2 Disable Module Requests

5 min read

Here are 3 common ways to steal when it comes to a Magento 2 disable module task.

Check now.

#1. Magento 2 Disable Module Using Command-Line.

Magento already provides command-line utility to disable a module. 

php bin/magento module:disable Bss_PreOrder
sundayz$ php bin/magento module:disable Bss_PreOrder

The following modules have been disabled:
- Bss_PreOrder
 
Cache cleared successfully.
Generated classes cleared successfully. Please run the 'setup:di:compile' command to generate classes.
Info: Some modules might require static view files to be cleared. To do this, run 'module:disable' with the --clear-static-content option to clear them.

If the module depends on other modules, using the basic command line might not complete Magento disable module correctly which will have errors like this:

sundayz$ php bin/magento module:disable Magento_Checkout

Unable to change status of modules because of the following constraints:
Cannot disable Magento_Checkout because modules depend on it:
Magento_Store: Magento_Store->Magento_Catalog->Magento_Checkout
Magento_Directory: Magento_Directory->Magento_Backend->Magento_Customer->Magento_Checkout
Magento_Theme: Magento_Theme->Magento_Customer->Magento_Checkout
Magento_AdvancedPricingImportExport: Magento_AdvancedPricingImportExport->Magento_Customer->Magento_Checkout
Magento_Backend: Magento_Backend->Magento_Customer->Magento_Checkout
Magento_Eav: Magento_Eav->Magento_Catalog->Magento_Checkout
Magento_Customer: Magento_Customer->Magento_Checkout
Magento_Backup: Magento_Backup->Magento_Backend->Magento_Customer->Magento_Checkout
Magento_AdminNotification: Magento_AdminNotification->Magento_Backend->Magento_Customer->Magento_Checkout
Magento_Indexer: Magento_Indexer->Magento_Backend->Magento_Customer->Magento_Checkout
Magento_BundleImportExport: Magento_BundleImportExport->Magento_Catalog->Magento_Checkout
Magento_Search: Magento_Search->Magento_Backend->Magento_Customer->Magento_Checkout
Magento_CacheInvalidate: Magento_CacheInvalidate->Magento_PageCache->Magento_Backend->Magento_Customer->Magento_Checkout
Magento_Cms: Magento_Cms->Magento_Catalog->Magento_Checkout
Magento_Widget: Magento_Widget->Magento_Catalog->Magento_Checkout
Magento_CatalogImportExport: Magento_CatalogImportExport->Magento_Customer->Magento_Checkout
Magento_Catalog: Magento_Catalog->Magento_Checkout

To solve this, we need to use [-f] (force) flag in the command line.

sundayz$ php bin/magento -f -c module:disable Magento_Checkout

The following modules have been disabled:
- Magento_Checkout
 
Cache cleared successfully.
Generated classes cleared successfully. Please run the 'setup:di:compile' command to generate classes.
Generated static view files cleared successfully.
Alert: You used the --force option. As a result, modules might not function properly.

Come to think of Magento disable module, another problem occurs when you don’t clear static view content. This may bring issues such as there are various files with a similar name and you don’t clear all of them.

On the other hand, due to static file fallback rules, assume that you don’t clear static files and have more than one file with the same name, but different content and fallback rules will make the static view display incorrectly. To everything work well, make sure that [-c] or [–clear-static-content] is added to the command line.

php bin/magento --force --clear-static-content module:disable Magento_Checkout

Remember to read carefully the warning:

Alert: You used the –force option. As a result, modules might not function properly.

You can also check the status of all modules:

php bin/magento module:status

SAVE NOW To Read >>> Quick Guide to Install Magento 2 in Minutes

#2. Magento 2 Disable Module Manually

To disable a module manually, some changes have to be done at app/etc/config.php.

However, this way is not recommended because config.php was created automatically after the command:

php bin/magento setup:upgrade

It means that the next time you “upgrade” your Magento, config.php will be renewed and changed that you did will be no longer there.

Magento stores the flag value 0 or 1 of each module with the meaning of enabling or disabling:

1 means that the module is enabled.

0 means that the module is disabled.

So if you want to complete Magento 2 disable module, you need to change its value to 0.

Then you need to save it, flush cache to complete disabling the module.

Example:

Assume that this is your config.php file:

<?php
return array (
  'modules' => 
  array (
    'Magento_Store' => 1,
    'Magento_AdvancedPricingImportExport' => 1,
    'Magento_Directory' => 1,
    'Magento_Theme' => 1,
    'Magento_Backend' => 1,
    'Magento_Backup' => 1,
    'Magento_Eav' => 1,
    'Magento_Customer' => 1,
    'Magento_BundleImportExport' => 1,
    'Magento_AdminNotification' => 1,
    'Magento_CacheInvalidate' => 1,
    'Magento_Indexer' => 1,
    'Magento_Cms' => 1,
    'Magento_CatalogImportExport' => 1,
    'Magento_Catalog' => 1,
    'Magento_Rule' => 1,
    'Magento_Msrp' => 1,

In order to complete Magento disable module, Magento_Cms, you just need to change ‘Magento_Cms’ => 1, to ‘Magento_Cms’ => 0, save it, and flush the cache.

#3. Magento 2 Disable Module Output Using Back-end Configuration

This is the easiest solution to a Magento 2 disable module and this seems convenient for non-developer users.

However, this way does not actually disable your extension but rather disabled the display block output defined or outputted by the module.

If there are no blocks used by the module, this option is useless. Let’s take an example: “if your module called directly from template, you disable module output, the module still works.”

By navigating in the Magento Backend to Stores => Configuration => Advanced => Disable module output

magento-configuration-tab

 magento-configuration-details

Find the module that you want to disable then choose “Disable”. After that, click “Save Config”, flush your cache and the module is “disabled”.

We have done with Magento 2 disable module tutorial. We hope it helps!

EXPLORE NOW more built-in solutions from BSS Commerce:

We are one of the leading Magento extension providers and web development services in the world. With experienced and certified Magento developers, we commit to bring high-quality products and services to optimize our business effectively. Let us know about your problems. We are willing to support you every time.

< Previous Post
Next Post >