cancel
Showing results for 
Search instead for 
Did you mean: 

Mage:: migration to Magento 2

Mage:: migration to Magento 2

I found a wonderfully helpful message asked by GoatHater and answered by Dmitry_Fedyuk. which showed how to migrate  an old style Mage::app call to Magento 2, namely

 

Mage::app()->getStore()->getName();

becomes:

$om = \Magento\Framework\App\ObjectManager::getInstance();
$manager = $om->get('Magento\Store\Model\StoreManagerInterface');
$store = $manager->getStore(null)->getName();

 

My question, which I think could help many developers, is:  "where do I find the information or what is the logic that tells me that app()->getStore() is now a method of the StoreManagerInterface class" ?

 

For example if my M1 code was

$users = mage::getModel('customer/customer')->getCollection()->getData();

What thought process or reference source do I need to lead me to the correct class to use in Magento 2 ?

 

Any pointers will be greatly appreciated

 

 

1 REPLY

Re: Mage:: migration to Magento 2

Hello Sandersonmc

 

I totally agree with you, we have faced the same problem when I was starting working on Magento 2.x.  Our personal opinion is we have gone through the core classes of Magento and their methods and follow the way used in core files. And using object manager we started creating  their object and called their methods. Through this approach, we got a great chance to learn more about Magento and started seamlessly working.