Magento version: 2.0.0

I copied the Magento_Checkout file to my custom vendor directory and renamed it, but the block and layout are not working for me when i modified some files.

How to overwrite them?

need to change the di.xml?

i just copied it.

1 Answer 1


In the following explanation I use the {...} notation to indicate placeholders you have to substitute with your own values.

Assuming you have created your own {magedir}/app/code/{Vendor}/{Module} (or {magedir}/vendor/{Vendor}/{Module} if you use composer) - from now on let's call it {yourmoduledir} - containing the {yourmoduledir}/etc/module.xml activation file you have to:

1) Define a preference

Create {yourmoduledir}/etc/di.xml with following content:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
  <preference for="Magento\Checkout\Controller\{TheActionClassYouWantToOverride}" type="{Vendor}\{Module}\Controller\{TheActionClassThatContainTheOverride}" />

2) Define your route

Create {yourmoduledir}/etc/frontend/routes.xml with following content:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
    <router id="standard">
        <route id="{YourRouteId}" frontName="{YourRouteFrontName}">
            <module name="{Vendor}_{Module}" />

3) Create the Action class (a.k.a. Controller) that contains the override

Create {yourmoduledir}/Controller/{TheActionClassThatContainTheOverride}.php

namespace {Vendor}\{Module}\Controller;

class {TheActionClassThatContainTheOverride} extends \Magento\Checkout\Controller\{TheActionClassYouWantToOverride}
    public function execute()
        // your code here

4) Update environment

Once all the above configuration and classes file are created, run the following commands from {magedir}:

# Enable module
bin/magento module:enable {Vendor}_{Module}

# Update config
bin/magento setup:upgrade

# In Production mode you need to generate plugin classes
bin/magento setup:di:compile

# Flush cache
bin/magento cache:flush

Hope it helps.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.