Questions tagged [di]

Denotes questions related to Dependency Injection in Magento 2.

Filter by
Sorted by
Tagged with
0
votes
3answers
36 views

Error while running di:compile command

Getting ReflectionException] Class PayPal\Api\PayoutSenderBatchHeader does not exist error while running php bin/magento setup:di:compile command
0
votes
0answers
22 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:...
0
votes
1answer
22 views

How does Magento 2 sku generated automatically?

I want to know how does Magento 2 sku generated automaticlly. I wonder when I type product name while creating new product in admin then its sku is automatically typed in sku field. I researched ...
0
votes
0answers
106 views

How to properly inject PriceResolverInterface to my module class

I am trying to inject via the constructor a \Magento\ConfigurableProduct\Pricing\Price\PriceResolverInterface So that I can properly resolve configurable product prices, however whenever I add it, ...
0
votes
1answer
34 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
18 views

Magento 2.3 - Append custom block to product listing using DI xml failed

I am trying to add my custom block using DI XML but it failed. Di XML <type name="Magento\Catalog\Block\Product\ListProduct"> <arguments> <argument name="data" xsi:...
0
votes
1answer
19 views

Magento 2.3: How do i solve this, Not registered handle, on custom form?

I'm new to Magento, my version is 2.3, i'm getting this error when i open form view: Not registered handle event_form_data_source, i made my custom module Plumtree_Events, here are my files code. /...
0
votes
0answers
43 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\...
1
vote
1answer
37 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: ...
0
votes
0answers
19 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> ...
2
votes
1answer
49 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....
1
vote
1answer
42 views

Needed short explanation

I have read many blogs to understand some of the topics in Magento 2 but still not clear about them. They are as follows EAV Dependency Injection Could anyone please explain them shortly? Thanks ...
1
vote
1answer
20 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 ...
2
votes
1answer
43 views

Preference class doesn't work

I'm trying to replace a class method "wrapResult" from: \Magento\Catalog\Pricing\Render\FinalPriceBox Never enter into this method. Try to stop the execution with die () or with xdebug, enter ...
0
votes
0answers
28 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
2answers
23 views

Magento 2 describe attrubute property used in Plugin method

I am trying to create a simple module and I can't find the propose of the attribute name and type inside the tag type and plugin in di.xml. can anyone describe attribute name used in plugin? <?...
1
vote
0answers
42 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 ...
0
votes
1answer
108 views

What is the Use of Type and Virtual Types(di.xml) in Magento2?

I want to know clear about Type and Virtual Types in di.xml with examples. When we can use it. Please share simple example to understand concept. Note please go through the practical examples.
0
votes
0answers
35 views

M2: Should I make a generic “My Company” module?

My question is a process question. I want to use Magento 2 best practices and I haven't seen any guidance in this regard. A lot of what I read is "how" to do something and not whether it's a good idea....
0
votes
1answer
34 views

Best practice to extend an object

What's the best practice and recommended way to extend an object like \Magento\Store\Model\Store with a new object property. I want to do something like this: $storeManager; //StoreManagerInterface ...
1
vote
3answers
170 views

Confused about using proxies

I kind of understand how the logic and the benefit of proxies in Magento 2 di. But can anybody tell me, how to use it?! Alan Storm use the generated proxy class, for example, I would call \...
8
votes
1answer
179 views

The purpose of the http verbs interfaces

In Magento 2.3 there are some interfaces for all the http verbs Magento\Framework\App\Action\HttpPostActionInterface Magento\Framework\App\Action\HttpGetActionInterface, ... All of them are empty ...
0
votes
1answer
374 views

Magento 2 Overwrites Topmenu.php In Module But Menu Nav Disappears

My di.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <...
7
votes
3answers
145 views

What is the use of “mapping” node in di.xml in Magento 2?

I am using Magento 2.2.5 have a look on file vendor\magento\module-sales\etc\di.xml <type name="Magento\Payment\Model\Checks\SpecificationFactory"> <arguments> <...
1
vote
1answer
239 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
52 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> ...
0
votes
0answers
59 views

Magento2: What is Dependency Injection(Di) and Object Management (Object Manager)?

Both are most important topics for learning Magento2. I want to discuss what learn from google, pdf,notes,magento documentation etc. Overview: Magento 2 provides a new approach to working with ...
0
votes
2answers
44 views

setup:di:compile ignores third party type definition (Monolog)

I have a DI configuration for a custom exception handler: <type name="My\Logger\Handler\ExceptionHandler"> <arguments> <argument name="formatter" xsi:type="object">My\...
0
votes
1answer
57 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="Censored\...
1
vote
1answer
298 views

Injecting object through virtual type not working

I am using this config in di.xml <virtualType name="ourFirstVirtualType" type="Test\Testmod\Model\Newmodelclass"> <arguments> <argument name="test_object" xsi:type=...
1
vote
2answers
171 views

Complex message not working

I've followed this tutorial: https://store.fooman.co.nz/blog/displaying-complex-error-messages-in-magento-2.html This is my di.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/...
5
votes
1answer
176 views

Plugin for aroundSavePaymentInformationAndPlaceOrder Throwing Error

I have a plugin that i want to intercept aroundSavePaymentInformationAndPlaceOrder, but it is giving me an error. Here is how it is set up: Vendor/Module/etc/di.xml <?xml version="1.0" ...
0
votes
0answers
124 views

magento 2 - Overriding Abstract class in model is not working in custom module

I am trying to override the fontsize value for pdfslip file in my module. The pdfslip files can be found in admin under sales->invoices->actions. The function that I am interested in is ...
3
votes
2answers
183 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 ...
0
votes
0answers
12 views

Magento 2. Make dependency injection work on storview level?

I have a custom module, and in di.xml file, I have the following code, <type name="Magento\CatalogSearch\Model\Search\IndexBuilder"> <plugin name="change_list_filter_table" ...
2
votes
1answer
683 views

Cannot get customer session in Controller

I am just trying to get the customer session in my custom controller class and it always returns NULL. What is wrong with Magento? It doesn't work as expected, I am spending days not minutes for a ...
0
votes
2answers
118 views

Activating custom grid in magento2 causes other grid to throws error

I have created a custom grid with following di.xml di.xml <preference for="\Magento\Customer\Controller\Adminhtml\Index\InlineEdit" type="Namespace\Modulename\Controller\Adminhtml\Index\...
4
votes
3answers
718 views

Overriding constructors for dependency injection

So, the new dependency injection approach requires me to inject everything I need into the contructor of an object. I get that. But how is this more flexible? For instance... I have my own Topmenu ...
5
votes
2answers
2k views

Magento 2: 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 follow: <?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:...
1
vote
1answer
155 views

Magento 2: Plugin not working on \Magento\Swatches\Block\LayeredNavigation\RenderLayered

I'm trying to create a plugin for \Magento\Swatches\Block\LayeredNavigation\RenderLayered in order to modify the return of getOptionViewData() It's not working. My di.xml looks like that: ... <...
0
votes
1answer
63 views

Multiple datasource define in di.xml magento2

<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <type name="...
0
votes
1answer
41 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 ...
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/...
-1
votes
4answers
89 views

Magento2 Controller Not overriding [closed]

I add the controller in my local but it not working. di.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../....
1
vote
1answer
370 views

In Magento 2 use the after plugin in place order function, in the plugin i can't get the order id?

in Magento 2 i extend the magento place order function \Magento\Sales\Model\Order but i did give the order id public function afterPlace(\Magento\Sales\Model\Order $subject, $result){ $this-&...
1
vote
2answers
1k views

Magento2 around method in plugin to save extra field data of customer

I would like to add extra information to the customer. I have added field in admin side form of customer. I have to save that data. How to add plugin around method during save customer.
2
votes
3answers
131 views

Magento 2 DI compilation issue

I've the run the before running setup:di:compile home page and other is working fine.After running the setup:di:compile expect home page other pages working fine. if i'm removing the di/global.ser ...
1
vote
0answers
83 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) { ...
0
votes
2answers
68 views

Contoller in magento2?

How to override Magento\Sales\Controller\Adminhtml\Order\AddressSave contoller? di.xml <preference for="Magento\Sales\Controller\Adminhtml\Order\AddressSave" type="Xxx\Order\Controller\Adminhtml\...
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 ...