protected function execute(InputInterface $input, OutputInterface $output)
{
$this->detectMagento($output, true);
if (!$this->initMagento()) {
return;
}
$dialog = $this->getHelper('dialog');
// Email
$email = $this->getHelper('parameter')->askEmail($input, $output);
// Password
$password = $this->getHelper('parameter')->askPassword($input, $output, 'password', false);
// Firstname
if (($firstname = $input->getArgument('firstname')) == null) {
$firstname = $dialog->ask($output, '<question>Firstname:</question>');
}
// Lastname
if (($lastname = $input->getArgument('lastname')) == null) {
$lastname = $dialog->ask($output, '<question>Lastname:</question>');
}
$website = $this->getHelper('parameter')->askWebsite($input, $output);
// create new customer
$customer = $this->getCustomerModel();
$customer->setWebsiteId($website->getId());
$customer->loadByEmail($email);
$outputPlain = $input->getOption('format') === null;
$table = array();
if (!$customer->getId()) {
$customer->setWebsiteId($website->getId());
$customer->setEmail($email);
$customer->setFirstname($firstname);
$customer->setLastname($lastname);
$customer->setPassword($password);
$customer->save();
$customer->setConfirmation(null);
$customer->save();
if ($outputPlain) {
$output->writeln('<info>Customer <comment>' . $email . '</comment> successfully created</info>');
} else {
$table[] = array($email, $password, $firstname, $lastname);
}
} else {
if ($outputPlain) {
$output->writeln('<error>Customer ' . $email . ' already exists</error>');
}
}
if (!$outputPlain) {
$this->getHelper('table')->setHeaders(array('email', 'password', 'firstname', 'lastname'))->renderByFormat($output, $table, $input->getOption('format'));
}
}