<?php
class MageCheck_Tutorial_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
$this-> createCustomer();
}
public function createCustomer()
{
// ...
}
}
/**
* @var \Magento\Customer\Model\Customer $customer
*/
protected $_customer;
public function __construct(
\Magento\Customer\Model\Customer $customer
){
$this->_customer = $customer;
}
public function execute()
{
$this->createCustomer();
}
public function createCustomer()
{
// ...
}
public function createCustomer()
{
$websiteId = Mage::app()->getWebsite()->getId();
$store = Mage::app()->getStore();
$_customer = array(
'firstname' => 'Mage',
'lastname' => 'Check',
'email' => 'example@magecheck.com',
'password' => '123456789',
'password_hash' => 'b7a9552802ce455e170a1c73a47796e4:6c',
'add_date' => '2018-11-21',
'birth_date' => '1980-01-01',
'gender' => 1, // Male (1) or Female (2)
'telephone' => '1234567890',
);
$customer = \Mage::getModel('customer/customer');
$customer->setWebsiteId($websiteId)
->setStore($store)
->setFirstname($_customer['firstname'])
->setLastname($_customer['lastname'])
->setEmail($_customer['email'])
->setPasswordHash($_customer['password'])
->setCreatedAt($_customer['add_date'])
->setDob($_customer['birth_date'])
->setGender($_customer['gender']);
$customer->save();
}
public function createCustomer()
{
$customer = $this->_customer;
$firstName = 'Mage';
$lastName = 'Check';
$customer->setEmail('example@magecheck.com');
$customer->setFirstname($firstName);
$customer->setLastname($lastName);
$customer->setPassword('123456789');
$customer->save();
}
This is the sample way to Programmatically create Customers in Magento!
Have you decided on an online Business Plan website?