Questions tagged [di]

Denotes questions related to Dependency Injection in Magento 2.

Filter by
Sorted by
Tagged with
0
votes
1answer
30 views

Override Model from third party vendor in custom theme

I am trying to override a Model from a third Party vendor in a custom-theme. The original file was: /vendor/3rdpartyompany/3rdpartymodule/Model/Formatter/BaseImage.php I copied that file over to: /...
0
votes
1answer
11 views

Magento 2 - Product gallery magnifier not working after overriding Gallery class

My magnifier is not showing anymore IF THE PRODUCT HAS MULTIPLE IMAGES, after I have overriden the gallery class! I have enabled the magnifier in THEME\etc\view.xml: <?xml version="1.0"?&...
0
votes
2answers
36 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
32 views

Error during compilation of Magento 2 Incompatible argument type : Required type:

Webkul\VendorPos\Model\ResourceModel\Orders\Grid\Collection Incompatible argument type: Required type: \Magento\Framework\App\Config\ScopeConfigInterface. Actual type: \Magento\Framework\DB\Adapter\...
18
votes
6answers
5k views

Magento 2.3.3 Fails on magento setup:di:compile with an error mentioning InvoiceFlexFieldProcessorInterface

I have installed the new Magento 2.3.3 version. After I have run the command: php bin/magento setup:di:compile I have Faced the following error: PHP Fatal error: Interface 'Vertex\Tax\Model\...
0
votes
1answer
27 views

Adding a productAttribute handler in Magento 2.4

I'd like my Magento 2.4 module to be able to modify the output of one of the product attributes programatically. I see that the ability to create a handler for this purpose was added in Magento 2.3.4, ...
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
2answers
39 views

How do I get an order collection in admin order view using the email address of the current order?

I am trying to build an order history table to display previous orders (order number/date/items ordered, etc) from a customer order in the admin order view (Magento\Sales\Block\Adminhtml\Order\View\...
1
vote
1answer
946 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....
0
votes
1answer
37 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
283 views

Search $block->getData('configProvider') in form.mini.phtml returns null after upgrade to 2.3.6

In 2.3.6, the following line was added to form.mini.phtml: $configProvider = $block->getData('configProvider'); Since the upgrade, this returns null and causes a fatal error due to this subsequent ...
1
vote
1answer
1k views

How to add an extension attribute into “Customer Address”

I want to manage the "extension attribute" named "example" into "Customer Address" entity. I've created a new custom module, and I've added the extension attribute into etc/extension_attribute.xml ...
0
votes
1answer
107 views

Is it possible to override a vendor module's di.xml file in Magento2?

So a module installed via composer lives in vendor/module, and I'd like to change its etc/di.xml from this: <virtualType name="customCategoryCollection" type="Magento\...
0
votes
1answer
149 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&...
8
votes
0answers
330 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\...
6
votes
2answers
7k views

How to Add a viewModel to a core block?

I am trying to overwrite a core template and add my custom logic using a viewModel as follows: <?xml version="1.0"?> <page 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?
1
vote
3answers
128 views

Magento 2 di.xml Parameter configuration inheritance explanation with example

I read about the Parameter configuration inheritance in Magento documentation but not able to understand the concept properly! https://devdocs.magento.com/guides/v2.4/extension-dev-guide/build/di-xml-...
10
votes
3answers
878 views

Magento 2: Use of priceModifiers

While browsing the code of magento 2.0.7's catalogrules module, i came accross a class Magento\CatalogRule\Model\Product\PriceModifier, Which was passed to Magento\Catalog\Model\Product\PriceModifier\...
1
vote
1answer
57 views

Why I'm receiving an error messages Class does not exist when running DI compile?

Why am I receiving error messages "Class does not exist" when running DI compile? I removed some modules using the node replace in my composer.json, as you can see below. "replace"...
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 ...
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
163 views

Dependency Injection (di.xml) - (virtualType vs type) Magento 2 xsi:type='object'

Can someone please explain when you would use <type/> or <virtualType in your di.xml file? I want to make sure I understand it correctly.. At the moment, this is what I sort of think the ...
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
107 views

Magento 2.3 - Error related to Amasty shopby while RUNNING setup di:compile

MiBPHP Fatal error: Declaration of Amasty\Shopby\Model\Source\Attribute\Extended::toOptionArray() must be compatible with Amasty\Shopby\Model\Source\Attribute::toOptionArray($boolean = 1) in /...
1
vote
1answer
390 views

What is the use of php bin/magento dev:di:info command?

With Magento 2.3, console command found which helps developers to find all the classes related to dependency injection. It seems that it shows dependency Injection classes from di.xml from all areas. ...
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
1answer
56 views

Not able to use virtualType as Action constructor argument

In short I seem unable to use a virtualType I created as an argument in my Action's contructor but everything works fine when using a concrete class instead. Index.php (my action): namespace Unit1\...
2
votes
2answers
706 views

What should we use instead of the Magento\Checkout\Model\Cart model?

The Magento\Checkout\Model\Cart class was marked as deprecated a long time ago (since 2.1 ver.). What should I use instead of it to work with a customers cart? I know that I can work directly with a ...
1
vote
1answer
414 views

Magento 2 Injecting Object in $data array

I am trying to inject my custom object in constructor like this in di.xml <type name="Magento\CatalogSearch\Block\Advanced\Result"> <arguments> <argument name="data" xsi:...
3
votes
3answers
1k views

Magento 2: Dependency Injection: Optional class as parameter

We are developing a Magento 2 extension and we need to inject a class from a third party extension that the user may or may not have installed. We thought about injecting the class via the di.xml ...
10
votes
3answers
11k views

Is it possible to disable plugins defined in di.xml programatically?

Given a plugin defined in di.xml such as the following: <type name="\Magento\Catalog\Model\Product"> <plugin name="se_catalog_product_plugin_ample" type="Example\Module\Model\...
6
votes
2answers
425 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 ...
1
vote
1answer
198 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 ...
7
votes
2answers
2k views

What is dependency injection in magento 2

I am new in Magento 2. I wanted to know, what is dependency injection in magento 2. What the concept is about, and how to use it in our framework ? I have referred this documentation But still ...
14
votes
1answer
19k views

Magento 2 - What case I use di.xml and How to use di.xml for module?

In Magento 2, What case I use di.xml and How to use di.xml for module? Anyone knew, please show me step by step.
36
votes
4answers
24k views

Magento 2: Run `setup:di:compile` **only** a Specific Module?

Is it possible to pre-generate code for one specific module? I.E. -- I can generate all the code in the system with php bin/magento setup:di:compile However, this can take a long time. I'd like to ...
1
vote
1answer
1k views

setup:di:compile VS rm -f var/generation

When we work in di.xml file for extend the functionality then we need to php bin/magento setup:di:compile setup:di:compile take 30 to 40 second or long in window. if we remove the generation folder/...
0
votes
1answer
106 views

Magento 2 Class CoinGate\Merchant does not exist

I have installed the CoinGage_Merchant module in Magento 2.3 setup but when I fire di:compile command it is showing below error. I set the generated folder permission 777 before compile command but ...
1
vote
1answer
36 views

Why avoiding ObjectManager can save us from multiple issues if Magento upgrade?

A new dependency injection framework will be used for the code. By avoiding ObjectManager in Magento 2, you won’t face multiple issues caused by the improvement. source:https://firebearstudio.com/blog/...
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
52 views

Using composition in patches / install scripts

TL;DR: Is there a way to declare virtual types and different arguments in di.xml of a module and have that configuration be picked up when the module gets installed without calling bin/magento module:...
1
vote
1answer
562 views

Magento 2: Override di.xml in custom theme

I have a module in vendor/company/module. I have created the following folder to override files. /vendor/theme/theme-frontend-default/Company_Module. I am able to override files in view folder but I ...
2
votes
1answer
1k views

Elegant way of constructor dependency injection when extending abstract class?

I'm wondering what the best way is to add extra dependencies in the constructor of a class when extending another (abstract) class? In follow up to this answer regarding dependency injection when ...
3
votes
1answer
385 views

Undo preference from third party module

I have to deal with a third party module that enthusiastically uses preferences for everything and breaks stuff with it. For example: <preference for="Magento\Sales\Model\Order" type=&...
4
votes
3answers
6k views

Magento 2 custom logger 'Missing required argument $name'

I'm trying to create a custom logger, so I can log to a custom log file. I've looked at and followed multiple tutorials that all say the same, however I keep getting the same error. Tutorials that I ...