Thursday, February 16, 2012

Create admin user by code

Here is a piece of code that will allow you to create admin users. It's really useful if you forget the admin password: Create a file called adminuser.php on the same level as index.php (in the root of the application) with the following content:
error_reporting(E_ALL | E_STRICT);
$mageFilename = 'app/Mage.php';
require_once $mageFilename;
ini_set('display_errors', 1);

Mage::app('default');//if you changed the code for the default store view change it here also
$username = 'yourUsername';//desired username
$firstname = "Firstname";//desired firstname
$lastname = "Lastname";//desired lastname
$email = "";//desired email
$pass = 'yourPaSSWordHere';//desired password
$user = Mage::getModel('admin/user')->load($username, 'username');
if ($user->getId()){
 echo "User {$username} already exists";
$result = $user->validate();
if (is_array($result)){
 foreach ($result as $res){
  echo $res."\n";
 echo "User {$username} was created";
catch (Exception $e){
 echo $e->getMessage();
Now call in you browser this url You should see a message on the screen with the result of your action. Cheers, Marius.

Friday, February 10, 2012

Keep products in the wishlist after adding them to cart.

Here is an interesting question I found on the Magento forum:
Leave Wishlist as it is after adding item to shopping cart?

Here is what you can do.
Override the wishlist index controller (app/code/core/Mage/Wishlist/controllers/IndexController.php) or edit it if you don't care about keeping the core clean (I recommend to keep it clean though)
and inside the method cartAction() there is this line:
$item->addToCart($cart, true);
The second parameter of the method addToCart means 'Remove from wishlist'.
You can change the second parameter to false or remove it completely - it defaults to false.