Questions tagged [object-manager]

Denotes question regarding Magento 2 Object Manager

Filter by
Sorted by
Tagged with
0 votes
0 answers
20 views

how to get store name display in a shipping method

I'm new here, please help. when you click shipping method a display of store view name show below using knock out js to display.
user avatar
1 vote
0 answers
103 views

Magento 2 $quote->getAllItems(); set StoreId or Website

Try to catch the quote items, it's working fine. But when quote is not in default website, the request is empty. How to change website ID or store ID in quote request? Did try with: $quote->...
user avatar
1 vote
2 answers
55 views

How to Get Order Details in Magento 2?

Want to get the order details programmatically, need to use an object manager. But unfortunately, Magento 2 restricts the direct use of the ObjectManager.
user avatar
-1 votes
1 answer
115 views

Is there a way to save value in core config data using Magento 2 using object manager?

Is there a way to save the value in core config data using object manager like I will get the value by using I will get the value by $objectManager = \Magento\Framework\App\ObjectManager::getInstance()...
user avatar
  • 566
1 vote
3 answers
111 views

How to save stock attribute value ('qty') for a product with Magento 2 objectmanager?

I've found out how to do this with other attributes. For example a custom 'location' attribute: $product = $this->objectManager->get('Magento\Catalog\Model\Product')- >load($post['id']); ...
user avatar
0 votes
1 answer
36 views

HOW TO GET PRODUCT ATTRIBUTE AND AVAILABILITY?

I want to get the Product attribute using Object manager and check the availability of the product if its RTS I have to assign that product to a category id.
user avatar
0 votes
1 answer
46 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 ...
user avatar
0 votes
1 answer
24 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\...
user avatar
  • 3
0 votes
0 answers
54 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\...
user avatar
0 votes
2 answers
247 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 ...
user avatar
0 votes
3 answers
496 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 ...
user avatar
0 votes
1 answer
55 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 ...
user avatar
  • 518
0 votes
1 answer
102 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\...
user avatar
3 votes
1 answer
254 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 ...
user avatar
1 vote
1 answer
2k 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/...
user avatar
  • 121
0 votes
1 answer
75 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
0 votes
1 answer
31 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 ?
user avatar
1 vote
1 answer
217 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="...
user avatar
  • 135
1 vote
1 answer
60 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 ...
user avatar
  • 368
0 votes
1 answer
47 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/...
user avatar
  • 308
0 votes
1 answer
213 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 ...
user avatar
0 votes
1 answer
96 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?
user avatar
  • 428
0 votes
2 answers
1k 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 ...
user avatar
  • 1,498
0 votes
3 answers
3k 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\...
user avatar
0 votes
1 answer
313 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 ...
user avatar
  • 31
1 vote
0 answers
232 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 ...
user avatar
  • 428
0 votes
1 answer
102 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'...
user avatar
0 votes
0 answers
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 ?
user avatar
1 vote
1 answer
39 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/...
user avatar
0 votes
1 answer
3k 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\...
user avatar
  • 934
1 vote
1 answer
254 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. ...
user avatar
1 vote
1 answer
108 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 ...
user avatar
5 votes
2 answers
681 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\...
user avatar
2 votes
1 answer
521 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://...
user avatar
  • 1,608
1 vote
2 answers
144 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 = $...
user avatar
0 votes
1 answer
370 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
0 votes
0 answers
128 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 ...
user avatar
0 votes
2 answers
1k 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\...
user avatar
2 votes
2 answers
100 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 ...
user avatar
0 votes
1 answer
139 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="...
user avatar
0 votes
1 answer
96 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 ...
user avatar
0 votes
1 answer
289 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(); $...
user avatar
1 vote
3 answers
1k 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 ...
user avatar
0 votes
1 answer
32 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 ...
user avatar
  • 1,590
1 vote
1 answer
69 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 ...
user avatar
  • 36
2 votes
1 answer
68 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 ...
user avatar
4 votes
3 answers
1k 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:...
user avatar
  • 1,936
3 votes
5 answers
20k 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 =...
user avatar
3 votes
2 answers
856 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-...
user avatar
1 vote
2 answers
2k 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\...
user avatar
  • 601