update customer email along with phone number in cart_customer_guest_detail table
This commit is contained in:
@@ -63,37 +63,14 @@ class CartCustomerGuestDetailCore extends ObjectModel
|
||||
);
|
||||
}
|
||||
|
||||
public static function getCustomerDefaultDetails($email)
|
||||
public static function getIdCustomerGuest($email)
|
||||
{
|
||||
return Db::getInstance()->getRow(
|
||||
'SELECT * FROM `'._DB_PREFIX_.'cart_customer_guest_detail`
|
||||
return Db::getInstance()->getValue(
|
||||
'SELECT `id_customer_guest_detail` FROM `'._DB_PREFIX_.'cart_customer_guest_detail`
|
||||
WHERE `id_cart` = 0 AND `email` = "'.pSQL($email).'"'
|
||||
);
|
||||
}
|
||||
|
||||
public static function updateCustomerPhoneNumber($email, $phone)
|
||||
{
|
||||
if ($customerDetail = self::getCustomerDefaultDetails($email)) {
|
||||
$objCartCustomerGuestDetail = new CartCustomerGuestDetail($customerDetail['id_customer_guest_detail']);
|
||||
$objCartCustomerGuestDetail->phone = $phone;
|
||||
return $objCartCustomerGuestDetail->save();
|
||||
} else {
|
||||
$objCustomer = new Customer();
|
||||
if (Validate::isLoadedObject($customer = $objCustomer->getByEmail($email, null, false))) {
|
||||
$objCartCustomerGuestDetail = new CartCustomerGuestDetail();
|
||||
$objCartCustomerGuestDetail->id_cart = 0;
|
||||
$objCartCustomerGuestDetail->id_gender = $customer->id_gender;
|
||||
$objCartCustomerGuestDetail->firstname = $customer->firstname;
|
||||
$objCartCustomerGuestDetail->lastname = $customer->lastname;
|
||||
$objCartCustomerGuestDetail->email = $customer->email;
|
||||
$objCartCustomerGuestDetail->phone = $phone;
|
||||
return $objCartCustomerGuestDetail->save();
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function getCustomerPhone($email)
|
||||
{
|
||||
return Db::getInstance()->getValue(
|
||||
|
||||
@@ -141,10 +141,6 @@ class CustomerCore extends ObjectModel
|
||||
const STATUS_DELETED = 2;
|
||||
|
||||
protected $webserviceParameters = array(
|
||||
'objectMethods' => array(
|
||||
'add' => 'addWs',
|
||||
'update' => 'updateWs'
|
||||
),
|
||||
'fields' => array(
|
||||
'id_default_group' => array('xlink_resource' => 'groups'),
|
||||
'id_lang' => array('xlink_resource' => 'languages'),
|
||||
@@ -268,6 +264,7 @@ class CustomerCore extends ObjectModel
|
||||
}
|
||||
$success = parent::add($autodate, $null_values);
|
||||
$this->updateGroup($this->groupBox);
|
||||
$this->updateCustomerAdditionalDetails(CartCustomerGuestDetail::getIdCustomerGuest($this->email));
|
||||
return $success;
|
||||
}
|
||||
|
||||
@@ -290,25 +287,22 @@ class CustomerCore extends ObjectModel
|
||||
}
|
||||
}
|
||||
|
||||
return parent::update(true);
|
||||
$objOldCustomer = new Customer($this->id);
|
||||
$success = parent::update(true);
|
||||
$this->updateCustomerAdditionalDetails(CartCustomerGuestDetail::getIdCustomerGuest($objOldCustomer->email));
|
||||
return $success;
|
||||
}
|
||||
|
||||
public function addWs($autodate = true, $null_values = false)
|
||||
public function updateCustomerAdditionalDetails($idCustomerGuest)
|
||||
{
|
||||
if ($this->phone) {
|
||||
CartCustomerGuestDetail::updateCustomerPhoneNumber($this->email, $this->phone);
|
||||
}
|
||||
|
||||
return $this->add($autodate, $null_values);
|
||||
}
|
||||
|
||||
public function updateWs($autodate = true, $null_values = false)
|
||||
{
|
||||
if ($this->phone) {
|
||||
CartCustomerGuestDetail::updateCustomerPhoneNumber($this->email, $this->phone);
|
||||
}
|
||||
|
||||
return $this->update($autodate, $null_values);
|
||||
$objCartCustomerGuestDetail = new CartCustomerGuestDetail($idCustomerGuest);
|
||||
$objCartCustomerGuestDetail->id_cart = 0;
|
||||
$objCartCustomerGuestDetail->id_gender = $this->id_gender;
|
||||
$objCartCustomerGuestDetail->firstname = $this->firstname;
|
||||
$objCartCustomerGuestDetail->lastname = $this->lastname;
|
||||
$objCartCustomerGuestDetail->email = $this->email;
|
||||
$objCartCustomerGuestDetail->phone = $this->phone;
|
||||
return $objCartCustomerGuestDetail->save();
|
||||
}
|
||||
|
||||
public function delete()
|
||||
@@ -348,6 +342,9 @@ class CustomerCore extends ObjectModel
|
||||
}
|
||||
|
||||
CartRule::deleteByIdCustomer((int)$this->id);
|
||||
// delete customer data from customerGuest table
|
||||
$objCartCustomerGuestDetail = new CartCustomerGuestDetail(CartCustomerGuestDetail::getIdCustomerGuest($this->email));
|
||||
$objCartCustomerGuestDetail->delete();
|
||||
return parent::delete();
|
||||
}
|
||||
|
||||
|
||||
@@ -1331,6 +1331,7 @@ class WebserviceSpecificManagementBookingsCore Extends ObjectModel implements We
|
||||
$objCustomer->lastname = $customerDetails['lastname'];
|
||||
$objCustomer->email = $customerDetails['email'];
|
||||
$objCustomer->passwd = md5(time()._COOKIE_KEY_);
|
||||
$objCustomer->phone = ($customerDetails['phone'] ? $customerDetails['phone'] : '');
|
||||
$objCustomer->cleanGroups();
|
||||
$objCustomer->add();
|
||||
$this->bookingCustomer = $objCustomer;
|
||||
@@ -1345,8 +1346,10 @@ class WebserviceSpecificManagementBookingsCore Extends ObjectModel implements We
|
||||
|
||||
if (isset($customerDetails['email']) && Validate::isEmail($customerDetails['email'])) {
|
||||
$this->bookingCustomer->email = $customerDetails['email'];
|
||||
} else {
|
||||
$customerDetails['email'] = $this->bookingCustomer->email;
|
||||
}
|
||||
|
||||
if (isset($customerDetails['phone']) && Validate::isPhoneNumber($customerDetails['phone'])) {
|
||||
$this->bookingCustomer->phone = $customerDetails['phone'];
|
||||
}
|
||||
|
||||
$this->bookingCustomer->save();
|
||||
@@ -1389,10 +1392,6 @@ class WebserviceSpecificManagementBookingsCore Extends ObjectModel implements We
|
||||
$objAddress->save();
|
||||
}
|
||||
|
||||
if (isset($customerDetails['phone']) && Validate::isPhoneNumber($customerDetails['phone'])) {
|
||||
CartCustomerGuestDetail::updateCustomerPhoneNumber($customerDetails['email'], $customerDetails['phone']);
|
||||
}
|
||||
|
||||
// to remove the older non ordered cart for this customer.
|
||||
$this->context->cookie->id_cart = $this->context->cart->id;
|
||||
$this->context->updateCustomer($this->bookingCustomer, 1);
|
||||
|
||||
@@ -1003,8 +1003,8 @@ class AdminCustomersControllerCore extends AdminController
|
||||
$this->errors[] = Tools::displayError('Some error ocurred while deleting the Customer');
|
||||
return;
|
||||
} else {
|
||||
if ($customerDetail = CartCustomerGuestDetail::getCustomerDefaultDetails($customerEmail)) {
|
||||
$objCartCustomerGuestDetail = new CartCustomerGuestDetail($customerDetail['id_customer_guest_detail']);
|
||||
if ($idCustomerGuest = CartCustomerGuestDetail::getIdCustomerGuest($customerEmail)) {
|
||||
$objCartCustomerGuestDetail = new CartCustomerGuestDetail($idCustomerGuest);
|
||||
$objCartCustomerGuestDetail->phone = preg_replace('/[0-9]/', '0', $objCustomer->phone);
|
||||
$objCartCustomerGuestDetail->email = $objCustomer->email;
|
||||
$objCartCustomerGuestDetail->save();
|
||||
@@ -1102,7 +1102,6 @@ class AdminCustomersControllerCore extends AdminController
|
||||
$this->errors[] = Tools::displayError('Password can not be empty.');
|
||||
$this->display = 'edit';
|
||||
} elseif ($customer = parent::processAdd()) {
|
||||
CartCustomerGuestDetail::updateCustomerPhoneNumber($customer->email, Tools::getValue('phone'));
|
||||
$this->context->smarty->assign('new_customer', $customer);
|
||||
return $customer;
|
||||
}
|
||||
@@ -1142,10 +1141,7 @@ class AdminCustomersControllerCore extends AdminController
|
||||
}
|
||||
}
|
||||
|
||||
if ($res = parent::processUpdate()) {
|
||||
CartCustomerGuestDetail::updateCustomerPhoneNumber($this->object->email, Tools::getValue('phone'));
|
||||
return $res;
|
||||
}
|
||||
return parent::processUpdate();
|
||||
} else {
|
||||
$this->errors[] = Tools::displayError('An error occurred while loading the object.').'
|
||||
<b>'.$this->table.'</b> '.Tools::displayError('(cannot load object)');
|
||||
|
||||
@@ -2846,9 +2846,6 @@ class AdminImportControllerCore extends AdminController
|
||||
|
||||
if ($res && isset($customer_groups)) {
|
||||
$customer->updateGroup($customer_groups);
|
||||
if ($phoneRequired) {
|
||||
CartCustomerGuestDetail::updateCustomerPhoneNumber($customer->email, $customer->phone);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -463,9 +463,8 @@ class AuthControllerCore extends FrontController
|
||||
$customer->active = 1;
|
||||
|
||||
if (!count($this->errors)) {
|
||||
$customer->phone = Tools::getValue('phone');
|
||||
if ($customer->add()) {
|
||||
$phone = Tools::getValue('phone');
|
||||
CartCustomerGuestDetail::updateCustomerPhoneNumber($customer->email, $phone);
|
||||
if (!$customer->is_guest) {
|
||||
if (!$this->sendConfirmationMail($customer)) {
|
||||
$this->errors[] = Tools::displayError('The email cannot be sent.');
|
||||
@@ -609,12 +608,10 @@ class AuthControllerCore extends FrontController
|
||||
} else {
|
||||
$customer->is_guest = 0;
|
||||
}
|
||||
$customer->phone = Tools::getValue('phone');
|
||||
if (!$customer->save()) {
|
||||
$this->errors[] = Tools::displayError('An error occurred while creating your account.');
|
||||
} else {
|
||||
// save customer phone number in cart_customer_guest_detail
|
||||
$phone = Tools::getValue('phone');
|
||||
CartCustomerGuestDetail::updateCustomerPhoneNumber($customer->email, $phone);
|
||||
$_POST['phone'] = $phoneAddress;
|
||||
|
||||
foreach ($addresses_types as $addresses_type) {
|
||||
|
||||
@@ -94,6 +94,8 @@ class IdentityControllerCore extends FrontController
|
||||
$this->errors[] = Tools::displayError('Invaid phone number.');
|
||||
} elseif ($phone && Tools::strlen($phone) > $rules['size']['phone']) {
|
||||
$this->errors[] = sprintf(Tools::displayError('Phone number is too long. (%s chars max).'), $rules['size']['phone']);;
|
||||
} else {
|
||||
$this->customer->phone = $phone;
|
||||
}
|
||||
|
||||
if (!count($this->errors)) {
|
||||
@@ -123,7 +125,6 @@ class IdentityControllerCore extends FrontController
|
||||
$this->context->cookie->passwd = $this->customer->passwd;
|
||||
}
|
||||
if ($this->customer->update()) {
|
||||
CartCustomerGuestDetail::updateCustomerPhoneNumber($this->customer->email, $phone);
|
||||
$this->context->cookie->customer_lastname = $this->customer->lastname;
|
||||
$this->context->cookie->customer_firstname = $this->customer->firstname;
|
||||
$this->context->smarty->assign('confirmation', 1);
|
||||
|
||||
@@ -125,6 +125,8 @@ class OrderOpcControllerCore extends ParentOrderController
|
||||
$this->errors[] = Tools::displayError('Please enter a valid Mobile phone number.', false);
|
||||
} elseif (Tools::strlen($phone) > $rules['size']['phone']) {
|
||||
$this->errors[] = sprintf(Tools::displayError('Mobile phone number is too long. (%s chars max).'), $rules['size']['phone']);
|
||||
} else {
|
||||
$this->context->customer = $phone;
|
||||
}
|
||||
|
||||
$_POST['lastname'] = $_POST['customer_lastname'];
|
||||
@@ -157,7 +159,6 @@ class OrderOpcControllerCore extends ParentOrderController
|
||||
);
|
||||
if (!count($this->errors)) {
|
||||
$return['isSaved'] = (bool)$this->context->customer->update();
|
||||
CartCustomerGuestDetail::updateCustomerPhoneNumber($this->context->customer->email, $phone);
|
||||
|
||||
} else {
|
||||
$return['isSaved'] = false;
|
||||
|
||||
Reference in New Issue
Block a user