first time here.
I am trying to migrate this code from Magento 1.6 to M 2.0. I have to note that I just have basic knowledge with programming so this is very hard for me. I have done some research where I found Mage change to Bootstrap in M 2.0. and getModel have changed also. I am not asking for the complete solution as I want to practice. Can you tell me what things are wrong or guide me a little so I can find it by myself?
$mageFilename = '../app/Mage.php';
require_once $mageFilename;
umask(0);
Mage::app('default');
$intRootCategoryId = Mage::app()->getStore()->getRootCategoryId();
$objCategories = Mage::getModel('catalog/category')->getCollection();
$arrCategories = array();
A couple of thing that might steer you in the right direction.
First, Magento's bootstrap process has changed enough that writing these sorts of one off simple shell scripts isn't quite as easy as it once was. It might be possible, but I haven't seen anyone do it yet. Instead, you can create a Magento module, and use that module to add a new command to magento's
bin/magento
console program.Second, objects in Magento are instantiated using an object manager class. However, making things a bit more confusing, you're not meant to use the object manager class directly -- instead you need to use automatic constructor dependency injection to inject the objects into your classes. I wrote an article series that covers this if you're interested.