Questions tagged [factory]

Denotes questions related to Magento 2 factories.

Filter by
Sorted by
Tagged with
1
vote
0answers
35 views

How to resolve Circular Dependency when one Helper class is depends on other Helper Class

Having one module named Override\Search in which two helper classes are there. 1. Override\Search\Helper\Data.php 2. Override\Search\Helper\Util.php Both helper are depends on each other, thus ...
0
votes
0answers
25 views

Classes *Factory from generated/ directory isn't use and look for them in vendor directory. Magento2.3

I'm using Magento\Catalog\Model\CategoryFactory in my module and in unit tests. Unit tests doesn't pass because CategoryFactory doesn't exists. Class CategoryFactory exists in generated directory and ...
4
votes
2answers
147 views

Magento 2: When should we use a ProductRepository, ProductFactory, Product model?

When should we use a ProductRepository, ProductFactory, Product model? vendor/magento/module-catalog/Model/Product.php vendor/magento/module-catalog/Model/ProductRepository.php generated/code/...
0
votes
2answers
48 views

Why does magento 2 use hard coded “Factory” class?

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 ...
0
votes
1answer
23 views

Why magento2 outputs the query while showing data from ResourceModel collection Factory..?

protected $productCollectionFactory; public function __construct( ..... \Custom\MyModule\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory, ... ) { ...
2
votes
1answer
23 views

factory class duplicate insert check in magento2

I have created a model class as like below. Vendor\Module\Model/Bulider.php namespace Vendor\Module\Model; use Magento\Framework\Exception\QualificationException; class Builder extends \Magento\...
2
votes
3answers
173 views

Magento2 Alternate of Method getCollection() which is deprecated

I have checked the similar post: Magento2.2 getCollection from Factory deprecated But I still don't find the answer of it. I am calling getCollection() function, and PHPStorm saying that this ...
0
votes
1answer
39 views

Recevied Empty array after using getItemsByColumnValue() collection method

I'm trying to retrieve a row from a custom table named 'lmap_shipping_tablerate' using a specific value for a column postcode. An empty array is returned when following line is used in my ...
1
vote
2answers
122 views

How to update record using multiple conditions in CollectionFactory magento 2

I am trying to update the record but it creates a new record. Collection factory <?php namespace Webkul\Mpquotesystem\Block; use Webkul\Mpquotesystem\Model\ResourceModel\Quoteconversation; ...
1
vote
0answers
84 views

Magento 2.3.1 Download an excel file with PHPSpreadsheet

Trying to create a download button for an Xlsx file. Using PHPSpreadsheet for this however when downloading the file it seems corrupted with a stack trace at the bottom of excel files: Stack trace: #...
0
votes
0answers
118 views

Magento 2.3 collection factory not exist

I use magento 2.3 and I can't see collectionFactory created in generated folder or inject to any class. ModelFactory can create normally. There are my code: Model file: <?php namespace Lights\...
1
vote
1answer
814 views

Magento 2 :Get country code from Country Name

I have the country name with me. How can I get corresponding country code from it. For ex: If the country name is Unites States, I want to get country code from it ie, US If there any way for it? I ...
0
votes
1answer
33 views

What is Factory in Magento2 and Why use? [duplicate]

What is Factory in Magento2? Why use this. I want to know more details about Factory. When we can use Factory.
0
votes
1answer
31 views

RewardspointsFactory class does not exist

Please anyone review my code. Facing this error. Exception #0 (ReflectionException): Class Sugarcode\Test\Model\ResourceModel\Test\RewardspointsFactory does not exist Exception #1 (ReflectionException)...
1
vote
1answer
21 views

GridFactory getting generated into wrong location

I have a custom module with backend management. I have an observer on config save that uses the file upload to read submitted file to update the collection however this fails due to below; class \My\...
1
vote
1answer
29 views

Magento 2: How to see the exact error

There are two parts to this question. 1. How can we add data to the database using factory not through object manager? 2. How can we find exactly what is the error in the code (dev mode is active, ...
2
votes
2answers
125 views

Magento 2 Get Product ViewCount Value By Factory

Trying to get most viewed product view count value, I need to use it in another method calculations. E.g.(if most viewed product view count value is 100 then I need this value to be returned) What am ...
7
votes
5answers
1k views

What is the use of pagefactory in Magento 2?

Although I refer some blog of pagefactory, I don't understand the use of page factory. There is one code in the controller. Could you please explain to me how it works? public function execute() { ...
0
votes
1answer
45 views

Magento 2.2.2 - Class not found in Factory

Namespace/Modulename/Model/WebService/ClientFactory.php <?php namespace Namespace\Modulename\Model\WebService; use Magento\Framework\ObjectManagerInterface; use Namespace\Modulename\Model\...
0
votes
2answers
117 views

Magento2 Model not loading complete data using Factory

Below is my construct function of controller - public function __construct( \Magento\Framework\App\Action\Context $context, \Magento\Framework\Registry $coreRegistry, \Vendor\...
1
vote
0answers
39 views

productCollectionFactory load function gives data in query but not in object

I have created a collection factory $collection = $this->_productCollectionFactory->create() ->addAttributeToFilter('status', '1') ->addAttributeToFilter('featured'...
3
votes
2answers
81 views

Magento 2.2.5: Add Student Instead of Update Student

So instead of update the student, this code add a new student. I'm looking for a way that not using object manager, because the objectmanager is recommended not to use. So when i searching for how to ...
0
votes
3answers
746 views

Magento 2.2.5: Exception #0 (InvalidArgumentException): Invalid return type

i'm doing update "students" on magento 2.2.5 and i'm stuck in how to get student data by id the error say: 1 exception(s): Exception #0 (InvalidArgumentException): Invalid return type here is my ...
0
votes
1answer
34 views

Magento 2.2.5: How to get something (students,teachers,products) by id

i'm doing update "students" on magento 2.2.5 and i'm stuck in how to get student data by id i saw they use repository to load by id, but when i come in this file C:\xampp\htdocs\magento\vendor\...
-2
votes
2answers
50 views

Class Factory doesn't exists

I am after this course https://www.mage-world.com/blog/grid-and-form-in-magento-2-admin-panel-part-1.html but my magento version is 2.2.5 so its a little bit different. i create NewsFactory auto by ...
5
votes
2answers
672 views

Difference between Session and SessionFactory in Magento 2

While working i found there are two methods of getting customer data using two session classes 1.) \Magento\Customer\Model\SessionFactory $customerSession 2.) \Magento\Customer\Model\Session $...
1
vote
2answers
184 views

Magento 2.1 - Memory Leak in my getCollection function

So I'm creating a really simple module to read from a custom table. Nothing fancy, table has two rows: +-----------+--------------+ + status_id + status_label + +-----------+--------------+ + 1 ...
1
vote
1answer
209 views

MEQP Gives a Warning : Data load getFirstItem() method detected in loop

I want to get the First item from the collection so I have used following code. But it gives some warning on the usage of getFirstItem() protected $_sampleFactory; public function __construct( \...
0
votes
1answer
346 views

Why Magento 2.2.3 returns empty collection?

I don't have any prior experience in this. I want to fetch the products from Database. I am trying from past few hours.But not working. I am using following code. protected $...
0
votes
1answer
129 views

How to create mock for factory classes?

In unit testing I want to create mock object for factory classes e.g. $this->getMockBuilder(\Magento\Framework\Controller\Result\RawFactory::class)->disableOriginalConstructor()->getMock(); but I ...
0
votes
2answers
21 views

How do I add products to the page.phtml?

I have an array with the product ID in my block, how do I get the product list on the page like this:
4
votes
1answer
2k views

difference between collection and collectionFactory

I need the list of all the admin users. And, both the below set of codes, provide the same result. Code 1 public function __construct( \Magento\User\Model\ResourceModel\User\Collection $...
3
votes
1answer
107 views

Magento 2 - Empty arguments in adapter __construct()

I am creating an adapter for a third party module by following the Magento_Braintree structure. In the Braintree module, they have a factory BraintreeAdapterFactory that creates an adapter ...
0
votes
1answer
906 views

In Repository, how to replace deprecated load() function?

I know we should use service contracts(Repository) over $model->load(), but in Repository itself, how to replace the deprecated load() function? For example, in Magento\Cms\Model\PageRepository, ...
1
vote
2answers
6k views

Get Region Id given Region Code and country id

I need to get the region_id given the region_code and the country_id, but I cannot manage to achieve it. I've tried using the countryFactory and the regionFactory, but i do not understand what i'm ...
1
vote
2answers
407 views

How does getInvoiceCollection() work with orderCollectionFactory in Magento 2?

The following code works but how can we identify what methods can be called on the order collection result, such as getInvoiceCollection? $collection = $this->orderCollectionFactory->create() ...
0
votes
1answer
363 views

Factory create model is not empty Magento 2

I use a custom model with it's own Factory. In my helper in the construct public function __construct( \Company\Module\Model\ResourceModel\Communication\CollectionFactory $communicationFactory ){ $...
1
vote
1answer
169 views

Fetch a specific model in magento 2

I have 2 ways to fetch a model object: $orderId = 18; /** @var \Magento\Sales\Model\Order $firstOrder */ $firstOrder = $this->_orderFactory->create()->load( $orderId); /** @var \Magento\...
1
vote
1answer
35 views

In Magento 2, what classes should be instantiated with a factory and what not?

Magento 2 has a big 'depend on abstractions, not concretions' philosophy. One example of this is the use of Factories. Automatically generated factories. But I'm wondering: from a software ...
3
votes
1answer
859 views

Magento2: What is the best practice to get collection

I know it is not a good practice to use objectManager to get collection. However, I don't know what is the advantage of using ModelFactory ($this->mymodelFactory->create()->getCollection()) ...
4
votes
1answer
2k views

Magento2: Difference between Factory and Repository

What is the difference between these two objects in magento2? (Factory and Repository) I have seen that they have almost the same methods. What proper use does one have?
1
vote
1answer
3k views

Model class not found in …/magento/framework/ObjectManager/Factory/AbstractFactory.php:93

When I try to load collection via getCollection method in my custom Block, I get this error in apache2 log. The complete error is: [Mon May 08 09:53:53.485661 2017] [proxy_fcgi:error] [pid 1996:...
2
votes
1answer
108 views

How to override UpgradeData.php with Factory?

I need to override the UpgradeData Class from Catalog\Setup\UpgradeData But the constructor has factories in his arguments like CategorySetupFactory When I run setup:di:compile I got an error that ...
1
vote
1answer
26 views

Magento 2 - Prohibits depends directly the ObjectManager, but all object can use factory object

As Magento prohibits depending on and directly using the ObjectManager, whether all object can use factory object to instantiate?
0
votes
0answers
54 views

Creating a category programmatically using category factory, category data gets created in DB, but category is not visible in admin

Pretty much self-explanatory. I create a category model using category factory and then use the ->save method to save the category. I can see some data created, along with catalog_category_entity, ...
1
vote
0answers
80 views

Magento2 performance killer -factory pattern

Magento using factory pattern injecting non-injectable objects such as products,categories.so that it will create new object every time when you use create method on factory object. Is there any other ...
6
votes
2answers
243 views

Why auto generated Factories do not extends or implements any classes (interfaces)

This is more abstract question then specific problem. Why auto-generated factories in magento do not implements any common interface? And what bothers me maybe more. Why auto-generated factories ...
0
votes
1answer
50 views

Object instantiations in compiled mode

I was poking around for academic reasons on how the objects are instantiated. I figured out most of the things and the differences between factories (dev, compiled, production) but something scared me....
69
votes
5answers
18k views

When Should We Use a Repository and Factory in Magento 2?

I have gone through a couple of tutorials in Magento 2, and this confuses me a little. I can see there are basically two ways by which we can read/write business entities: Retrieve Data Using A ...
2
votes
1answer
170 views

Registering a shared service with a custom factory

I'm wondering how (if I can) register a shared service with a custom factory. Consider the following code: class MyApiFactory { private $config; public function ___construct(Config $config) ...