Questions tagged [di]

Denotes questions related to Dependency Injection in Magento 2.

42 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
8
votes
0answers
326 views

What is/means/does Magento\Framework\EntityManager\MetadataPool and Magento\Framework\EntityManager\Operation\ExtensionPool

There are new things we can see at Magento 2.3 in di.xml for service contracts. let's give an example:Magento_Cms module Like Magento\Framework\EntityManager\MetadataPool Magento\Framework\...
4
votes
0answers
2k views

Magento 2 - Overwrite di.xml for Core Cms module

I've looked and looked, but can't find anything explaining what i need to do. Problem is, i want to add an svg file to the image uploader in the WYSIWYG. I know i need to extend the core to do this, ...
3
votes
0answers
2k views

Fatal error: Uncaught Error: Cannot instantiate interface Magento\Framework\Serialize\SerializerInterface

When I try to update magento 2.1.9 to 2.2.0 I am getting this error Fatal error: Uncaught Error: Cannot instantiate interface Magento\Framework\Serialize\SerializerInterface in vendor/magento/...
3
votes
1answer
157 views

How to Override custom module Model in custom module Magento 2?

I have two Modules in app/code. Xyz_Xyz - Module that already exists. I can't change its file. Abc_Abc - Module that I creating to override Xyz_Xyz Model. The code I try is here. app/code/Abc/Abc/...
3
votes
1answer
792 views

Why is `app/etc/di.xml` stored in `app/etc` and not in (lets say) `vendor`?

The default DI configuration of Magento 2 is placed in app/etc/di.xml alongside other configuration files like env.php and config.php. While the latter are files that you are meant to modify, the di....
2
votes
1answer
319 views

Magento 2 : di.xml on custom param won't work

I've a class located in \Vendor\Module\Model which is named Test. Here is the constructor of this class : public function __construct(array $map = []) { var_dump($map); die; } I created a di....
2
votes
0answers
99 views

Exception after bin/magento setup:di:compile and adding virtualType

I was adding this: <virtualType name="Test\Faq\Model\ResourceModel\VisitStat\Collection" type="Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult"> <arguments> ...
2
votes
0answers
238 views

Magento2 plugin does not working on class Magento\OfflineShipping\Model\Carrier\Freeshipping

Create a plugin using for class Magento\OfflineShipping\Model\Carrier\Freeshipping. Use after method (afterCollectRates) for CollectRates function. But this does not work here list of files: app/...
2
votes
1answer
261 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) ...
2
votes
0answers
93 views

Magento 2.1 : Cannot retrieve session variable

Im trying to save form token in session variable and get it back in the result page when the form is submitted. I created the following Session Model to handle sessions in my custom module: <?php ...
1
vote
0answers
21 views

DI compilation error when referenced module is not installed

I have a module that integrates with other modules from other developers. These other modules may or may not be installed, it is different for each user. As an example, the MSG_InstantSearch module ...
1
vote
0answers
14 views

Is it possible to retrieve dependency injected arguments in another class?

Is it possible to retrieve dependency injected arguments in another class? For example, we have a class Vendor\Module\Block\Autocomplete. // app/code/Vendor/Module/Block/Autocomplete.php namespace ...
1
vote
1answer
196 views

Magento 2 Overide public static method of framwork class

I want to override public static function getCorrectFileName method of Magento\Framework\File\Uploader, I have check with Preference and Plugin but it is not working for me. Anyone have idea about ...
1
vote
0answers
112 views

Di.xml error Cannot instantiate interface

I am trying to use the di.xml to pull a table from different module to populate a dropdown in the admin panel. When I write the XML code below it is throwing this error: PHP Fatal error: Uncaught ...
1
vote
0answers
39 views

Where are di.xml files merged?

My questions is pretty simple and straight forward. Somewhere in the code di.xml files are read and merged. Where is this happening?
1
vote
1answer
163 views

How to create a new price type?

I am now struggling to create a new price type on Magento 2.2.7. Below are what I have tried so far. I have created a module Foo_Bar. And then, first of all, inject the new type into the price pool: ...
1
vote
1answer
31 views

Are there any restrictions on classes you can override with preference in di.xml

When overriding a class with a custom one using the di.xml, are there any restrictions on what class you can override? I have tried overriding a class of a third party module, but it does not appear ...
1
vote
0answers
74 views

Magento 2 getting interface implementation from admin config

I have an interface which gives me the country in which the customer is located. interface CustomerLocatorInterface { public function getLocalCountryCode(); } And I have two possible ...
1
vote
1answer
940 views

How can i filter in sales order grid magento 2?

While i am using same code for filter it's working but i have break other grid like customer,invoice,cms page and get error "Not registered handle cms_page_listing_data_source" While i have moved di....
1
vote
0answers
243 views

Magento 2 class constructor

I have class in my module for Magento 2. His constructor gets 2 parameters class MyClass { private $str1; private $str2; public function __construct(string $str1, string str2) { ...
1
vote
0answers
38 views

Disable di:compile PHP Comments check in Magento 2.2.2

I Upgraded to Magento 2.2.2 and now di:compile checks if @params comments for constructors are correct. I have many modules where the comments are incorrect but the params are correct, so I want to ...
1
vote
0answers
451 views

“Cannot instantiate interface” but preference tag exists in di.xml

I'm getting this error when trying to load a page: Fatal error: Uncaught Error: Cannot instantiate interface Codazon\ThemeOptions\Framework\App\Config\Scope\ReaderPoolInterface in /magento2/vendor/...
1
vote
0answers
775 views

Circular dependency: Magento\Framework\App\Action\Context

I have a custom module. On 1 installation (all others work) I get the error, that there's a circular dependency. YES: Magento\Framework\App\Action\Context is a dependency in my Controller because ...
1
vote
0answers
28 views

Setting up proxy for constructor arguments vs. etc areas

Generally it is prefereable to set .xml configuration files only for areas that will use it. I want to set some proxy object for my classes__construct()` arguments. In case of models it can be not so ...
1
vote
3answers
178 views

Custom Block Product List Injection failed

I have to display a list of product on the product view, depending on its sku. In order to do that, i have simply pasted the Random.php list example of Magento_Catalog. But in order to find the ...
0
votes
2answers
32 views

Error during compilation in magento2 .3 Incompatible argument type: Required type:

Webkul\Marketplace\Model\Order\Pdf\Creditmemo Incompatible argument type: Required type: \Magento\Store\Model\App\Emulation. Actual type: \Magento\Framework\Locale\ResolverInterface; File: /var/www/...
0
votes
1answer
35 views

Plugin for Magento\Shipping\Model\Rate\Result not working

I am trying to disable the default sorting based on price, that is happening on shipping methods. I found that this is happening in sortRatesByPrice() vendor/magento/module-shipping/Model/Rate/Result....
0
votes
0answers
26 views

How can i pass an object with it's value using DI?

I'm still new at Magento and im trying to work on something where I need to pass the product SKU from a file that has a function that retrieves the product SKU to another file with no such function, ...
0
votes
1answer
147 views

Getting error Not registered handle cms_page_listing_data_source in Magento 2?

I have added some filter in Sales -> Order and for that add a di.xml file. di.xml file <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance&...
0
votes
0answers
5 views

How to set use address attributes

I have attributes wich display in customer_form_address_user_attributes BLOCK. How i can pass or change attributes. Maybe some xml or di?
0
votes
0answers
18 views

Magento2 : Join Another Table in Existing Collection

Lets say, Third party collection class is as below: namespace Vendor\ShipRule\Model\ResourceModel\Rule; class Collection extends Magento\Framework\Model\ResourceModel\Db\Collection\...
0
votes
0answers
28 views

Overwrite EmailNotification from Module Customer

Can anyone let me know how can I Over write EmailNotification File in our custom module. I tried this way by modifying methods of private function sendEmailTemplate( $customer, $...
0
votes
2answers
57 views

Override Magento 2 Order Invoice PDF

I can not seem to override the Magento Invoice class. I've created a module, installed it, enabled it. I have the following in my di.xml file <?xml version="1.0"?> <config xmlns:xsi="http://...
0
votes
0answers
57 views

aroundSavePaymentInformationAndPlaceOrder plugin not working in magento 2

etc/di.xml <?xml version="1.0" encoding="UTF-8"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config....
0
votes
1answer
3k views

Magento2 How to pass argument parameters with multiple class

How to pass argument Parameter configuration inheritance in using theme module inside di.xml here one thing in our theme inside header file inside define code below <?php $objectManager = \...
0
votes
0answers
47 views

Magento2: setup:di:compile issue

Got the error below when I run the setup:di:compile command [Magento\Framework\Exception\LocalizedException] Source class "\Magento\Framework\EntityManager\OperationInterface" for "Magento\...
0
votes
0answers
29 views

how to use other module data source to new module in magento 2

Hi I want to use the data source of module 1 to module 2 in Magento 2 how I can do this ?? vendor/module2/etc/module.xml <sequence> <module name=vendor_module1/> </sequence> ...
0
votes
0answers
146 views

Error Class not found before deleting generated folder

I have created a preference to override a class but constantly getting error "Class not found" before deleting "generated" folder content: Error: Fatal error: Uncaught Error: Class 'Vendor\Module\...
0
votes
1answer
181 views

Magento2: How to use different implementations of an interface

I am creating supplier imports. In order to do this, I created a base module "ProductImportBase" and two supplier specific modules "ProductImportA" and "ProductImportB". The base module contains stuff ...
0
votes
1answer
117 views

Cannot Extend Widget Block Class

I have installed the Amasty ShopBy Extension and am trying to make my own modifications the correct way: using my own extension. I have created a preference in di.xml (tried in /etc and /etc/frontend)...
0
votes
1answer
207 views

Override do not apply in a custom module

I try to override the mini cart but by changes are not getting applied. I have the following in my di.xml inside custom module <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/...
0
votes
1answer
37 views

multiple dependency injection problem

I try to override some core files and in my custom module I injected the dependencies like <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:...