0

I have created a custom page in magento, from this I want to send coupon code to customer which are new and already registered both. For this I have created a custom form with all information I needed, on submit form I am calling a ajax and my custom module handle this request.

But How to identify there that it is new customer and How to create a new customer account in controller action?

  • Pls check my answer it will helps you. – Nikunj Vadariya Oct 20 '16 at 10:57
2

Try something like below:

$customer_email = 'test@gmail.com';  // email adress that will pass by the questionaire 
    $customer_fname = 'test_firstname';      // we can set a tempory firstname here 
    $customer_lname = 'test_lastname';       // we can set a tempory lastname here 
    $passwordLength = 10;                    // the lenght of autogenerated password

    $customer = Mage::getModel('customer/customer');
    $customer->setWebsiteId(Mage::app()->getWebsite()->getId());
    $customer->loadByEmail($customer_email);
    /*
    * Check if the email exist on the system.
    * If YES,  it will not create a user account. 
    */

    if(!$customer->getId()) {
        $customer->setEmail($customer_email);
        $customer->setFirstname($customer_fname);
        $customer->setLastname($customer_lname);
        $customer->setPassword($customer->generatePassword($passwordLength));
    }
    try {
        $customer->save();
        $customer->setConfirmation(null);
        $customer->save();

        // Send welcome email
        $storeId = $customer->getSendemailStoreId();
        $customer->sendNewAccountEmail('registered', '', $storeId);
        //Make a "login" of new customer
        //Mage::getSingleton('customer/session')->loginById($customer->getId());

    }
    catch (Exception $ex) {
       echo 'error';
    }
0

use this code for check Customer Exist

$customer = Mage::getModel('customer/customer');
$customer->setWebsiteId(Mage::app()->getWebsite()->getId());
$customer->loadByEmail($customer_email);

if($customer->getId())
{
  "Customer Exist";
}

add add this this code http://www.onlinecode.org/customer-rgistration-programmatically-magento/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.