2015-12-14 16:07:18 +01:00

47 lines
1.2 KiB
PHP

<?php
class Customer extends CustomerCore
{
public function getByEmail($email, $passwd = null, $ignore_guest = true)
{
if (($passwd && !Validate::isPasswd($passwd)))
die (Tools::displayError());
$result = Db::getInstance()->getRow('
SELECT *
FROM `'._DB_PREFIX_.'customer`
WHERE `email` = \''.pSQL($email).'\'
'.Shop::addSqlRestriction(Shop::SHARE_CUSTOMER).'
'.(isset($passwd) ? 'AND `passwd` = \''.pSQL(Tools::encrypt($passwd)).'\'' : '').'
AND `deleted` = 0
'.($ignore_guest ? ' AND `is_guest` = 0' : ''));
if (!$result) {
$result = Db::getInstance()->getRow('
SELECT *
FROM `'._DB_PREFIX_.'customer`
WHERE `email` = \''.pSQL($email).'\'
'.Shop::addSqlRestriction(Shop::SHARE_CUSTOMER).'
'.(isset($passwd) ? 'AND `passwd` = \''.pSQL(Tools::encryptOld($passwd)).'\'' : '').'
AND `deleted` = 0
'.($ignore_guest ? ' AND `is_guest` = 0' : ''));
if ($result) {
$customer = new Customer((int) $result['id_customer']);
$customer->passwd = Tools::encrypt($passwd);
$customer->save();
}
}
if (!$result)
return false;
$this->id = $result['id_customer'];
foreach ($result as $key => $value)
if (array_key_exists($key, $this))
$this->{$key} = $value;
return $this;
}
}