php Magento 1.9新用户

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php Magento 1.9新用户相关的知识,希望对你有一定的参考价值。

<?php
$mageFilename = 'app/Mage.php';
if (!file_exists($mageFilename)) {
	echo $mageFilename." was not found";
	exit;
}
require_once $mageFilename;
Mage::app();

try {
	//create new user by providing details below
	$user = Mage::getModel('admin/user')
	            ->setData(array(
		            'username'  => 'madmin1',
		            'firstname' => 'John',
		            'lastname'  => 'Doe',
		            'email'     => 'john@example.com',
		            'password'  => '5W#*q11%Rl0dI6h',
		            'is_active' => 1
	            ))->save();

} catch (Exception $e) {
	echo $e->getMessage();
	exit;
}

try {
	//create new role
	$role = Mage::getModel("admin/roles")
	            ->setName('Inchoo')
	            ->setRoleType('G')
	            ->save();

	//give "all" privileges to role
	Mage::getModel("admin/rules")
	    ->setRoleId($role->getId())
	    ->setResources(array("all"))
	    ->saveRel();

} catch (Mage_Core_Exception $e) {
	echo $e->getMessage();
	exit;
} catch (Exception $e) {
	echo 'Error while saving role.';
	exit;
}

try {
	//assign user to role
	$user->setRoleIds(array($role->getId()))
	     ->setRoleUserId($user->getUserId())
	     ->saveRelations();

} catch (Exception $e) {
	echo $e->getMessage();
	exit;
}

echo 'Admin User sucessfully created!<br /><br /><b>THIS FILE WILL NOW TRY TO DELETE ITSELF, BUT PLEASE CHECK TO BE SURE!</b>';
@unlink(__FILE__);
?>

以上是关于php Magento 1.9新用户的主要内容,如果未能解决你的问题,请参考以下文章

Magento 1.9 - 创建新页面不起作用

magento 1.9 新添加的产品没有显示在分类页面?

自定义模块仅允许Magento 1.9中的完全管理员权限

magento 1.9 nginx 404

magento 1.9 上传后图片前后台无法正常显示

在Magento 1.9中安装Magento 2的扩展