Questions tagged [virtualtype]

Virtual types are used in the Dependency Injection container of Magento 2

0
votes
1answer
30 views

Injecting additional dependencies into a class - Magento 2.3

I am trying to inject additional dependencies into a class. The class in question is: \Magento\Customer\Block\Adminhtml\Edit\Tab\View\PersonalInfo The construct of this class looks like: public ...
0
votes
0answers
19 views

can virtual types be used as cronjob instances

I tried to use a virtual type in cronjob as instance but without any success. When I use a real class it works as expected. Is there any hint to get virtual types working in cronjobs? crontab.xml: &...
1
vote
0answers
49 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> ...
1
vote
1answer
259 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=...
4
votes
1answer
165 views

Can Virtual Types be used as controllers?

This is more of a curiosity than a "need". I have a few controller actions that do exactly the same thing, just some parameters differ. I'm trying to reduce the amount of code I write and have one ...
2
votes
1answer
279 views

Const argument in virtual type breaks magento2 [closed]

So, I'm using the code from here sample-payment and I have in di.xml the following code: <!-- Payment Method Facade configuration --> <virtualType name="SamplePaymentGatewayFacade" type="...
3
votes
1answer
388 views

How to set ifconfig for di.xml magento 2

I want set ifconfig configuration for below code: First code in di.xml <virtualType name="searchFilterList" type="Magento\Catalog\Model\Layer\FilterList"> <arguments> <...
3
votes
1answer
469 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
1answer
568 views

Magento2 unable to create|use a virtual type

I'm trying to make use of a virtual type. I'm following the docs on this and everything should be pretty straight forward yet I'm kinda stuck. This is what I have. The class. namespace Company\...
2
votes
1answer
459 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 ...
2
votes
1answer
333 views

How to extends virtual type from di.xml

Is it possible to extends virtual type class declared in di.xml ? If yes how ?
3
votes
2answers
481 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 ...
0
votes
1answer
233 views

VirtualType not created / class not found (after cache clear)

Virtual Type XML Declaration: <virtualType name="SliderSlideImageUploader" type="Magento\Catalog\Model\ImageUploader"> <arguments> <argument name="baseTmpPath" xsi:type="...
0
votes
0answers
102 views

Assign template of block via virtualType in Magento 2?

It's possible to assign template of the block via virtualType? app/code/Vendor/Module/etc/frontend/di.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ...
6
votes
0answers
373 views

How to override class Virtual Type class

I saw this, but it don't work for me. How to override Virtual Type class in Magento 2 <virtualType name="categoryFilterList" type="Magento\Catalog\Model\Layer\FilterList"> <arguments>...
1
vote
1answer
373 views

Receiving object specific class which was injected in constructor by three-part extension

For example, anybody can modify this virtual type magento/module-catalog/etc/di.xml: <virtualType name="Magento\Catalog\Model\Layer\Search\Context" type="Magento\Catalog\Model\Layer\Context">...
5
votes
1answer
621 views

Change <item> node class via di.xml

If I have something like this: <type name="Magento\Downloadable\Ui\DataProvider\Product\Form\Modifier\Composite"> <arguments> <argument name="modifiers" xsi:type="array">...
2
votes
1answer
1k views

Magento2 - VirtualType argument replacement

I'm trying to remove the category filter in category view. But apart from that, my question is more about Magento 2 itself. in di.xml of Magento_CatalogSearch , you just have to comment the "category"...
0
votes
1answer
158 views

Can virtual types be used as source models for EAV attributes?

I'm creating my own EAV entity and one of the attributes of my entity has the type select so it requires a source model. But I don't want to create my own class just for this attribute since I already ...
8
votes
2answers
1k views

Magento 2: virtual types plugins

I'm confused by Magento 2 documentation regarding plugins: It is first said that: Plugins cannot be used with virtual types But then it is said that: You can specify a class, interface, or ...
3
votes
1answer
5k views

How to Override or Extend protected or parent function in Magento 2 using Plugin

I need to override protected function or parent function ex Magento\Checkout\Controller\Cart\Add is extended from Magento\Checkout\Controller\Cart and getBackUrl() is a Magento\Checkout\Controller\...
10
votes
1answer
619 views

Magento 2: Virtual Type Naming Convention

Date: June 1, 2015 (given the changing nature of Magento 2) In Magento 2, you can configure a "virtual type" in a module's di.xml configuration file. These virtual types allow you to change the ...
37
votes
3answers
10k views

What is the difference between type and virtualType

In the di.xml that comes with Magento2 there is a node type and a node virtualType. My questions is what is this virtualType and in what case should it be used instead of type? In some places it ...