Thanks for posting solution to this issue, it's working fine with PS1.5 as well. I found a little typo in your manual - missing "d" in DB table creation causes problems in queries further:
I made a class override for PS1.5 based on your code - you can overwrite prestashop/override/classes/Customer.php with that code instead of editing core files.
<?php
class Customer extends CustomerCore
{
public function getByEmail($email, $passwd = null) {
if (!Validate::isEmail($email) || ($passwd && !Validate::isPasswd($passwd)))
die (Tools::displayError());
$sql = 'SELECT *
FROM `'._DB_PREFIX_.'customer`
WHERE `email` = \''.pSQL($email).'\'
'.Shop::addSqlRestriction(Shop::SHARE_CUSTOMER).'
'.(isset($passwd) ? 'AND `passwd` = \''.Tools::encrypt($passwd).'\'' : '').'
AND `deleted` = 0
AND `is_guest` = 0';
$result = Db::getInstance()->getRow($sql);
// == BEGIN ZEN-CART / OSCOMMERCE TO PRESTASHOP PASSWORD INTEGRATION ==
// == BY João Cunha -
[email protected]
// == @ 31/03/2012
// == USE AND MODIFY AT WILL
// == TESTED ON PRESTASHOP V1.4.7X
if (!$result) { //<- INVALID PRESTASHOP LOGIN, IT MAY BE A ZEN-CART / OSCOMMERCE PASSWORD
//CHECK IF THE GIVEN EMAIL MATCHES A ROW IN OUR LEGACY TABLE AND RETRIEVES THE LEGACY PASSWORD
$resultZC = Db::getInstance()->getRow('
SELECT `password`
FROM `osc_legacy_passwords`
WHERE `email` = \''.pSQL($email).'\'
AND `updated` = 0');
if (!$resultZC)
return false; //<- EMAIL NOT FOUND IN NONE OF THE TABLES, SO IT IS AN INVALID LOGIN
//ENCRYPTS THE GIVEN PASSWORD IN ZEN-CART / OSCOMMERCE FORMAT
$salt = substr($resultZC['password'], strrpos($resultZC['password'],':')+1, 2);
$ZCpassword = md5($salt . $passwd) . ':' . $salt;
if ($ZCpassword != $resultZC['password'])
return false; //<- WRONG ZEN-CART/OSCOMMERCE PASSWORD GIVEN
//WE'LL UPDATE THE CUSTOMER TABLE WITH ITS PRESTASHOP ENCRYPTED PASSWORD...
Db::getInstance()->Execute('
UPDATE `'._DB_PREFIX_ .'customer`
SET `passwd` = \''.md5(pSQL(_COOKIE_KEY_.$passwd)).'\'
WHERE `email` = \''.pSQL($email).'\'');
//...AND FLAG IT AS UPDATED, SO THE NEXT TIME HE LOGS IN, HE WON'T ENTER THIS ROUTINE.
Db::getInstance()->Execute('
UPDATE `osc_legacy_passwords`
SET `updated` = 1
WHERE `email` = \''.pSQL($email).'\'');
//USER IS AUTHENTICATED, OVERWRITE THE EMPTY $result VARIABLE
$result = Db::getInstance()->getRow('
SELECT *
FROM `'._DB_PREFIX_ .'customer`
WHERE `active` = 1
AND `email` = \''.pSQL($email).'\'
AND `deleted` = 0
AND `is_guest` = 0');
}
// == END ZEN-CART / OSCOMMERCE TO PRESTASHOP PASSWORD INTEGRATION
$this->id = $result['id_customer'];
foreach ($result as $key => $value)
if (key_exists($key, $this))
$this->{$key} = $value;
return $this;
}
}
EDIT: Forgot to mention - I've renamed legacy passwords table name to osc_legacy_passwords so you'll probably have to rename it (either table name in DB or hardcoded in script).