Questions tagged [construct]

The tag has no usage guidance.

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

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, ...
user avatar
1 vote
0 answers
20 views

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 ...
user avatar
  • 129
0 votes
1 answer
90 views

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 ...
user avatar
0 votes
2 answers
48 views

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\...
user avatar
  • 383
0 votes
1 answer
61 views

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="http://www.w3.org/2001/XMLSchema-instance" xsi:...
user avatar
  • 135
0 votes
1 answer
68 views

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 ...
user avatar
  • 325
1 vote
0 answers
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 ...
user avatar
  • 740
0 votes
0 answers
24 views

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 $...
user avatar
  • 1,469
0 votes
0 answers
83 views

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\...
user avatar
  • 167
0 votes
1 answer
365 views

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 ...
user avatar
5 votes
1 answer
133 views

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 ...
user avatar
0 votes
1 answer
142 views

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?
user avatar
  • 3,426
0 votes
1 answer
89 views

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 ...
user avatar
0 votes
2 answers
222 views

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....
user avatar
1 vote
2 answers
443 views

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($...
user avatar
0 votes
0 answers
264 views

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 ...
user avatar
  • 894
1 vote
3 answers
402 views

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 ...
user avatar
  • 7,389
0 votes
2 answers
205 views

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 ...
user avatar
  • 99
0 votes
1 answer
57 views

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'; ...
user avatar
  • 149
2 votes
2 answers
59 views

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 ...
user avatar
2 votes
1 answer
131 views

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( \...
user avatar
14 votes
2 answers
12k views

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\...
user avatar
2 votes
0 answers
18 views

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 ...
user avatar
  • 51
6 votes
3 answers
3k views

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" ...
user avatar
  • 1,168
0 votes
1 answer
424 views

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 ...
user avatar
  • 885
0 votes
1 answer
187 views

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 ...
user avatar
1 vote
2 answers
43 views

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\...
user avatar
1 vote
1 answer
2k views

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]\...
user avatar
1 vote
0 answers
661 views

"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 ...
user avatar
0 votes
3 answers
70 views

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\...
user avatar
2 votes
1 answer
6k views

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 ...
user avatar
  • 237
10 votes
3 answers
5k views

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 ...
user avatar
2 votes
1 answer
381 views

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\...
user avatar
  • 2,582
8 votes
3 answers
15k views

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\...
user avatar
  • 299
1 vote
1 answer
96 views

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($...
user avatar
3 votes
1 answer
842 views

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\...
user avatar
0 votes
1 answer
476 views

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\...
user avatar
  • 5,215