Questions tagged [object-manager]

Denotes question regarding Magento 2 Object Manager

Filter by
Sorted by
Tagged with
1
vote
2answers
40 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
117 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
42 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
27 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
17 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
69 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
40 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
34 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
60 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
32 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
65 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
13 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
26 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
26 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 ...
2
votes
1answer
68 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:...
0
votes
2answers
688 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 =...
2
votes
2answers
204 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-...
0
votes
0answers
50 views

Call external API on billing step of Checkout

I need to make an external API call during checkout, after the shipping step. This call will use data from the cart. When the API is called, the cart data is passed to my app, returned, and displayed ...
0
votes
2answers
290 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
0answers
33 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
209 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.
1
vote
3answers
806 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
38 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
32 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 ...
7
votes
3answers
188 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> <...
2
votes
0answers
26 views

Can Magento 2 Proxies be used to handle non existing class

I am building an extension which is dependent on multiple third party payment gateways. So I have created a special service class which gives the respective payment gateway class object depending on ...
0
votes
0answers
67 views

Magento2: What is Dependency Injection(Di) and Object Management (Object Manager)?

Both are most important topics for learning Magento2. I want to discuss what learn from google, pdf,notes,magento documentation etc. Overview: Magento 2 provides a new approach to working with ...
0
votes
0answers
180 views

Magento 2: grid data source definition in compact form

I have my own grid data provider \Vendor\Module\Ui\DataProvider\Grid\Base class Base extends \Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider { public function ...
2
votes
1answer
45 views

how to pass required variable in class using object manager magento2

I have a class $class = new Abc\Cde\Efg('variable'); how can i implement this using object manager $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $class = $objectManager->...
0
votes
0answers
24 views

what is addSharedInstance and when to use it in integration testing

I was looking for some information on addSharedInstance and an example of when to use it in the integration testing
7
votes
5answers
2k views

What is the use of pagefactory in Magento 2?

Although I refer some blog of pagefactory, I don't understand the use of page factory. There is one code in the controller. Could you please explain to me how it works? public function execute() { ...
2
votes
1answer
145 views

Compilation error due to final class Vault in Magento version before 2.2.0

I am writing a plugin on class Magento\Payment\Model\MethodInterface: <type name=“Magento\Payment\Model\MethodInterface”> <plugin name=“mageworx_ordereditor_change_title_print_order” ...
3
votes
3answers
217 views

What is difference on both Object manager?

What is difference on both and how will i understand to where should i use any one of these ? \Magento\Framework\ObjectManagerInterface \Magento\Framework\App\ObjectManager::getInstance() if i use ...
0
votes
1answer
64 views

Magento 2 Increment id

How can I get increment_id on Magento 2 checkout page? >$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); >$quoteId = $objectManager-> create('Magento\Checkout\Model\...
0
votes
1answer
54 views

Magento 2.2.2 - Class not found in Factory

Namespace/Modulename/Model/WebService/ClientFactory.php <?php namespace Namespace\Modulename\Model\WebService; use Magento\Framework\ObjectManagerInterface; use Namespace\Modulename\Model\...
0
votes
1answer
705 views

Magento 2: Use of ObjectManager in Controller

Let's say I want to load a order item in a controller. I can use: $order = $this->_objectManager->create('Magento\Sales\Model\Order\item')->load($id); I see this happening in a lot of free ...
2
votes
0answers
243 views

What is the use of load() method in collection?

CASE productCollectionFactory load function gives data in query but not in object $collection = $this->_productCollectionFactory->create() ->addAttributeToFilter('status', ...
1
vote
2answers
216 views

Magento 2.2.3 - Can't get the URL of logo from core_config_data

I was trying to pull the logo_src from the database table core_config_data but can't return it on the frontend. I was trying to do this via objectManager and know that this is not the correct way. ...
3
votes
2answers
84 views

Magento 2.2.5: Add Student Instead of Update Student

So instead of update the student, this code add a new student. I'm looking for a way that not using object manager, because the objectmanager is recommended not to use. So when i searching for how to ...
4
votes
2answers
483 views

Passing Arguments to contructor

I am having a situation where I need to instantiate a helper object from my custom module in list.phtml file. For this I have two options either I need to overrride productlist.php and pass the helper ...
1
vote
2answers
34 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\...
2
votes
1answer
77 views

ObjectManager in category init [duplicate]

Why Magento is using $this->_objectManager->create() directly in function _initCategory in file vendor/magento/module-catalog/Controller/Adminhtml/Category.php? protected function _initCategory(...
1
vote
1answer
41 views

SetId on category results on exception

I would like to set my ID on the category Category::setId but this results in the following exception: "No such entity with id = x". My code: $catFactory = $objectManager->get(CategoryFactory::...
1
vote
0answers
66 views

How can I get Customer's Address?

Update This is not a duplicate of this. I've referenced that question, but it didn't give me what I looking for. I need to create a file with specific data on customer. I tried few methods I found ...
1
vote
0answers
174 views

Magento 2 : When running integration tests, how can I override some of the dependencies that are injected?

I am running an integration test for Magento 2, but I am at a certain point that my integration test needs a different dependency than my production code. Without going too much into detail as to why, ...
0
votes
2answers
2k views

Magento 2.2.3 - Get all categories in store programmatically

I'm trying to gather all categories in my store. As a start I'm using the object manager. I know it is bad practise to use the objectmanager directly, but after this I will convert it into a block ...
1
vote
1answer
582 views

How to Add Product to Wishlist Programmatically Using Object Manager in Magento2

I have existing product slider and that slider made with object manager so I want to add the product to wishlist by Product id Using Object Manager.
0
votes
4answers
767 views

How to get secure baseurl (https) in magento 2? [duplicate]

with this code im getting http://url.com i want to get https://url.com using object manager. i'm using magento 2.0.4 echo $store->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_WEB); echo '&...
0
votes
1answer
67 views

How to get names, IDs and details of my categories without falling in to bad practice?

It's been commonly accepted you should never use \Magento\Framework\App\ObjectManager::getInstance() I can link sources explaining why if needed. Given this how would I go about getting the names of ...
3
votes
3answers
2k views

Magento 2: -How to get product reviews, each review with a star

<?php $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $product = $objectManager->get('Magento\Framework\Registry')->registry('current_product'); $storeManager = $...