Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [object-manager]

The tag has no usage guidance.

2
votes
0answers
15 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
28 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
12 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
27 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
9 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
5
votes
4answers
305 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
49 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
4answers
200 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
33 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
37 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
211 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
65 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
51 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
66 views

Magento 2.2.5: Add Student Instead of Update Student

I'm doing 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 ...
3
votes
2answers
339 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
27 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
1answer
31 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(...
0
votes
1answer
30 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
64 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 ...
0
votes
0answers
86 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
0answers
24 views

transactionFactory is working to save data in the data base as bulk kindly please solve my issue?

transactionFactory is working to save data in the data base as bulk kindly please check the Object manager is create model project model or not?? public function __construct( \Magento\Framework\DB\...
0
votes
2answers
897 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
370 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
393 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
62 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
571 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 = $...
1
vote
3answers
1k views

Magento 2.2.2 how to check if current page is a CMS page in .phtml file?

I am using the following code to check if the current page is Product detail page: $objectManagerCms = \Magento\Framework\App\ObjectManager::getInstance(); $registry = $objectManagerCms->get('...
0
votes
0answers
31 views

Pass an object as argument for object manager in magento 2

I want to instantiate ApiContext class and pass an object as argument : $apiContext = new \PayPal\Rest\ApiContext( new \PayPal\Auth\OAuthTokenCredential('id','secret') ); so I tried to make the ...
0
votes
1answer
129 views

How to remove object manager

Below is my code how to write this code without object manager. $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); //get current product $product = $objectManager-&...
1
vote
0answers
334 views

Magento 2 - Obtain attribute values in template phtml file

Is there a proper method of getting an attributes list of values (drop down list) within a template phtml file that is being called from a CMS block? I currently have a file mytemplate.phtml and I'm ...
3
votes
2answers
1k views

Create object using object manager in magento 2

I want to load that $configLoader without constructor i tried like below, but it's not working please tell me any other way to load that ConfigLoaderInterface without constructor. <?php namespace ...
1
vote
2answers
2k views

How to load multiple id's for products in magento 2 using objectManager?

I want to load array(2,6,7) of products id's using objectManager and get details of the product. I found most of the Magento-1.9 solutions. Is there anything for Magento 2? I found this, <?php $...
1
vote
1answer
162 views

Only dependency assignment operations are allowed in constructor. No other operations are allowed

MEQP2: How to resolve below issue? abstract class ClassName extends \Magento\Backend\App\Action { public function __construct( ... \Magento\Catalog\Helper\Product $productHelper, ...
1
vote
0answers
19 views

Class instatiation with data

I have created custom Factory class for my custom model class. Of course basically you can instantiate it by calling $this->objectManager->create(Someobject::class);. But, ObjectManage has also ...
0
votes
0answers
229 views

Magento 2: Class 'ObjectManager' not found

I have a cron to launch to erase a database table, here is the cron <?php require_once 'Controller/Adminhtml/NewProduct.php'; $cron=new \Managys\Pricing\Controller\Adminhtml\NewProduct(); ...
1
vote
1answer
31 views

ClassName::class vs FQN (eg '/Magento/Catalog/Model/Product')

In magento2's code style its mentioned to use ::class. see: http://devdocs.magento.com/guides/v2.0/coding-standards/code-standard-php.html however in objectManager or resource model initialization i ...
1
vote
2answers
561 views

Get category image without object manager

I previously used ObjectManager to get current category image. but it sometimes caused problems to me. Like loading blank page without no content, slower loading time etc.. , also I saw in a few ...
0
votes
1answer
196 views

Magento 2 - Replacing an injected argument via constructor throws an error

I am trying to replace an argument via configuration file (di.xml)that's been injected in constructor but it throws an error. Any help will be appreciated Fatal error: Uncaught TypeError: Argument ...
0
votes
1answer
205 views

Magento2 different between Object Manager get and create method [duplicate]

In magento2, we have use object manager: $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); and use get() and create() method $cookieManager = $objectManager->get('{...
1
vote
1answer
417 views

Set cookie lifetime in phtml

I want to set the cookie lifetime in my phtml file. I am using the following code: $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $cookieManager = $objectManager->get('...
0
votes
1answer
148 views

get Product not work - Magento 2

I'm trying to create a php file to be inserted in my Magento root that prints all the products and the associated fields. <?php $objectManager = \Magento\Framework\App\ObjectManager::...
3
votes
5answers
4k views

Get customer name from customer id using object manager

I try to use object manager to retrieve customer first name and last name using customer id like this: $customer = $objectManager->get('Magento\Customer\Api\CustomerRepositoryInterface')->...
1
vote
1answer
307 views

Can a virtual type be used as a dependency for a class?

I'm trying to do something new with virtual types. I understand that you can create these in your di.xml and use them as arguments for other types in di.xml. But can I also declare a virtual type and ...
1
vote
2answers
834 views

Magento 2: The direct use of ObjectManager is discouraged [duplicate]

when I am check using object manager it gives me warning that The direct use of ObjectManager is discouraged. Inject necessary dependencies via constructor". How to solve this problem and I also want ...
2
votes
0answers
104 views

Correct way to use an array of SKUs to filter collection results in M2

Working with Magento EE v2.1.7. I have an arbitrary array of SKUs that I wish to use to filter the products I'm returning on all category pages. I've created a custom module to generate this array ...
0
votes
1answer
434 views

How is the array $data parameter set in Magento 2 (dataObject constructor)

In https://github.com/SnowdogApps/magento2-menu/blob/master/Block/Menu.php, a plugin that makes it possible to replace the default menu, the constructor of the block looks like below. For all ...
-2
votes
2answers
1k views

How to get customer id using object manager in Magento 2 [closed]

How to get customer id using object manager?
1
vote
1answer
1k views

Get plain value from custom variable in php with objectManager

I want to get a plain value from custom variable (defined on admin) in php with objectManager. storeID is in $order->getStore()->getId() Custom Variable Code is 'mycustomvar' why does ...
3
votes
8answers
18k views

How to load product collection in Magento 2

How to load product collection in Magento 2 and what is the difference between Magento 1 and Magento 2 load product collection
1
vote
2answers
664 views

Magento2 Passing Arguments to class in Construct

I am trying to instantiate the below class in my custom code \Magento\Solr\Model\Client\Solarium like public function __construct( \Magento\Solr\Model\Client\Solarium $solr ) {....}...