Skip to main content
Share Your Experience: Take the 2024 Developer Survey

Questions tagged [construct]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
1 answer

Is it possible to override type configuration in the di.xml of a module in Magento2?

I want to override the file "Fooman\EmailAttachments\Observer\AbstractSendInvoiceObserver". Here is the code in the di.xml. <!-- module introduced preferences --> <preference for=&...
Jancy Abraham's user avatar
1 vote
1 answer

Cannot instantiate abstract class Magento\Framework\Data\Collection\AbstractResource

I am getting this error on my homepage after upgrading my Magento version from 2.4.0 to 2.4.6. Error: Cannot instantiate abstract class Magento\Framework\Data\Collection\AbstractResource in /home/...
Tisha Jhanwar's user avatar
2 votes
3 answers

Extra parameters passed to parent construct $directoryHelper

I am getting the following error on di compile: **Extra parameters passed to parent construct $directoryHelper** That's the original code: class PreviewButton extends \Magento\Config\Block\System\...
Someguy's user avatar
  • 21
0 votes
3 answers

Preference Module - When to Pass in Parent Dependencies

I am currently creating a preference module to add additional functionality to \Magento\Catalog\Model\Product and in reviewing some of the tutorials, example below, I noted that dependencies weren't ...
A. Andersen's user avatar
0 votes
1 answer

Error on constructor while saving form into the database

Here is my save.php <?php namespace Mageplaza\Menu\Controller\Adminhtml\Post; use Mageplaza\Menu\Model\PostFactory; use Magento\Backend\App\Action; use Magento\Framework\App\Action\Context; use ...
Thoubik's user avatar
  • 128
0 votes
1 answer

required argument directoryList in parent::__construct call

I'm getting this error but I don't really understand it.. as I'm looking through the file I believe the error is complaining about this bit of code. Is it missing the path to a directory or something? ...
Singleton's user avatar
1 vote
1 answer

Magento 2.4 constructing controller URL admin(backend) in JavaScript

I tried to make a simple ajax call to my controller, but I can't generate the url to make the request requirejs(['jquery', 'Magento_Ui/js/modal/confirm', 'mage/url'], function ($, confirmation, ...
GStiven's user avatar
  • 41
1 vote
0 answers

magento 2 is the position of parent::costruct() relevant?

I'm looking at Magento 2 core code. When Magento needs to extend a class, it creates a class with a constructor that calls the parent construct via the parent::__construct() method, something like ...
Lou Nik's user avatar
  • 443
0 votes
1 answer

Why is parent::__construct($context) used?

I have experience in programming with php and i think i have a good understanding of what a constructor does. But in Magento the constructor is called with the implemented Dependency's but after that ...
BigJonna's user avatar
0 votes
2 answers

Inject class into plugin

I created an plugin for afterGetProductPriceHtml() and it works so far. My di.xml: <?xml version="1.0"?> <config> <type name="Magento\Catalog\Block\Product\...
Mario's user avatar
  • 478
0 votes
1 answer

Block override issue in Magento2

I am overriding Google analytics block file. Here is my Vendor/Module/etc/di.xml <?xml version="1.0"?> <config xmlns:xsi="" xsi:...
Manjunath's user avatar
  • 177
0 votes
1 answer

Inject a class when extending the CatalogWidget component

I want to extend the Catalog Widget to filter Out Of Stock products. To do this, I have created a component to extend the Catalog Widget's ProductsList class, which contains the following code to ...
RichardB's user avatar
  • 325
1 vote
0 answers

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 ...
Quisse's user avatar
  • 860
0 votes
0 answers

Magento 2 how to set constructor argument?

I am trying to find out how I can send constructor argument when calling class. This is what I tried: class Subscriber extends \Magento\Framework\Model\AbstractModel{ protected $...
JohnyFree's user avatar
  • 1,539
0 votes
0 answers

Custom Console command __cunstructor always gets an error in Magento 2.3

I have a console command class with constrcutor that looks like this: namespace Vendor\Module\Console\Command; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\...
jojo's user avatar
  • 39
0 votes
1 answer

Error occurred when creating object

I have a plugin with constructor <?php namespace Vendor\Contact\Plugin\Controller\Index; use \Zend_Validate; use Magento\Contact\Controller\Index\Post; use Magento\Framework\App\Request\Http; use ...
Михайло Годованюк's user avatar
5 votes
1 answer

Magento 2 What is the fastest way to get construction changes?

Whenever I made any changes on the construction method, I need to do bin/magento setup:di:compile to get any changes on my code. It was wasting my time, how can I get any changes faster than have to ...
Fiko iCube's user avatar
0 votes
1 answer

Magento 2: How we can add construct into overridden class

If There are no parent::__construct from parent class then How we can add construct into overridden class?
Arjun's user avatar
  • 3,586
0 votes
1 answer

What's the logic of inherited constructor order parameters

I have this module class namespace VendorName\Module\Block\Magento\Framework\Pricing; use Magento\Framework\Pricing\Amount\AmountInterface; use Magento\Framework\Pricing\Price\PriceInterface; use ...
tarek fellah's user avatar
0 votes
2 answers

Error on constructor of a class that extends \Magento\CatalogRule\Model\Rule

Im trying to do a model that extends \Magento\CatalogRule\Model\Rule, but in the contructor the context is giving me a warning: Declaration of overridden method should be compatible with parent class....
Juan Alvarez's user avatar
1 vote
2 answers

How to pass custom parameters to parent construct?

I have extended \Magento\Sales\Controller\Adminhtml\Order to Custom class like below,but not able pass one more parameter($httpClientFactory) to this construct level. How to pass custom parameters($...
Vamsy Krishna's user avatar
0 votes
0 answers

Override __construct Magento\Catalog\Model\Product

I have overrided the Magento\Catalog\Model\Product. When I create a new function, I can access it with $this->_currentProduct->myNewFunction() in my code. But, in my new function, I need to ...
Kozame's user avatar
  • 964
1 vote
3 answers

How many types of Injection methods does Magento 2 support?

What types of Injection methods does Magento 2 support? I am aware about, Constructor Injection - consider as a Injection. Method Injection - consider as a Injection. BUT And Interface and Model ...
Aditya Shah's user avatar
  • 7,617
0 votes
2 answers

How to replace direct use of Object Manager?

in the success.phtml file I currently have a direct use of the object manager, which I am now reading is not best practice. I was wondering how to make a constructor to replace the following code in ...
Degnan's user avatar
  • 99
0 votes
1 answer

Is this the correct way to write a constructor that extends this other PHP file?

I am using Magento 2.2.6. The file I am extending is \Magento\UrlRewrite\Model\Storage\DbStorage. It has the following constructor: /** * DB Storage table name */ const TABLE_NAME = 'url_rewrite'; ...
kig's user avatar
  • 169
2 votes
2 answers

Extends constructor

I have a class that extends \Magento\Customer\Block\Account\Dashboard\Info and I want to extend its constructor to get customer session, but how do I extend constructor? PhpStorm is highlighting my ...
Morgan Tartreau's user avatar
2 votes
1 answer

Difference between declare class in : "__construct" and in the top of file with "use" [duplicate]

Anyone have idea about declare class in __construct and declare class in top of file with use. Exemple: use Magento\Store\Model\StoreManagerInterface; and public function __construct( \...
Niranjan Gondaliya's user avatar
16 votes
3 answers

M2/ How to fix "Incompatible argument type: Required type: string. Actual type ..."

A compilation was started. Interception cache generation... 6/7 [========================>---] 85% 1 min 404.0 MiB Errors during compilation: SkyFox\Supplier\UI\DataProvider\Supplier\...
Nguyễn Hoàng Tuấn's user avatar
2 votes
0 answers

Magento 2.2.4 - unable to print messages. - New Theme

I have a Module which processes a Post action, and then redirects. for example i am trying to overwrite - Magento\Checkout\Controller\Cart\Add I have used my construct function and my method as ...
Hacker's user avatar
  • 51
6 votes
3 answers

Magento 2.2.5 : Cant go to execute() in Controller

I'm doing a simple CRUD custom module after this module C:\xampp\htdocs\magento\vendor\magento\module-cms\Controller\Adminhtml\Page\Save.php and I have a controller to save/create/add the "students" ...
fudu's user avatar
  • 1,278
0 votes
1 answer

Override construct function in child class magento2

I want override a model class, for this I have made entry in di.xml and created a respective file on my custom module. My file is calling but now here apart from modify other functions I also need to ...
Atul's user avatar
  • 915
0 votes
1 answer

Datetime Error on Newsletter Template

Steps to reproduce Go to Admin->Marketing->Newsletter Template Select Queue Newsletter from right dropdown Select a Queue Date Start and try to save it Expected Result Saved Actual result ...
Nimesh Patel's user avatar
1 vote
2 answers

Magento2 :Change the object maganer to constructor

Can anyone help me how to change the object manager to a constructor in magento2: $om = \Magento\Framework\App\ObjectManager::getInstance(); $customerSession = $om->get('Magento\...
venkata prasad's user avatar
1 vote
1 answer

Argument passed to __construct() must be an instance of \Helper\Data

I get this error Argument 2 passed to [VENDOR][MODULE]\Controller\Index\Index::__construct() must be an instance of [VENDOR][MODULE]\Helper\Data this is my controller namespace [VENDOR]\[MODULE]\...
Altravista's user avatar
1 vote
0 answers

"Fatal error: Uncaught TypeError: Argument 1 passed to [...]::__construct() must be an instance of [...]" after (re-)compile

So I've inherited this weirdly behaving (and horribly tinkered) shop containing some external product and customer import scripts. One of these scripts ('importcustomer_fields.php', located in the ...
Christoph Farnleitner's user avatar
0 votes
3 answers

Controller not executing if changing constructor parameters

I have a Controller class as follow : class Delete extends \Magento\Framework\App\Action\Action { protected $cache; protected $cacheManager; public function __construct( \Magento\...
androniennn's user avatar
2 votes
1 answer

Missed required argument request in parent::__construct call

I'm working on a Magento module for the past month, and everything works great on my local machine. Then I decided to release the module as a beta and test it online in a newly installed store, and ...
Pablo's user avatar
  • 237
10 votes
3 answers

XML Parsing Errors

I believe I have a syntax error or something? I'm confident it's either something to do with xml or syntax. Everything appears to be in order when i look into the file. This error is dealing with the ...
Singleton's user avatar
2 votes
1 answer

Magento 2 model error after updating on 2.2 verison

I have a CRUD module created on magento 2.1.6 version which was working ok untill i updated magento to version 2.2.1 Now when i compile my code i receive the following err: namespace\module\Model\...
Alin Lupoiu's user avatar
  • 2,672
8 votes
3 answers

magento2 Uncaught ArgumentCountError: Too few arguments to function

I am getting "Uncaught ArgumentCountError: Too few arguments to function on parent::__construct($context); Index.php <?php namespace MyTheme\Theme\Controller\Index; use Magento\Framework\App\...
brazuka's user avatar
  • 309
1 vote
1 answer

How to Override Construct function of Magento without violating "

I created a class with the construction: public function __construct( \Magento\Store\Model\StoreManagerInterface $storeManager, array $data = [] ) { parent::__construct($...
Nguyen Hai's user avatar
4 votes
1 answer

Does arguments order in constructor matters?

I've noticed strange situation while creating class contructor (__construct). Here is my code: public function __construct( \Magento\Framework\Model\Context $context, \Magento\...
Kyrylo Romantsov's user avatar
0 votes
1 answer

Using construct instead of object manager

I'm running into an error while converting below code that uses object manager to injecting within construct instead. In this example i have this code: $objectManager->create('Magento\...
harri's user avatar
  • 5,475