1

I wanted to overrid:

vendor/magento/module-catalog/Model/ResourceModel/Product/Compare/Item/Collection.php

so I copied it to:

app/code/Magento/Catalog/Model/ResourceModel/Product/Compare/Item/Collection.php

But the override is not working.

Please let me know how I can override it without creating a new module.

Thank you!

1

This won't work. I can't imagine any way to do it without the custom module, there are several clean ways, though, depending what you exactly want. Most wanted is using plugin pattern: Plugins docs

Another manner is using observer pattern if the feature you want to rewrite dispatches some events. More: Observer docs

Finally, if neither plugins nor observers suits your case you can use preference, which helps you to replace whole class. More: Preference tutorial

| improve this answer | |
  • Thank you. You are right, cannot be done without custom module. I created custom module and used "preferences" method. – Abid Malik Dec 19 '17 at 10:18

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.