How to Replace Spryker Bundle Dependencies

Spryker Dependencies

This article describes how to identify bundle dependencies and replace a dependent bundle with another one.

Each Spryker bundle might have several dependent bundles that provide communication, utilities and added functionality. Usually adjustments are done via our plugin mechanism or via class extensions. However, when introducing a massive functional change, you may need to replace an entire core bundle with one of your own (or a 3rd party). To do so, there are two steps that you need to follow. Firstly, you will need to replace the bundle and secondly, connect the bundle to the new functionality.

For example:
A company working with the Payone and Refund bundles decides they want to use a different refund functionality. They can replace the core refund bundle with their own implementation that satisfies the same interface..This requires that they first replace the existing refund bundle with a new refund implementation in project code. Then, they will have to reroute the Payone bundle to communicate with the new refund functionality instead.

In the example above we assume that you know exactly what core bundle you want to replace. If that is not the case, you will first need to know what are the core bundle’s dependencies. You can find this information in a bundle’s composer.json file. This file lists all the dependent components and can be used to locate the dependent functionality that you want to replace, based on your project’s requirements.

To replace a bundle with another bundle:
The following process describes adding a replace command into a new bundle to indicate that it replaces a core bundle.

  1. For each bundle that you want to add:
    • Replace the old bundle with the new one by creating a dummy bundle repository in a directory accessible to composer.
      • Name or rename the new bundle by using the old bundle’s name and prefixing it with replace_.
        For example, create a dummy file called replace_refund to replace the refund bundle. This will help to keep track of any relplaces you do in the project.
      • In the newly created dummy bundle directory create an empty composer.json file and add the following configuration information.
      • Add the newly created bundle to your project’s composer.json file by going to shop/composer.json and adding the new location.
      • Check if the core bundle is in your project’s composer.json file and if it is, remove it.

    Note: For more information on using the composer replace command click here.

  2. Execute composer update with the replace bundle name: composer update “replace_<the name of the bundle you are replacing>” Running composer update will remove all mentions of the dependent bundle (for example: refund) and replace it with your bundle (for example: replace_refund’).

Composer configuration information

     "name": “<vendor>/ replace_<the name of the bundle you are replacing> ",
     "replace": {
       "spryker/<the name of the bundle you are replacing> ":"*"
     "description": “<add_decription_of_what_you_are_replacing>"

If you added a replace bundle, Go to shop/vendor and check that composer added the new replace_ bundle/s to this directory.

To check this worked:
Go to shop/vendor/spryker and check that composer removed the bundles that needed to be replaced from the directory.

The next step is to connect the bundle with your new functionality.

Setting up a connection with the new functionality

Now that we have replaced a core bundle with a different bundle, we need to connect the rest of the Framework to this new bundle.

  • To set up connectivity, check the replaced bundle’s usage and adapt its logic to the new bundle.

For further assistance on project level implementations, email us.