developer
March 3, 2025
Magento 2 provides a robust way to customize its core functionalities without modifying the core files. One of the most common methods used for customization is Preferences (also known as Virtual Types). However, when working on a Magento 2 project, you might need to find which core files have been overridden using preferences.
In this blog, we will discuss how to find overridden files using preferences in Magento 2 and the best practices for handling them.
grep -r "<preference" app/code/ vendor/
To display the block on a page, define it inside a layout XML file. Create default.xml inside Vendor/Module/view/frontend/layout/:
php bin/magento dev:di:info "Magestore\Webpos\Helper"
Below Image Shows the Preference for Magento\Sales\Model\Order\Email\Sender\ShipmentSender which is overwritten by Mageride\ClickandCollect\Model\Order\Email\Sender\ShipmentSender
Conclusion
Finding overridden files using preferences in Magento 2 is essential when debugging customizations or conflicts. By searching the di.xml files, using Magento CLI, inspecting generated code, and applying debugging techniques, you can easily identify and manage overridden classes. However, always consider using Plugins instead of Preferences for better maintainability.
By following these best practices, you can ensure a smooth and conflict-free Magento 2 development experience.
Need Help with Magento Development?
If you’re facing issues with Magento 2 customizations or need expert assistance, feel free to reach out! Our team of Magento specialists is here to help.
Contact us today to learn more about how we can turn your vision into reality and take your business to the next level!