Questions tagged [construct]
The construct tag has no usage guidance.
40
questions
0
votes
3
answers
39
views
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 ...
0
votes
1
answer
20
views
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 ...
0
votes
1
answer
42
views
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?
...
0
votes
1
answer
489
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, ...
1
vote
0
answers
39
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 ...
0
votes
1
answer
454
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 ...
0
votes
2
answers
225
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\...
0
votes
1
answer
87
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:...
0
votes
1
answer
102
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 ...
1
vote
0
answers
27
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 ...
0
votes
0
answers
75
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 $...
0
votes
0
answers
168
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\...
0
votes
1
answer
511
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 ...
5
votes
1
answer
255
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 ...
0
votes
1
answer
379
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?
0
votes
1
answer
194
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 ...
0
votes
2
answers
379
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....
1
vote
2
answers
662
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($...
0
votes
0
answers
362
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 ...
1
vote
3
answers
530
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 ...
0
votes
2
answers
409
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 ...
0
votes
1
answer
130
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';
...
2
votes
2
answers
301
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 ...
2
votes
1
answer
147
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(
\...
15
votes
2
answers
17k
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\...
2
votes
0
answers
38
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 ...
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" ...
0
votes
1
answer
519
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 ...
0
votes
1
answer
211
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
...
1
vote
2
answers
70
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\...
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]\...
1
vote
0
answers
865
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 ...
0
votes
3
answers
72
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\...
2
votes
1
answer
8k
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 ...
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 ...
2
votes
1
answer
390
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\...
8
votes
3
answers
18k
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\...
1
vote
1
answer
143
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($...
4
votes
1
answer
893
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\...
0
votes
1
answer
578
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\...