Overriding BaseFrontEndController in Craft Commerce Is there a clean way to alter the cartArray that is returned when updating the cart through ajax? Which is defined in the BaseFrontEndController Craft Commerce.

For example by using a module? In this question Override a model method via plugin, Yii 2 dependency injection support is mentioned, but I feel like I need someone to point me into the right direction.

Thank you!
The most easiest solution in Your case is to create a custom Controller that extends the default BaseFrontEndController to call that one. The issue for Dependency Injection is the following piece of code:

For example when you do

Craft::$container-&gt;set('craft\controllers\EntriesController', [
    'class' =&gt; 'prefix\namespace\controllers\FooController'
]);


You would overwrite the default EntriesController with your custom one and the function createControllerByID would do the following

if (is_subclass_of($className, 'yii\base\Controller')) {
    $controller = Yii::createObject($className, [$id, $this]);
    // $controller is now my custom prefix\namespace\controllers\FooController instead of the default

    // but the line below -&gt; get_class($controller) === $className won't match
    return get_class($controller) === $className ? $controller : null;
}


Thus you'll receive an exception, it will work with most other classes/services/components that are created with Yii::createObject but not with Controllers. To change that behavior you would have to replace the createControllerByID in yii\base\Module

Just do as Brad Bell already said and create a custom controller.