PIĄTEK, SIE 07, 2015 POSTED BY PATRYK CHAMIER- CIEMIŃSKI
Sometimes you need to get to Magento admin panel but you don’t have an account, what then? Don’t worry, there is a simple solution.
You can add an admin account programmatically. Open index.php file in your project and right after Mage::run add the following block of code:
$adminUser = Mage::getModel('admin/user'); $adminUser->setData(array( 'username' => 'my_login', 'firstname' => 'my_firstname', 'lastname' => 'my_lastname', 'email' => 'firstname.lastname@example.org', 'password' => 'my_password', 'is_active' => 1 )); $adminUser->save(); $adminUser->setRoleIds(array(1))->setRoleUserId($adminUser->getUserId()); $adminUser->saveRelations();
First, the model instance is created. After that we set some data and save to database. Then we need to set a role and save relations. The code can be also put in a module install/upgrade script or executed from standalone script. If you put the code in index.php, remember to delete the code after you refresh the site. If you don’t do that, you will get an exception because some data are supposed to be unique.
Easy right? Hope this solution will be helpful.