Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [di]

Denotes questions related to Dependency Injection in Magento 2.

0
votes
0answers
11 views

magento2 How can I override root.phtml in custom controller?

Is there any way I can override root.phtml in my custom controller only? Something like this from M1: <?xml version="1.0" encoding="UTF-8"?> <layout> <mycustommodule_index_index&...
1
vote
0answers
19 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
28 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
27 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
25 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
33 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
1answer
45 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
41 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
21 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
71 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
10 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
284 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
0answers
25 views

Magento 2.1.8 - Custom Column Module in Admin Disables Buttons

Initial Goal: Add a new custom column to display additional existing product data per variation/simple in the Current Variations grid in the Configurable view. Initial View: After some searching, ...
0
votes
0answers
201 views

Magento 2 block page Not registered handle

I have created a module, from that the super admin can assigns an order to the sub-admin, the sub-admin can only view that assigned orders. for that in sales_order_grid table, I have added two ...
0
votes
2answers
36 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\...
3
votes
3answers
202 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 ...
2
votes
2answers
621 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
120 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
26 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
0answers
28 views

How to rewrite a Magento 2 Command

I am looking for a way to rewrite (replace) the following class: Magento\Setup\Console\Command\ModuleEnableCommand But cannot find any way to do it. These commands are loaded using the Zend Service ...
0
votes
1answer
22 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
0answers
16 views

Why is Magento 2 using the Zend Service Locator instead of the ObjectManager in Magento\Setup\Model\InstallerFactory

In the class Magento\Setup\Model\InstallerFactory there is a create method that returns a new installer. This class is used for example when running bin/magento setup:upgrade The method looks like ...
3
votes
0answers
705 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
51 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
66 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-&...
0
votes
0answers
37 views

Category Name Alteration

I have created a module to replace the category name on the front-end with the name entered in my custom attribute, I tested it in Magento 2.2.2 & it worked perfect there but now when I am ...
1
vote
2answers
656 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.
0
votes
0answers
141 views

Order collection in plugin not working

I'm trying following code to get the specific order from quote_id in magento2.1.5 and it is working properly. <?php namespace Package\Module\Controller\Index; class Index extends \Magento\...
2
votes
3answers
82 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 ...
0
votes
0answers
19 views

how to get product repository in di class file

Right now i am customizing the order edit page. For the purpose, i have overridden name.phtml and classes associated to it to my module. I have also used DI to override \Magento\Sales\Block\...
0
votes
2answers
67 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
60 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 ...
1
vote
0answers
32 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 ...
4
votes
2answers
1k views

Magento 2: How can I use ifconfig or something similar to layout component

I created a boolean option (Yes / No) in Store -> Configuration, with which I can display or not the checkout sidebar. The configuration path is: vendorname_sidebar/display/enabled. Below is a part ...
0
votes
0answers
276 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
1answer
72 views

unit test with phpunit

I create simple unit test with object manager with class name $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this) and object Name ModuleList like $...
2
votes
2answers
1k 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 ...
0
votes
1answer
29 views

Magento2 di in ResourceCollection

I have the fallowing collection and I want to pass the ProductFactory so it can be accessible in my collection. class Collection extends AbstractCollection { public $productFactory; ...
1
vote
0answers
53 views

Magento 2 Resource Model not working [closed]

Di.xml <?xml version="1.0"?> <!-- /** * Mageplaza_HelloWorld extension * NOTICE OF LICENSE * * This source file is subject to the Mageplaza ...
0
votes
2answers
111 views

DI not working in Controller

I have a Controller that contains the following: ... use Magento\Backend\App\Action; use Magento\TestFramework\ErrorLog\Logger; use Magento\MediaStorage\Model\File\UploaderFactory; use MyNamespace\...
2
votes
1answer
315 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 ...
2
votes
1answer
250 views

Magento 2. Injecting a virtual type results in array instead of object

I'm having some trouble with virtual types. I've done some research and this is what I have. 0: A class which takes a string argument 1: A virtual type based on above class with a constant value for ...
0
votes
4answers
416 views

Is there any way to identify what class causes 'Area code is not set' or 'Area code already set'?

I know there are a lot of questions about 'Area code is not set', but no one has yet answered the main question. How to find the file which caused this Exception? In my case, I updated a lot of ...
0
votes
1answer
331 views

Magento 2: Use a model with a dynamic name through DI

i have one situation where i need to load need model dynamically i followed below steps it work great same way like layersPool in catalog module but they used objectManager as per magento we ...
0
votes
1answer
42 views

Error on overriding magento 2 block with the Plugin(Intercepter)

I am trying to override a Magento 2 block with the help of di.xml and Plugin(Interceptor). But I am getting an error message [2017-09-27 05:17:33] main.CRITICAL: Packagename\Modulename\Plugin\Block\...
2
votes
3answers
169 views

REST Api interface di not working. Class ItemInterface does not exist

ItemInterface: namespace MyVendor\SampleModule1\Api\Data; interface ItemInterface { /** * @return string */ public function getName(); /** * @return string|null */ ...
1
vote
1answer
80 views

Although I use the correct namespace a wrong instance is passed to the constructor

I have a block php file. Block File Code: <?php namespace Vendor\SampleModule1\Block; use Magento\Framework\View\Element\Template; use Magento\Framework\View\Element\Template\Context; use Vendor\...
3
votes
1answer
77 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/...
1
vote
1answer
306 views

Can a virtual type be used as a dependency for a class?

I'm trying to do something new with virtual types. I understand that you can create these in your di.xml and use them as arguments for other types in di.xml. But can I also declare a virtual type and ...
3
votes
2answers
274 views

Magento 2 not respecting preference?

I'm trying to make a preference to override the PayPal Module's ResponseValidator class, so that i can save the validation errors for easier debugging on our end if a customer's checkout fails. The ...