Magento 2 Performance Boost: How to Safely Remove Unwanted Payment Gateways Like Braintree and Mollie
Optimizing Magento 2: Shedding Unwanted Payment Modules for Better Performance
In the world of e-commerce, every millisecond counts for site speed and user experience. A common challenge faced by Magento 2 merchants and developers is the presence of default modules that, while potentially useful for some, can become unnecessary bloat for others. This GitHub issue highlights a pertinent problem: the default installation of payment gateways like Braintree and, in some cases, Mollie, even when they are not actively used.
The Problem: Unused Modules and Their Hidden Costs
The issue, raised by user 'fabotha', details how Braintree and Mollie, when not in use, consume valuable system resources, inflate the static file size, and even spam the system.log with recurring error messages. Specifically, Braintree was reported to generate 'Braintree\Configuration::merchantId needs to be set' errors every few seconds, contributing to log bloat and making debugging harder. The larger static file size directly impacts page load times, which in turn can negatively affect Google search rankings and overall user experience.
The core request was for an installation option to exclude these modules by default, aiming for a leaner, faster Magento instance with fewer resources consumed and cleaner logs.
The Community Solution: Leveraging Composer's 'Replace' Directive
While the initial request was for a core Magento installation option, the community, particularly 'hostep', quickly provided an actionable workaround using Composer – Magento's dependency manager. It was clarified that Braintree is bundled within the adobe-commerce/os-extensions-metapackage, a meta-package that pulls in several other modules. Mollie, on the other hand, is typically not a core Magento module but often comes bundled with third-party themes like Hyvä (e.g., hyva-themes/magento2-mollie-theme-bundle).
The elegant solution involves using Composer's replace directive in your project's composer.json file. This trick tells Composer that your project 'replaces' a certain package, effectively preventing it from being installed or removing it if it's already present. This is crucial for optimizing your Magento 2 environment.
How to Remove Braintree and Mollie:
To remove Braintree (and other modules from the meta-package) and Mollie (if using the Hyvä bundle), you would add the following to your composer.json file:
"replace": {
"adobe-commerce/os-extensions-metapackage": "*",
"hyva-themes/magento2-mollie-theme-bundle": "*"
}After modifying your composer.json, run the following Composer commands:
- For Braintree:
composer update adobe-commerce/os-extensions-metapackage - For Mollie (if applicable):
composer update hyva-themes/magento2-mollie-theme-bundle
Finally, run bin/magento setup:upgrade to update your app/etc/config.php and complete the module removal process.
Why This Matters for Magento Users and Migrations
This discussion highlights a critical aspect of Magento 2 management: the power of Composer. For merchants looking to optimize their store's performance, reduce hosting costs, and streamline their development environment, understanding how to manage dependencies is key. For those undergoing Magento migrations, cleaning up unnecessary modules before or during the migration process can significantly reduce complexity and improve the performance of the new store.
While 'fabotha' initially sought an 'uninstall' process, 'hostep' clarified that the Composer 'replace' method is indeed the way to effectively remove these packages from an existing installation, not just prevent their initial installation. This underscores the importance of having a Magento developer with Composer expertise on hand for such customizations.
The issue was ultimately closed as 'not much to do in core Magento' given the effective Composer workaround, reinforcing the community-driven nature of solutions within the Magento ecosystem.