Questions tagged [object-manager]

Denotes question regarding Magento 2 Object Manager

43 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
3
votes
0answers
37 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 ...
3
votes
0answers
999 views

Working with Models and Databases in Magento 2

So I've been following along with these questions : https://stackoverflow.com/questions/31983546/in-magento-2-what-is-the-correct-way-for-getmodel/31984198 https://stackoverflow.com/questions/...
2
votes
0answers
54 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 ...
2
votes
1answer
55 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->...
2
votes
1answer
229 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” ...
2
votes
0answers
320 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', ...
2
votes
0answers
127 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 ...
2
votes
1answer
187 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:...
1
vote
0answers
25 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 ...
1
vote
1answer
60 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
25 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 ...
1
vote
2answers
59 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 = $...
1
vote
3answers
150 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 ...
1
vote
1answer
35 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 ...
1
vote
2answers
38 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
54 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
68 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
238 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, ...
1
vote
0answers
391 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 ...
1
vote
1answer
288 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 ...
1
vote
1answer
2k 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 ...
1
vote
1answer
122 views

Magento 2: How to avoid objectManager in Model?

I have achieved Magento 2: How to change Weight field for DHL Shipping Method [SOLVED] I tried to put protected $_product; public function __construct(\Magento\Catalog\Model\Product $product) { ...
1
vote
0answers
24 views

Proxy object - when should I use them in fact

I have yesterday read great tutorial about Proxy objects: http://alanstorm.com/magento_2_object_manager_proxy_objects/ I understand that I should use them to lazy load object which have can be slowly ...
1
vote
1answer
80 views

Magento 2: Guide for All Collections

For now, I'm not able to find any guide for this. If I need to get all collection say for Example all Orders List so I will go to Vendor Magento Folder, Particular Module's di.xml file & checking ...
0
votes
1answer
25 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
0answers
11 views

Magento 2 populate dropdown value from database with condition

I have trouble populating my select in my form. I tried to get the value from my custom database with condition but still failed. Here what I'm trying to do with my code. app/code/Testing/Basic/...
0
votes
1answer
26 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
0answers
19 views

How do I create a new instance of a dependency, instead of using the existing singleton instance?

I'm trying to get all configurable options of a simple product by calling linkManagement->getChildren() in a plugin which runs after Magento\ConfigurableProduct\Block\Product\View\Type\Configurable....
0
votes
1answer
37 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 ...
0
votes
0answers
31 views

Object manager in magento2

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 ?
0
votes
1answer
165 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
27 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
1answer
50 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
83 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(); $...
0
votes
1answer
14 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 ...
0
votes
0answers
74 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
0answers
491 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(); ...
0
votes
1answer
350 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::...
0
votes
1answer
751 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 ...
0
votes
1answer
525 views

Magento2 getting - Error filtering template error after add custom attribute value programmatically

Getting this error when reload page after adding value programmatically in a custom attribute. And when i delete that value which i added programmatically then its working fine. Error filtering ...
0
votes
1answer
518 views

Magento 2 : Can not add method/class in __construct()

I have a collection.php file. I am adding some function into that which calls other models.As per Magento 2 first we have to add object managerger interface. And then we can call other model.like ...
0
votes
1answer
79 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\...