Magento allows adding patches to Composer in order to prevent modifications from being overwritten while updating the extension. To apply the patch using Composer, follow the guidelines below.
Please note that this instruction works only for patches applied to the vendor folder. Patches that are applied to the app folder can't be added to Composer.
Step 1. Navigate to the directory of your project via CLI.
Step 2. Run the below command to install package cweagans/composer-patches that allows you to patch modules:
composer require cweagans/composer-patches
Step 3. Edit the composer.json file and add the “extra” section with the subsequent information:
- Module name, which the patch is applied to:
⇾ "amasty/shopby"
- Title. We recommend specifying the title that contains the ticket ID where the patch was provided and a mini-description of the modification:
⇾ "390600: ILN can be enabled per store view"
- Path to patch. Usually, such patches are added to the "patches" folder in the root Magento:
⇾ "patches/390600.diff"
The expected outcome should resemble the following example:
"extra": {
"composer-exit-on-patch-failure": true,
"patches": {
"amasty/shopby": {
"390600: ILN can be enabled per store view": "patches/390600.diff"
}
}
}
If a patch affects multiple modules, you must create multiple patch files targeting multiple modules.
Further steps will differ based on what version of cweagans/composer-patches you have in your Magento environment.
For cweagans/composer-patches v.1.7.3 and older:
- Apply the patch with the command below (use the
-v option only if you want to see debugging information):
composer -v 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 cweagans/composer-patches v.2.0.0 and newer:
- Regenerate patches.lock.json file with your new patch:
- Reinstall patched dependencies with any defined patches:
- Update the
composer.lock file to update the content hash:
composer update --lock
If you encounter any difficulties, please do not hesitate to contact us for assistance.