My Cart 0

How to Apply a Patch to Your Magento 2 Store

If you’re unable to upgrade your extension but need to ensure your store continues to operate correctly, applying a patch via Composer is the recommended solution. Follow these steps to apply the patch manually.

 

  1. Install the composer patches package

    First, run the following command in the root of your Magento project:

    composer require cweagans/composer-patches

  2. Edit the composer.json file

    Open the composer.json file located in the root of your Magento installation. You’ll need to add the patch details to the existing extra object. Add the patch and specify the package(s) to which it should be applied. It should look like this:

    "extra": {

        "magento-force": "override",

        "composer-exit-on-patch-failure": true,

        "patches": {

            "magento/module-example": {

                "XX: Unable to save product with negative quantity": "patches/XX_module-example.patch"

            },

            "magento/module-ui": {

                "XX: Unable to save product with negative quantity": "patches/XX_module-ui.patch"

            }

        }

    }

  3. Apply the patch

    Run the following command to apply the patch:

    composer install
  4. Update the Composer Lock File

    Next, run the following command to update the composer lock file, ensuring that the patch is registered correctly:

    composer update <PACKAGE NAME>

    For example: composer update magento/module-catalog-inventory

    The composer lock file will track which patches have been applied to each composer package within the extra > patches_applied object.

  5. Commit and Push Changes

    After applying the patch, add the composer.json, composer.lock, and the newly added patch files (patches/***) to your version control system. Commit and push  the changes.

By following these steps, you can apply the necessary patch to ensure your store runs smoothly. If you encounter any issues, please feel free to reach out to our support team for assistance.

Report incorrect information

Still Have Questions?

Our customer care team is here for you!

Contact Us