0

As I've checked in Magento 2.3.1 Sales module there is one hardcoded Factory file in below path:

vendor/magento/module-sales/Model/ResourceModel/Order/CollectionFactory.php

And in Cms module there is no Factory file available

vendor/magento/module-cms/Model/ResourceModel/Block/Collection.php

I've read concept regarding factories which are automatically generated but I was surprised when I saw hardcoded Factory file. So just wanted to know the reason behind it.

0

I am not dam sure why Magento use hardcoded Factory class but I think they need to use hardcoded factory class because of while installing default Magento they need to set default data like order, system config data, reports or any other data to display default value in fresh Magento.

I have checked and see that vendor/magento/module-sales/Model/ResourceModel/Order/CollectionFactory class impliment CollectionFactoryInterface and that interface Create class instance with specified parameters. see the below diagram.

diagram

Below are some the hardcoded factory class.

  • Magento\Reports\Model\ResourceModel\Quote\CollectionFactory

  • magento/module-sales/Model/ResourceModel/Order/CollectionFactory

See refrance link.

I hope it helps!

| improve this answer | |
0

I reckon if you delete and let magento generate factory class you will be missing some functionality. Therefore this was done for no reason other that it served the purpose of edits made to the file.

Even with the best intentions sometimes rules need to be broken.

| improve this answer | |

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.