In Daily Operations, We Rely on Various External Modules, Files, and Solutions Declared in the composer.json file and Installed in the Vendor Directory in Magento. However, When Confronted with Broken Packages or Security Vulnerabilities, Addressing the Issue Might Not Be Straightforward, Especially When There Are Extensive Dependencies Involved.
Times like these where git patches comes to the rescue for Magento 2 git patch.
Table of Contents
How to create a patch
- 1- Install package for managing patches in composer:
composer require cweagans/composer-patches
This package empowers you to effectively oversee patches within your project. With it, you can effortlessly add new patches, modify existing ones, and remove outdated ones. Its user-friendly design ensures easy usage, and it’s entirely written in PHP for seamless integration.
- Create a
patches/composer
directory in your local project. - File to changed should be added to the git
git add -f vendor/dotmailer/dotmailer-magento2-extension/Api/Data/CouponAttributeInterface.php
- After making the changes run
git diff vendor/dotmailer/dotmailer-magento2-extension/Api/Data/CouponAttributeInterface.php > patches/composer/webapi-fix.patch
- Next, you need to remove the file from git
git reset head vendor/dotmailer/dotmailer-magento2-extension/Api/Data/CouponAttributeInterface.php
How to apply a magento 2 git patch
Ready patch is already in your project. Now it is time to let the composer know that it needs to be installed. Open composer.json file and find object “extra”. Here you have to add those lines:
"extra": {
"patches": {
"dotmailer/dotmailer-magento2-extension": {
"patch description": "patches/composer/webapi-fix.patch"
}
}
}
If the patch and edited composer.json file are ready, we can finally install the magento 2 git patch!
composer install
Update the composer.lock
file. The lock file tracks which patches have been applied to each Composer package in an object.
composer update --lock
For more information, you can consult the magento documentation https://experienceleague.adobe.com/docs/commerce-operations/upgrade-guide/patches/overview.html?lang=en
You can also check out an article about the best seo extension for magento.