Extending a Core Module That is Used by Another

Edit on GitHub

This topic describes how to extend a core module that is used by another core module.

Extra consideration must be taken when extending core modules that are already in use by another module.

In the following example, we will extend the Cart -> Calculation modules.

Step 1: Modify the Interface

Add a foo() method to CalculationFacade on the project level and call it from the Cart module.

The CalculationFacade needs to implement the CartToCalculationInterface because this interface is used in the Cartmodule.

You can also add your own interface as follows:

namespace Pyz\Zed\Cart\Dependency\Facade;

use Spryker\Zed\Cart\Dependency\Facade\CartToCalculationInterface as SprykerCartToCalculationInterface;

interface CartToCalculationInterface extends SprykerCartToCalculationInterface
    public function foo();

Step 2: Add the New Method to the Interface

The interface needs to extend the one from core.

namespace Pyz\Zed\Calculation\Business;

use Pyz\Zed\Cart\Dependency\Facade\CartToCalculationInterface;
use Spryker\Zed\Calculation\Business\CalculationFacade as SprykerCalculationFacade;

class CalculationFacade extends SprykerCalculationFacade implements CartToCalculationInterface
    public function foo()
        die('<pre><b>'.print_r('!!', true).'</b>'.PHP_EOL.__CLASS__.' '.__LINE__);


Step 3: Remove the Bridge

In the Cart module’s dependency provider, remove the bridge to directly use the facade.

class CartDependencyProvider extends SprykerCartDependencyProvider

public function provideBusinessLayerDependencies(Container $container)

	$container[self::FACADE_CALCULATION] = function (Container $container) {
		return $container->getLocator()->calculation()->facade();
Bridges are for core-level only. If you use them at the project-level, you are doing it wrong!
The described case is only practical when you are “between” two core-bundles and you want to make it right. For you own modules, use the general module-interface (e.g. `MyModuleInterface`).