Video Lesson: Override a class using a preference in Magento

Override a class using a preference in Magento

This is premium content

Only available to enrolled or University students.
Join today to unlock all lessons in this course.

Override a class using a preference in Magento

Learn how to override a Magento class using di.xml class preference and disable plugins.

Lesson Content

Sometimes you wish to completely override a Magento class. This can be done using a class preference. This is useful if you can’t use a plugin, for example when the function you want to change is private or protected, or when you have many changes that would make plugins hard to follow.

Let’s say we want to prevent the event property from ever being created in the first place. We can do this by completely overriding the controller with our own class.

First disable the prevent post detail logger plugin. Do this by adding a disabled attribute equal to true on the plugin node.

Here...

Premium content

Enroll to unlock the full content and all course materials.

Maggie

Hey, I'm Maggie! πŸ‘‹

Ask me anything.

Want to chat with Maggie?

Enroll in this course for AI tutor access.

Comments

Join the discussion!

Comments

Want to comment on this lesson?

Enroll in this course to leave comments.