Questions tagged [object-manager]

Denotes question regarding Magento 2 Object Manager

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

Programmatically Updating Products changes Custom Option & MetaData scope

I am working on a free standing script that updates product price and I have noticed that the scope of the product's custom options change after execution, causing the 'Use Default Value' to become ...
0
votes
1answer
17 views

How to change order state from external file

Try to change the order state from a file within the Magento root directory. What I did: Connected to Magento engine and included the object manager: // Start Magento engine use Magento\...
0
votes
0answers
46 views

How to solve Type Error occurred when creating object: Webkul\MpBlog\Block\Account\Navigation?

1 exception(s): Exception #0 (Magento\Framework\Exception\RuntimeException): Type Error occurred when creating object: Webkul\MpBlog\Block\Account\Navigation Exception #0 (Magento\Framework\Exception\...
0
votes
2answers
89 views

Is it possible to manipulate the default Store View programmatically?

I recently tried to update some product-information on the default storeView (id 0). Instead of applying the changes to the default store, it instead applied them to the product in the next higher ...
0
votes
3answers
340 views

magento 2.4 issue creating configurable product programmatically

i am using the below code to create a configurable product from product sku (from attributes color and size), it is working fine when all associated products have both attributes - color and size ...
0
votes
1answer
40 views

How do I change not using ObjectManager directly? and use Dependency injection?

How do I change not using ObjectManager directly? and use Dependency injection? what about my SQL query? My code is work, but seems not in good Magento style, anyone can help to correct me? I am ...
0
votes
1answer
56 views

Is it bad to use ObjectManager in list.phtml like in Code Below? What's the best Practice?

Is it bad practice to use ObjectManager in file app/design/frontend/Smartwave/porto/Magento_Catalog/templates/product/list.phtml like this below. <?php $objectManager = \Magento\...
3
votes
1answer
139 views

Is it okay to use $this->helper(...) in phtml files?

A question on using $this->helper(...) in phtml files: It returns something like this: ObjectManager->get(...) (Singleton) I'm aware it's bad practice to use Object Manager phtml, but ...
1
vote
1answer
1k views

Magento 2 - Using Object Manager

I have a module that places some shipping information into the order view of the admin. I am trying to display the current shipping method in this section. I have this in view/adminhtml/templates/...
0
votes
1answer
48 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 ...
0
votes
1answer
26 views

How many ways to do dependency injection?

How many ways to do dependency injection? Object Manager,Constructor injection and Method injection Is that it ?
0
votes
1answer
101 views

How to Inject a new Class to Overridden Class using Preference

I want to override __prepareLayout function from 'Magento\Sales\Block\Order\History' so I used the preference. In my di.xml <preference for="Magento\Sales\Block\Order\History" type="...
1
vote
1answer
50 views

Type Error occurred when creating object, attempting to use custom model from custom module

Yes I know, another "Type Error occurred when creating object" post... In addition, I'm probably going about this in a way that will make the seasoned M2 dev need a moment before reading ...
0
votes
1answer
41 views

when iam paasing arugment to helper from controller iam getting error magento 2.3

Iam Getting the below error Recoverable Error: Object of class Magento\Framework\App\ObjectManager could not be converted to string in /var/www/html/development/amt/app/code/vendor/...
0
votes
1answer
82 views

Filter custom attribute in product collection

I have created a custom attribute with name product_deisgn_proof. I want to filter this attribute using product collection in custom template file. When I try to fetch collection of product in an ...
0
votes
1answer
51 views

How to get product attribute without using Object manager?

How to get product attribute of a product without using Object manager directly, since using Object manager is not recommended?
0
votes
2answers
514 views

Magento 2 get product attribute value without objectManager

I load some related products inside a foreach and want to call some attribute values of these individual products. My current code below works fine with using $objectManager, but that's not the best ...
0
votes
3answers
1k views

Call to a member function get() on null

I am new to magento 2 and i have tried to get the store id. Here is my code simplifyed: class Mage{ private static $_objectManger; public function __construct( \Magento\Framework\...
0
votes
1answer
114 views

Get attribute value in magento2

I am using an object manager to get the attribute value even though it's not recommended. I am getting NULL in product-object which causing error "GetattributeText() on NULL". Below is the code that ...
1
vote
0answers
170 views

Call to a member function getAttributeText() on null

I have created an dropdown attribute programatically. Now i am trying to get an attribute value inside the class using object manager but unfortunately i am facing an error function ...
0
votes
1answer
60 views

How not to use ObjectManager in phtml from template

First a bit of context, and at the end, my question I added an EAV attribute to my customer. It's an attribute with multiple values, and I want to add it to the account information (for reasons). I'...
0
votes
0answers
37 views

Object manager in magento2 [duplicate]

What is object manager in magento2? Is it good to avoid use of it in Magento and where shall we make use of object manager ?
1
vote
1answer
38 views

Why avoiding ObjectManager can save us from multiple issues if Magento upgrade?

A new dependency injection framework will be used for the code. By avoiding ObjectManager in Magento 2, you won’t face multiple issues caused by the improvement. source:https://firebearstudio.com/blog/...
0
votes
1answer
2k views

Magento 2.2 Can we use Object Manager in Controller or Block? [duplicate]

To get product data, I am using object manager in my controller, but I read in docs that we should not use it directly. <?php pubic function execute() { $objectManager = \Magento\Framework\...
1
vote
1answer
179 views

How to remove custom attribute of category using object manager in magento 2

I created 4 custom attributes for category. Now I want to remove it. I want to use object manager for delete attributes and its values. See this image. Created attributes are display in this manner. ...
1
vote
1answer
59 views

What is use case to for directly calling new in Magento2

I know you should now init object using new keyword as it surpasses the DI But in few cases in core code is have observed the use of new keyword like in class module-catalog/Helper/Product Do any ...
5
votes
2answers
556 views

Argument replacement not working for type object

I am trying to replace an object using Argument Replacement but unfortunately I am unable to do so for type:object. Every time I am getting error: 1 exception(s): Exception #0 (Magento\Framework\...
2
votes
1answer
420 views

What is object Manager In Magento 2

I am looking at the concept of the object manager, but I didn't get any proper explanation about that. I also have gone through the below link, but they are just explaining the usage, etc.. https://...
1
vote
2answers
86 views

Save stock data programmatically

You know how you've got; $tempProduct->setData('price', 9.99); $tempProduct->getResource()->saveAttribute($tempProduct,'price'); I want to do the same, except for stock; $stockData = $...
0
votes
1answer
354 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 ...
0
votes
0answers
88 views

Magento 2.2.7 - How to access custom attributes of the associated products of a grouped product on final_price.phtml

Sorry in advance if this is a silly question. I'm fairly new to backend development. I have a custom attribute that determines whether or not a price should be visible on the frontend. It works just ...
0
votes
2answers
809 views

Magento 2 how to get Postcode from billing address in observer?

I cannot get the postcode from Users's billing Address,this is my code, everything works fine except for the postcode, which i'm not able to pull. $objectManager = \Magento\Framework\App\...
2
votes
2answers
86 views

How to securely run PHP scripts in Magento 2

I know that we can run php scripts by placing our script in root of magento 2 folder and we can load products, orders etc via object manager and perform our desired functionality. although this method ...
0
votes
1answer
111 views

Error when observer is executed after order is placed

I created a module in order to save order data to a custom table: <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="...
0
votes
1answer
81 views

Nicer Magento 2 code

How do I improve this code? I use it in ListProduct.php to get the base price in another currency for products in list.phtml. How can I do this without objectManager? Why should I not use ...
0
votes
1answer
182 views

How to get product rating using object manager in magento 2

i want to get products rating using object manager i tried below mention code but its not working for me please guide me $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $...
1
vote
3answers
832 views

Where to use object manager in Magento 2

I have doubt on object manager someone saying You should not use the ObjectManager directly! but I have questioned if I want to get customer session in my phtml how can I get?. that time can I use ...
0
votes
1answer
18 views

Trouble testing plugin with object manager

Issue: When attempting to test a plugin "after" method with $objectManager->create('Shopgate\Base\Model\Config')->startup(), the original startup() method is called but not my plugins ...
1
vote
1answer
45 views

Dependancy injection and shared/unshared object and cron job

Something interesting happens to Magento2 code and I cannot realise what I missed. The same code works flawlessly via browser and does not work via cron. (in adminhtml area) I calculate the result in ...
2
votes
1answer
59 views

How does objectmanager instantiated by objectmanagerinterface?

I always see objectmanager instantiated by objectmanagerinterface. But I never found di.xml that have preference of objectmanagerinterface to objectmanager. Is it something I have never found? Or is ...
4
votes
3answers
799 views

Magento 2 developer mode doesn't generates Interceptors

If a class has plugins and the deploy mode is set to developer the ObjectManager is supposed to generate an Interceptor of the class as needed. That's what happens when running bin/magento setup:di:...
3
votes
5answers
13k views

Get order id by order increment id in Magento 2

I want to get order id by order increment id. I have this code but it is returning empty value: $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $incrId = 100005363; $collection =...
3
votes
2answers
691 views

How do i create a shipment class object in magento 2?

i am trying to get tracking from csv and save to magento 2 order programmatically. i grabbed the create shipment & add tracking code from here https://www.scommerce-mage.com/blog/magento-2-how-to-...
1
vote
2answers
1k views

How to get child categories using object manager?

For now I'm getting category name. This is my code: app/code/Vendor/Module/view/frontend/templates/storecategories.phtml <?php $categoryId = 65; $_objectManager = \Magento\...
2
votes
1answer
89 views

Mocked shared instance incomplete on second identical integration test

I'm writing an integration test on a plugin that changes the action of an existing form. The plugin calls a helper method that decides whether the url should be changed and returns the result. I ...
0
votes
1answer
809 views

Magento 2 : How to get best seller product collection using object manager in home page custom slider?

How to add best seller products in home page custom slider. So, I need a best seller product collection in phtml file.
2
votes
3answers
6k views

how to get shipping method using order id in magento 2

I am trying to get the shipping method using Object Manager $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $order = $objectManager->create('Magento\Sales\Api\Data\...
0
votes
1answer
127 views

Add Date filter in object-manager

I have Code for getting all order But I want date filter in Object-manager. How Can I add date filter in it. I tried but I got Blank array. I am using Object manager in the script so I am suitable ...
0
votes
2answers
112 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 ...
8
votes
3answers
725 views

What is the use of "mapping" node in di.xml in Magento 2?

I am using Magento 2.2.5 have a look on file vendor\magento\module-sales\etc\di.xml <type name="Magento\Payment\Model\Checks\SpecificationFactory"> <arguments> <...