Questions tagged [object-manager]

Denotes question regarding Magento 2 Object Manager

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

Add product information like name, price and url to ("data" Object in) add-to-cart ajax function - Magento2

I am trying to get some more product data in the add-to-cart event (using ajax). So far, I can see the form works like this: $(document).on('ajax:addToCart', function (event, data) { console.log(...
TheFrakes's user avatar
  • 307
0 votes
2 answers
148 views

How can i remove object manager from my code of Magento 2

I don't want to use object manager, how can i change my code? In the past, i have used method cart $cart but it is deprecated <?php namespace Custom\ShippingMethod\Model\Carrier; use ...
Miron's user avatar
  • 59
0 votes
1 answer
92 views

How to instantiate an helper class from my custom module in a test program in the directory at the same level as the root of Magento?

With the code below, I'm trying to instantiate an helper class from my custom module. // Sanitize the $_GET[] value // Create an object of the order loaded with the $order_id passed as query string. $...
CodeForGood's user avatar
0 votes
1 answer
81 views

Magento continue shopping link to last added product’s category page

I've seen a few similar questions here when i searched but they all pertain to magento 1. This seems identical do what i want to do.. Redirect "Continue Shopping" Button to the Current ...
Head's user avatar
  • 125
1 vote
0 answers
264 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->...
user2270134's user avatar
1 vote
2 answers
443 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.
Kuldeep Sharma's user avatar
-1 votes
1 answer
445 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()...
Prits's user avatar
  • 626
2 votes
3 answers
549 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']); ...
IvoJongmans's user avatar
0 votes
1 answer
150 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.
Aniket Singh's user avatar
0 votes
1 answer
61 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 ...
A. Andersen's user avatar
0 votes
1 answer
77 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\...
SoD's user avatar
  • 3
0 votes
0 answers
60 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\...
Sonali Ghule's user avatar
0 votes
2 answers
500 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 ...
Hurrpadurr's user avatar
0 votes
3 answers
713 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 ...
user1799722's user avatar
0 votes
1 answer
70 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 ...
Paul Fan's user avatar
  • 614
0 votes
1 answer
125 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\...
Jonathan's user avatar
  • 103
3 votes
1 answer
608 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 ...
Chris Rogers's user avatar
1 vote
1 answer
3k 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/...
stanhook's user avatar
  • 131
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 ...
RichardB's user avatar
  • 325
0 votes
1 answer
42 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 ?
Giga Todadze's user avatar
1 vote
1 answer
609 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 69's user avatar
  • 135
1 vote
1 answer
64 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 ...
joeybab3's user avatar
  • 378
0 votes
1 answer
50 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/...
Sabareesh's user avatar
  • 328
0 votes
1 answer
418 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 ...
manoj kumar's user avatar
0 votes
1 answer
149 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?
Mr Zid's user avatar
  • 438
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 ...
JGeer's user avatar
  • 1,420
0 votes
3 answers
6k 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\...
marijanovic's user avatar
0 votes
1 answer
656 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 ...
Aashik's user avatar
  • 31
1 vote
0 answers
321 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 ...
Mr Zid's user avatar
  • 438
0 votes
1 answer
177 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'...
Jean-Marc SALIS's 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 ?
Zarna Parekh's 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/...
Sagar Parikh's user avatar
0 votes
1 answer
4k 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\...
temper's user avatar
  • 974
1 vote
1 answer
378 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. ...
Chirag Parmar's user avatar
1 vote
1 answer
193 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 ...
Vishwas Bhatnagar's user avatar
5 votes
2 answers
925 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\...
Narendra Vyas's user avatar
2 votes
1 answer
748 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://...
senthil's user avatar
  • 1,707
1 vote
2 answers
328 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 = $...
davidelias16's user avatar
0 votes
1 answer
513 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 ...
Михайло Годованюк's user avatar
0 votes
0 answers
208 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 ...
Amelia York's 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\...
Oscar Vazquez's user avatar
2 votes
2 answers
131 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 ...
Joey Leblanc's user avatar
0 votes
1 answer
197 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="...
Ángel Carlos del Pozo Muela's user avatar
0 votes
1 answer
101 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 ...
M2Newbie's user avatar
0 votes
1 answer
501 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(); $...
Shan Haider's user avatar
1 vote
4 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 ...
Pawankumar's user avatar
0 votes
1 answer
41 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 ...
tylersDisplayName's user avatar
1 vote
1 answer
112 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 ...
vistore's user avatar
  • 36
2 votes
1 answer
92 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 ...
Jinmo Chong's user avatar
5 votes
4 answers
2k 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:...
Daniel's user avatar
  • 2,199