[-] BO : Bug Fixed #PSCFV-3270 - CSV Import addresses + multishop
This commit is contained in:
@@ -284,6 +284,24 @@ class CustomerCore extends ObjectModel
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve customers by email address
|
||||||
|
*
|
||||||
|
* @static
|
||||||
|
* @param $email
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function getCustomersByEmail($email)
|
||||||
|
{
|
||||||
|
$sql = 'SELECT *
|
||||||
|
FROM `'._DB_PREFIX_.'customer`
|
||||||
|
WHERE `email` = \''.pSQL($email).'\'
|
||||||
|
'.Shop::addSqlRestriction(Shop::SHARE_CUSTOMER);
|
||||||
|
|
||||||
|
return Db::getInstance()->ExecuteS($sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check id the customer is active or not
|
* Check id the customer is active or not
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1909,10 +1909,10 @@ class AdminImportControllerCore extends AdminController
|
|||||||
{
|
{
|
||||||
if (Validate::isEmail($address->customer_email))
|
if (Validate::isEmail($address->customer_email))
|
||||||
{
|
{
|
||||||
$customer = Customer::customerExists($address->customer_email, true);
|
// a customer could exists in different shop
|
||||||
if ($customer)
|
$customer_list = Customer::getCustomersByEmail($address->customer_email);
|
||||||
$address->id_customer = (int)$customer;
|
|
||||||
else
|
if (count($customer_list) == 0)
|
||||||
$this->errors[] = sprintf(
|
$this->errors[] = sprintf(
|
||||||
Tools::displayError('%1$s does not exist in database %2$s (ID: %3$s) cannot be saved'),
|
Tools::displayError('%1$s does not exist in database %2$s (ID: %3$s) cannot be saved'),
|
||||||
Db::getInstance()->getMsgError(),
|
Db::getInstance()->getMsgError(),
|
||||||
@@ -1970,10 +1970,35 @@ class AdminImportControllerCore extends AdminController
|
|||||||
if (($field_error = $address->validateFields(UNFRIENDLY_ERROR, true)) === true &&
|
if (($field_error = $address->validateFields(UNFRIENDLY_ERROR, true)) === true &&
|
||||||
($lang_field_error = $address->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true)
|
($lang_field_error = $address->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true)
|
||||||
{
|
{
|
||||||
if ($address->id && $address->addressExists($address->id))
|
if (count($customer_list) > 0)
|
||||||
$res = $address->update();
|
{
|
||||||
if (!$res)
|
$filter_list = array();
|
||||||
$res = $address->add();
|
foreach ($customer_list as $customer)
|
||||||
|
{
|
||||||
|
if (in_array($customer['id_customer'], $filter_list))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
$filter_list[] = $customer['id_customer'];
|
||||||
|
|
||||||
|
unset($address->id);
|
||||||
|
$address->id_customer = $customer['id_customer'];
|
||||||
|
$res = $address->add();
|
||||||
|
|
||||||
|
if (!$res)
|
||||||
|
$this->errors[] = sprintf(
|
||||||
|
Tools::displayError('%1$s (ID: %2$s) cannot be saved'),
|
||||||
|
$info['alias'],
|
||||||
|
(isset($info['id']) ? $info['id'] : 'null')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ($address->id && $address->addressExists($address->id))
|
||||||
|
$res = $address->update();
|
||||||
|
if (!$res)
|
||||||
|
$res = $address->add();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!$res)
|
if (!$res)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user