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.

2 Answers 2

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!

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.

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.