I'm trying to override the next files:

  • vendor/magento/module-backend/Block/Dashboard/Sales.php
  • vendor/magento/module-reports/Model/ResourceModel/Order/Collection.php

What path I need to create in a Module to override those files?

I tried

  • app/code/Vendor/Module/Block/Dashboard/Sales.php
  • app/code/Vendor/Module/Magento_Backend/Block/Dashboard/Sales.php
  • app/code/Vendor/Module/Model/ResourceModel/Order/Collection.php
  • app/code/Vendor/Module/Model/Magento_Reports/ResourceModel/Order/Collection.php

none work.


1 Answer 1


This is about magento 2 basics, and as it might seems confusing when you start learning it...it end up being quite easy to deal with.

What you need to get information about is di.xml while (di lands for dependency injection). In that file you will be able to specify things like preference and plugin among other things which are 2 way to extend a core functionality.

Before and After plugin are meant to add a peace of logic at the start or the end of a method. While preference are more like being overriding the whole class; which seems like what you are trying to do here.

here is an exemple of existing preference

<preference for="Psr\Log\LoggerInterface" type="Magento\Framework\Logger\LoggerProxy" />

The for argument takes the class you want to override and the type argument take the class you are overriding it with. The class name and path by itself in type is irrelevant but it's common to re-use the same path as the core class.

Then your custom class is nothing special, just be careful about using or not extend if you need it. Be also aware that extending private methods or attributes won't work and you will have to define them again.

  • Thanks! very clear and explained.
    – carlos
    Jan 29 at 18:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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