diff --git a/admin/themes/default/template/controllers/customers/helpers/view/view.tpl b/admin/themes/default/template/controllers/customers/helpers/view/view.tpl index 8213ed88d..467ea386e 100644 --- a/admin/themes/default/template/controllers/customers/helpers/view/view.tpl +++ b/admin/themes/default/template/controllers/customers/helpers/view/view.tpl @@ -664,6 +664,38 @@ {/if} + {if $customer_guests && count($customer_guests)} +
+
+ + {l s='Customer Guests'} + {count($customer_guests)} +
+ + + + + + + + + + + + {foreach $customer_guests AS $key => $customer_guest} + + + + + + + + + {/foreach} + +
{l s='Email'}{l s='First name'}{l s='Last name'}{l s='phone'}{l s='Actions'}
{$customer_guest['email']}{$customer_guest['firstname']}{$customer_guest['lastname']}{$customer_guest['phone']}
+
+ {/if} diff --git a/admin/themes/default/template/controllers/customers/modals/_customer_guest_form.tpl b/admin/themes/default/template/controllers/customers/modals/_customer_guest_form.tpl new file mode 100644 index 000000000..12e9baa32 --- /dev/null +++ b/admin/themes/default/template/controllers/customers/modals/_customer_guest_form.tpl @@ -0,0 +1,53 @@ +{* +* Since 2010 Webkul. +* +* NOTICE OF LICENSE +* +* All right is reserved, +* Please go through this link for complete license : https://store.webkul.com/license.html +* +* DISCLAIMER +* +* Do not edit or add to this file if you wish to upgrade this module to newer +* versions in the future. If you wish to customize this module for your +* needs please refer to https://store.webkul.com/customisation-guidelines/ for more information. +* +* @author Webkul IN +* @copyright Since 2010 Webkul IN +* @license https://store.webkul.com/license.html +*} + + diff --git a/admin/themes/default/template/controllers/customers/modals/index.php b/admin/themes/default/template/controllers/customers/modals/index.php new file mode 100644 index 000000000..ccbf6cb72 --- /dev/null +++ b/admin/themes/default/template/controllers/customers/modals/index.php @@ -0,0 +1,29 @@ + +* @copyright 2010-2020 Webkul IN +* @license https://store.webkul.com/license.html +*/ + +header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); +header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); + +header('Cache-Control: no-store, no-cache, must-revalidate'); +header('Cache-Control: post-check=0, pre-check=0', false); +header('Pragma: no-cache'); + +header('Location: ../../../../../../'); +exit; diff --git a/classes/CartCustomerGuestDetail.php b/classes/CartCustomerGuestDetail.php deleted file mode 100644 index 2d4ae2fa6..000000000 --- a/classes/CartCustomerGuestDetail.php +++ /dev/null @@ -1,124 +0,0 @@ - -* @copyright 2010-2022 Webkul IN -* @license https://store.webkul.com/license.html -*/ - -class CartCustomerGuestDetailCore extends ObjectModel -{ - public $id_customer_guest_detail; - public $id_cart; - public $id_gender; - public $firstname; - public $lastname; - public $email; - public $phone; - public $date_add; - public $date_upd; - - public static $definition = array( - 'table' => 'cart_customer_guest_detail', - 'primary' => 'id_customer_guest_detail', - 'fields' => array( - 'id_cart' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), - 'id_gender' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), - 'firstname' => array('type' => self::TYPE_STRING, 'validate' => 'isName', 'size' => 32), - 'lastname' => array('type' => self::TYPE_STRING, 'validate' => 'isName', 'size' => 32), - 'email' => array('type' => self::TYPE_STRING, 'validate' => 'isEmail', 'size' => 128), - 'phone' => array('type' => self::TYPE_STRING, 'validate' => 'isPhoneNumber', 'size' => 32), - 'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'), - 'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'), - ), - ); - - public static function getCartCustomerGuest($id_cart) - { - return Db::getInstance()->getValue(' - SELECT `id_customer_guest_detail` - FROM `'._DB_PREFIX_.'cart_customer_guest_detail` - WHERE `id_cart` = '.(int)$id_cart - ); - } - - public static function getCustomerGuestDetail($id_customer_guest_detail) - { - return Db::getInstance()->getRow(' - SELECT `id_gender`, `firstname`, `lastname`, `email`, `phone` - FROM `'._DB_PREFIX_.'cart_customer_guest_detail` - WHERE `id_customer_guest_detail` = '.(int)$id_customer_guest_detail - ); - } - - public static function getIdCustomerGuest($email) - { - 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 getCustomerPhone($email) - { - return Db::getInstance()->getValue( - 'SELECT `phone` FROM `'._DB_PREFIX_.'cart_customer_guest_detail` - WHERE `id_cart` = 0 AND `email` = "'.pSQL($email).'"' - ); - } - - public function validateGuestInfo() - { - $isValid = true; - if (!trim($this->firstname) || !Validate::isName($this->firstname)) { - $isValid = false; - } - if (!trim($this->lastname) || !Validate::isName($this->lastname)) { - $isValid = false; - } - if (!trim($this->email) || !Validate::isEmail($this->email)) { - $isValid = false; - } - if (!trim($this->phone) || !Validate::isPhoneNumber($this->phone)) { - $isValid = false; - } - - $className = 'CartCustomerGuestDetail'; - $rules = call_user_func(array($className, 'getValidationRules'), $className); - - if (isset($rules['size']['firstname'])) { - if (Tools::strlen(trim($this->firstname)) > $rules['size']['firstname']) { - $isValid = false; - } - } - if (isset($rules['size']['lastname'])) { - if (Tools::strlen(trim($this->lastname)) > $rules['size']['lastname']) { - $isValid = false; - } - } - if (isset($rules['size']['email'])) { - if (Tools::strlen(trim($this->email)) > $rules['size']['email']) { - $isValid = false; - } - } - if (isset($rules['size']['phone'])) { - if (Tools::strlen(trim($this->phone)) > $rules['size']['phone']) { - $isValid = false; - } - } - - return $isValid; - } -} \ No newline at end of file diff --git a/classes/Customer.php b/classes/Customer.php index 5bd03cb43..fd5fe9f97 100644 --- a/classes/Customer.php +++ b/classes/Customer.php @@ -283,9 +283,7 @@ class CustomerCore extends ObjectModel } } - $objOldCustomer = new Customer($this->id); - $success = parent::update(true); - return $success; + return parent::update(true); } public function delete() @@ -327,6 +325,9 @@ class CustomerCore extends ObjectModel CartRule::deleteByIdCustomer((int)$this->id); // delete customer data from customerGuest table + $objCustomerGuestDetail = new CustomerGuestDetail(); + $objCustomerGuestDetail->deleteCustomerGuestByIdCustomer($this->id); + return parent::delete(); } @@ -518,18 +519,6 @@ class CustomerCore extends ObjectModel return Cache::retrieve($cache_id); } - public static function getPhone($id_customer) - { - - return Db::getInstance()->getValue( - 'SELECT cgd.`phone` - FROM `'._DB_PREFIX_.'customer` c - INNER JOIN `'._DB_PREFIX_.'cart_customer_guest_detail` cgd - ON (cgd.`email` = c.`email`) - WHERE `id_cart` = 0 AND c.`id_customer` = '.(int)($id_customer) - ); - } - public static function getCustomerIdAddress($id_customer, $use_cache = true) { $cache_id = 'Customer::getCustomerIdAddress'.(int)$id_customer; diff --git a/classes/CustomerGuestDetail.php b/classes/CustomerGuestDetail.php new file mode 100644 index 000000000..f40bf3006 --- /dev/null +++ b/classes/CustomerGuestDetail.php @@ -0,0 +1,258 @@ + +* @copyright 2010-2022 Webkul IN +* @license https://store.webkul.com/license.html +*/ + +class CustomerGuestDetailCore extends ObjectModel +{ + public $id_customer_guest_detail; + public $id_customer; + public $id_gender; + public $firstname; + public $lastname; + public $email; + public $phone; + public $date_add; + public $date_upd; + + public static $definition = array( + 'table' => 'customer_guest_detail', + 'primary' => 'id_customer_guest_detail', + 'fields' => array( + 'id_customer' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), + 'id_gender' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), + 'firstname' => array('type' => self::TYPE_STRING, 'validate' => 'isName', 'size' => 32), + 'lastname' => array('type' => self::TYPE_STRING, 'validate' => 'isName', 'size' => 32), + 'email' => array('type' => self::TYPE_STRING, 'validate' => 'isEmail', 'size' => 128), + 'phone' => array('type' => self::TYPE_STRING, 'validate' => 'isPhoneNumber', 'size' => 32), + 'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'), + 'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'), + ), + ); + + + /** + * Get the customer guest id by id cart. + * + * @param int id_cart + * @return int|false id_customer_guest_detail if exists + */ + public static function getCustomerGuestIdByIdCart($id_cart) + { + return Db::getInstance()->getValue(' + SELECT `id_customer_guest_detail` + FROM `'._DB_PREFIX_.'cart_customer_guest` + WHERE `id_cart` = '.(int) $id_cart + ); + } + + /** + * set the customer guest id for the id cart. + * + * @param int id_cart + * @param int id_customer_guest_detail + * @return bool True on success, false on failure + */ + public function saveCustomerGuestInCart($idCart, $idCustomerGuestDetail) + { + return Db::getInstance()->insert( + 'cart_customer_guest', + array( + 'id_cart' => (int) $idCart, + 'id_customer_guest_detail' => (int) $idCustomerGuestDetail + ) + ); + } + + /** + * removes the customer guest id for the id cart. + * + * @param int id_cart + * @return bool True on success, false on failure + */ + public function deleteCustomerGuestInCart($idCart) + { + return Db::getInstance()->delete( + 'cart_customer_guest', + ' `id_cart`='.(int) $idCart + ); + } + + /** + * Removes this guest's ID from all related cart entries. + * + * @return bool True on success, false on failure + */ + public function deleteCustomerGuestFromCart() + { + return Db::getInstance()->delete( + 'cart_customer_guest', + '`id_customer_guest_detail` = ' . (int) $this->id + ); + } + + public function delete() + { + $this->deleteCustomerGuestFromCart(); + + return parent::delete(); + } + + /** + * Deletes the guest profiles created by a customer. + * + * @param int $idCustomer Customer ID + * @param int $offset Number of guests to skip + * @return bool True on success, false on failure + */ + public function deleteCustomerGuestByIdCustomer($idCustomer, $offset = 0) + { + $guests = $this->getCustomerGuestsByIdCustomer((int)$idCustomer); + if (empty($guests)) { + return true; + } + + $guestsToDelete = array_slice($guests, $offset); + if (empty($guestsToDelete)) { + return true; + } + + $res = true; + foreach ($guestsToDelete as $guest) { + $customerGuestDetail = new CustomerGuestDetail($guest['id_customer_guest_detail']); + $res &= $customerGuestDetail->delete(); + } + + return $res; + } + + /** + * Retrieves guest profiles created by a customer using the "booking for someone else" feature. + * + * @param int $idCustomer The customer ID + * @param string $firstname Optional first name filter + * @param string $lastname Optional last name filter + * @param string $email Optional email filter + * @return array List of matching guest profiles + */ + public function getCustomerGuestsByIdCustomer($idCustomer, $firstname = '', $lastname = '', $email = '') + { + $sql = 'SELECT cgd.`id_customer_guest_detail`, cgd.`email`, cgd.`firstname`, cgd.`lastname`, cgd.`phone` + FROM `' . _DB_PREFIX_ . 'customer_guest_detail` cgd + LEFT JOIN `' . _DB_PREFIX_ . 'cart_customer_guest` ccg + ON ccg.`id_customer_guest_detail` = cgd.`id_customer_guest_detail` + WHERE cgd.`id_customer` = '.(int) $idCustomer; + + if ($firstname !== '') { + $sql .= ' AND cgd.`firstname` LIKE "%'.pSQL($firstname).'%"'; + } + + if ($lastname !== '') { + $sql .= ' AND cgd.`lastname` LIKE "%'.pSQL($lastname).'%"'; + } + + if ($email !== '') { + $sql .= ' AND cgd.`email` LIKE "%'.pSQL($email).'%"'; + } + + $sql .= ' GROUP BY cgd.`id_customer_guest_detail` ORDER BY cgd.`date_add` DESC'; + + return Db::getInstance()->executeS($sql); + } + + /** + * Retrieves guest information using the Id. + * + * @param int id_customer_guest_detail + * @return array customer guest details. + */ + public static function getCustomerGuestDetailById($idCustomerGuestDetail) + { + return Db::getInstance()->getRow(' + SELECT `id_gender`, `firstname`, `lastname`, `email`, `phone` + FROM `'._DB_PREFIX_.'customer_guest_detail` + WHERE `id_customer_guest_detail` = '.(int) $idCustomerGuestDetail + ); + } + + /** + * Retrieves guest information using the email. + * + * @param int email + * @return int|false id customer guest details. + */ + public static function getCustomerGuestByEmail($email, $idCustomer = null, $idCart = 0) + { + return Db::getInstance()->getValue( + 'SELECT cgd.`id_customer_guest_detail` FROM `'._DB_PREFIX_.'customer_guest_detail` as cgd + LEFT JOIN `'._DB_PREFIX_.'cart_customer_guest` ccg + ON ccg.`id_customer_guest_detail` = cgd.`id_customer_guest_detail` + WHERE cgd.`email` = "'.pSQL($email).'"'. + (!is_null($idCart) ? ' AND (ccg.`id_cart` = '.(int) $idCart.' '. (($idCart) ? ')' : ' OR ISNULL(ccg.`id_cart`)) ') : ' '). + (!is_null($idCustomer) ? ' AND cgd.`id_customer` = '.(int) $idCustomer : ' ') + ); + } + + /** + * Validates the Guest profile details. + * + * @return bool return true or false after validating the guest profile. + */ + public function validateGuestInfo() + { + $isValid = true; + if (!trim($this->firstname) || !Validate::isName($this->firstname)) { + $isValid = false; + } + if (!trim($this->lastname) || !Validate::isName($this->lastname)) { + $isValid = false; + } + if (!trim($this->email) || !Validate::isEmail($this->email)) { + $isValid = false; + } + if (!trim($this->phone) || !Validate::isPhoneNumber($this->phone)) { + $isValid = false; + } + + $className = 'CustomerGuestDetail'; + $rules = call_user_func(array($className, 'getValidationRules'), $className); + + if (isset($rules['size']['firstname'])) { + if (Tools::strlen(trim($this->firstname)) > $rules['size']['firstname']) { + $isValid = false; + } + } + if (isset($rules['size']['lastname'])) { + if (Tools::strlen(trim($this->lastname)) > $rules['size']['lastname']) { + $isValid = false; + } + } + if (isset($rules['size']['email'])) { + if (Tools::strlen(trim($this->email)) > $rules['size']['email']) { + $isValid = false; + } + } + if (isset($rules['size']['phone'])) { + if (Tools::strlen(trim($this->phone)) > $rules['size']['phone']) { + $isValid = false; + } + } + + return $isValid; + } +} diff --git a/classes/PaymentModule.php b/classes/PaymentModule.php index e15ac46d1..6d38afb8b 100644 --- a/classes/PaymentModule.php +++ b/classes/PaymentModule.php @@ -400,16 +400,16 @@ abstract class PaymentModuleCore extends Module } // save customer guest information - if ($id_customer_guest_detail = CartCustomerGuestDetail::getCartCustomerGuest($this->context->cart->id)) { - if (Validate::isLoadedObject($objCartCustomerGuestDetail = new CartCustomerGuestDetail( - $id_customer_guest_detail + if ($idCustomerGuestDetail = CustomerGuestDetail::getCustomerGuestIdByIdCart($this->context->cart->id)) { + if (Validate::isLoadedObject($objCustomerGuestDetail = new CustomerGuestDetail( + $idCustomerGuestDetail ))) { $objOrderCustomerGuestDetail = new OrderCustomerGuestDetail(); - $objOrderCustomerGuestDetail->id_gender = $objCartCustomerGuestDetail->id_gender; - $objOrderCustomerGuestDetail->firstname = $objCartCustomerGuestDetail->firstname; - $objOrderCustomerGuestDetail->lastname = $objCartCustomerGuestDetail->lastname; - $objOrderCustomerGuestDetail->email = $objCartCustomerGuestDetail->email; - $objOrderCustomerGuestDetail->phone = $objCartCustomerGuestDetail->phone; + $objOrderCustomerGuestDetail->id_gender = $objCustomerGuestDetail->id_gender; + $objOrderCustomerGuestDetail->firstname = $objCustomerGuestDetail->firstname; + $objOrderCustomerGuestDetail->lastname = $objCustomerGuestDetail->lastname; + $objOrderCustomerGuestDetail->email = $objCustomerGuestDetail->email; + $objOrderCustomerGuestDetail->phone = $objCustomerGuestDetail->phone; $objOrderCustomerGuestDetail->id_order = (int)$order->id; $objOrderCustomerGuestDetail->save(); } @@ -1236,9 +1236,9 @@ abstract class PaymentModuleCore extends Module ); } // send mail to customer guest if customer booked for someone other. - if ($id_customer_guest_detail = OrderCustomerGuestDetail::isCustomerGuestBooking($order->id)) { + if ($idCustomerGuestDetail = OrderCustomerGuestDetail::isCustomerGuestBooking($order->id)) { if ($objOrderCustomerGuestDetail = new OrderCustomerGuestDetail( - $id_customer_guest_detail + $idCustomerGuestDetail )) { if (Validate::isEmail($objOrderCustomerGuestDetail->email)) { $data['{firstname}'] = $objOrderCustomerGuestDetail->firstname; @@ -1391,7 +1391,7 @@ abstract class PaymentModuleCore extends Module } // End foreach $order_detail_list // delete cart feature prices after booking creation success - HotelRoomTypeFeaturePricing::deleteFeaturePrices($id_cart); + HotelRoomTypeFeaturePricing::deleteByIdCart($id_cart); if (count($cart_rules)) { foreach ($cart_rules as $idCartRule => $cartRule) { diff --git a/classes/checkoutProcess/CheckoutCustomerDetailsStep.php b/classes/checkoutProcess/CheckoutCustomerDetailsStep.php index 6bccd6e83..c75c4f5f6 100644 --- a/classes/checkoutProcess/CheckoutCustomerDetailsStep.php +++ b/classes/checkoutProcess/CheckoutCustomerDetailsStep.php @@ -39,9 +39,9 @@ class CheckoutCustomerDetailsStepCore extends AbstractCheckoutStepCore } } elseif (Tools::getValue('proceed_to_payment')) { $guestInfoComplete = true; - if ($id_customer_guest_detail = CartCustomerGuestDetail::getCartCustomerGuest($this->context->cart->id)) { + if ($idCustomerGuestDetail = CustomerGuestDetail::getCustomerGuestIdByIdCart($this->context->cart->id)) { $guestInfoComplete = false; - $objCustomerGuestDetail = new CartCustomerGuestDetail($id_customer_guest_detail); + $objCustomerGuestDetail = new CustomerGuestDetail($idCustomerGuestDetail); if ($objCustomerGuestDetail->validateGuestInfo()) { $guestInfoComplete = true; } diff --git a/controllers/admin/AdminAddressesController.php b/controllers/admin/AdminAddressesController.php index 51e7a7817..4a6e665b6 100644 --- a/controllers/admin/AdminAddressesController.php +++ b/controllers/admin/AdminAddressesController.php @@ -579,8 +579,7 @@ class AdminAddressesControllerCore extends AdminController $customer = Customer::searchByName($email); if (!empty($customer)) { $customer = $customer['0']; - $phone = Customer::getPhone($customer['id_customer']); - echo json_encode(array('infos' => pSQL($customer['firstname']).'_'.pSQL($customer['lastname']).'_'.pSQL($customer['company']).'_'.pSQL($customer['id_customer']).'_'.pSQL($phone))); + echo json_encode(array('infos' => pSQL($customer['firstname']).'_'.pSQL($customer['lastname']).'_'.pSQL($customer['company']).'_'.pSQL($customer['id_customer']).'_'.pSQL($customer['phone']))); } } die; diff --git a/controllers/admin/AdminCustomerPreferencesController.php b/controllers/admin/AdminCustomerPreferencesController.php index 0526cc277..76bfa40d6 100644 --- a/controllers/admin/AdminCustomerPreferencesController.php +++ b/controllers/admin/AdminCustomerPreferencesController.php @@ -121,6 +121,16 @@ class AdminCustomerPreferencesControllerCore extends AdminController 'cast' => 'intval', 'type' => 'bool' ), + 'PS_CUSTOMER_GUEST_MAX_LIMIT' => array( + 'title' => $this->l('Maximum Guests per Customer'), + 'validation' => 'isUnsignedInt', + 'cast' => 'intval', + 'size' => 5, + 'type' => 'text', + 'class' => 'fixed-width-xl', + 'hint' => $this->l('Enter the maximum number of guest profiles a customer can create when using the "Booking for Someone Else" option.'), + 'desc' => $this->l('Set as 0 for no limit.') + ), ), 'submit' => array( 'title' => $this->l('Save'), diff --git a/controllers/admin/AdminCustomersController.php b/controllers/admin/AdminCustomersController.php index f81342a8f..cf9237c8b 100644 --- a/controllers/admin/AdminCustomersController.php +++ b/controllers/admin/AdminCustomersController.php @@ -975,6 +975,9 @@ class AdminCustomersControllerCore extends AdminController $customerLanguage = new Language($customer->id_lang); $shop = new Shop($customer->id_shop); + + $objCustomerGuestDetail = new CustomerGuestDetail(); + $customerGuests = $objCustomerGuestDetail->getCustomerGuestsByIdCustomer($customer->id); $this->tpl_view_vars = array( 'customer' => $customer, 'gender' => $gender, @@ -1021,7 +1024,8 @@ class AdminCustomersControllerCore extends AdminController 'connections' => $connections, // Referrers 'referrers' => $referrers, - 'show_toolbar' => true + 'show_toolbar' => true, + 'customer_guests' => $customerGuests, ); return parent::renderView(); } @@ -1038,11 +1042,11 @@ class AdminCustomersControllerCore extends AdminController $this->errors[] = Tools::displayError('Some error ocurred while deleting the Customer'); return; } else { - if ($idCustomerGuest = CartCustomerGuestDetail::getIdCustomerGuest($customerEmail)) { - $objCartCustomerGuestDetail = new CartCustomerGuestDetail($idCustomerGuest); - $objCartCustomerGuestDetail->phone = preg_replace('/[0-9]/', '0', $objCustomer->phone); - $objCartCustomerGuestDetail->email = $objCustomer->email; - $objCartCustomerGuestDetail->save(); + if ($idCustomerGuest = CustomerGuestDetail::getCustomerGuestByEmail($customerEmail, false)) { + $objCustomerGuestDetail = new CustomerGuestDetail($idCustomerGuest); + $objCustomerGuestDetail->phone = preg_replace('/[0-9]/', '0', $objCustomer->phone); + $objCustomerGuestDetail->email = $objCustomer->email; + $objCustomerGuestDetail->save(); } } @@ -1220,14 +1224,6 @@ class AdminCustomersControllerCore extends AdminController $this->errors[] = Tools::displayError('Phone number is required.'); } } - $className = 'CartCustomerGuestDetail'; - $rules = call_user_func(array($className, 'getValidationRules'), $className); - if ($phone && !Validate::isPhoneNumber($phone)) { - $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']); - } - $customer = new Customer(); $this->errors = array_merge($this->errors, $customer->validateFieldsRequiredDatabase()); @@ -1433,17 +1429,128 @@ class AdminCustomersControllerCore extends AdminController $this->ajaxDie(json_encode($response)); } + public function ajaxProcessInitGuestModal() + { + $response['hasError'] = 1; + if (Validate::isLoadedObject($objCustomerGuestDetail = new CustomerGuestDetail((int) Tools::getValue('id_customer_guest_detail')))) { + $this->context->smarty->assign( + array( + 'genders' => Gender::getGenders(), + 'customerGuestDetail' => $objCustomerGuestDetail, + ) + ); + $modal = array( + 'modal_id' => 'customer-guest-modal', + 'modal_class' => 'customer_guest_modal', + 'modal_title' => '  '.$this->l('Guest details'), + 'modal_content' => $this->context->smarty->fetch('controllers/customers/modals/_customer_guest_form.tpl'), + 'modal_actions' => array( + array( + 'type' => 'button', + 'value' => 'submitGuestInfo', + 'class' => 'submitGuestInfoInfo btn-primary pull-right', + 'label' => ' '.$this->l('Save Guest'), + ), + ), + ); + + $this->context->smarty->assign($modal); + $response['hasError'] = 0; + $response['modalHtml'] = $this->context->smarty->fetch('modal.tpl'); + } + + $this->ajaxDie(json_encode($response)); + } + + + public function ajaxProcessUpdateGuestDetails() + { + $response = array('hasError' => 0, 'errors' => array()); + // Check tab access is allowed to edit + if ($this->tabAccess['edit'] == 1) { + if (Validate::isLoadedObject($objCustomerGuestDetail = new CustomerGuestDetail((int) Tools::getValue('id_customer_guest_detail')))) { + $response['errors'] = $objCustomerGuestDetail->validateController(); + if (!Tools::getValue('lastname')) { + $response['errors']['lastname'] = Tools::displayError('lastname is required'); + } + if (!Tools::getValue('firstname')) { + $response['errors']['firstname'] = Tools::displayError('firstname is required'); + } + if (!Tools::getValue('email')) { + $response['errors']['email'] = Tools::displayError('email is required'); + } + if (!Tools::getValue('phone')) { + $response['errors']['phone'] = Tools::displayError('phone is required'); + } + if (!$response['errors']) { + $objCustomerGuestDetail->id_gender = Tools::getValue('id_gender'); + $objCustomerGuestDetail->firstname = Tools::getValue('firstname'); + $objCustomerGuestDetail->lastname = Tools::getValue('lastname'); + $objCustomerGuestDetail->phone = Tools::getValue('phone'); + if ($objCustomerGuestDetail->save()) { + $gender = new Gender($objCustomerGuestDetail->id_gender, $this->context->language->id); + $response['data']['gender'] = $gender->name; + $response['data']['firstname'] = $objCustomerGuestDetail->firstname; + $response['data']['lastname'] = $objCustomerGuestDetail->lastname ; + $response['data']['email'] = $objCustomerGuestDetail->email; + $response['data']['phone'] = $objCustomerGuestDetail->phone; + $response['data']['id'] = $objCustomerGuestDetail->id; + $response['msg'] = $this->l('Guest details are updated.'); + } else { + $response['errors'][] = Tools::displayError('Unable to save guest details.'); + } + } + } else { + $response['errors'][] = Tools::displayError('Guest details not found.'); + } + } else { + $response['errors'][] = Tools::displayError('You do not have permission to edit this.'); + } + + if ($response['errors']) { + $response['hasError'] = 1; + $this->context->smarty->assign('errors', $response['errors']); + $response['errorsHtml'] = $this->context->smarty->fetch('alerts.tpl'); + } + + $this->ajaxDie(json_encode($response)); + } + + public function ajaxProcessDeleteGuest() + { + $response = array('hasError' => 1, 'errors' => array()); + // Check tab access is allowed to edit + if ($this->tabAccess['delete'] == 1) { + if (Validate::isLoadedObject($objCustomerGuestDetail = new CustomerGuestDetail((int) Tools::getValue('id_customer_guest_detail')))) { + if ($objCustomerGuestDetail->delete()) { + $response['hasError'] = false; + $response['msg'] = $this->l('Successful deletion.'); + } else { + $response['msg'] = $this->l('Unable to delete guest details.'); + } + } else { + $response['msg'] = $this->l('Guest details not found.'); + } + } else { + $response['msg'] = $this->l('You do not have permission to delete this.'); + } + + $this->ajaxDie(json_encode($response)); + } + public function setMedia() { parent::setMedia(); if ($this->loadObject(true) - && ($this->display == 'edit' || $this->display == 'add') + && ($this->display == 'edit' || $this->display == 'add' || $this->display == 'view') ) { $idCustomer = $this->object->id ? $this->object->id : 0; Media::addJSDef( array( 'customer_controller_url' => self::$currentIndex.'&token='.$this->token, - 'id_customer' => $idCustomer + 'id_customer' => $idCustomer, + 'txtSomeErr' => $this->l('Some error occurred. Please try again.', null, true), + 'confirmTxt' => $this->l('Are you sure you want to delete this guest details?', null, true) ) ); $this->addJS(_PS_JS_DIR_.'admin/customers.js'); diff --git a/controllers/front/AuthController.php b/controllers/front/AuthController.php index ff254b67a..7f2dd8e4e 100644 --- a/controllers/front/AuthController.php +++ b/controllers/front/AuthController.php @@ -422,16 +422,8 @@ class AuthControllerCore extends FrontController $addresses_types[] = 'address_invoice'; } - $className = 'CartCustomerGuestDetail'; - $rules = call_user_func(array($className, 'getValidationRules'), $className); if (Configuration::get('PS_ONE_PHONE_AT_LEAST') && !Tools::getValue('phone')) { $this->errors[] = Tools::displayError('Phone number is required.'); - } else { - if (Tools::getValue('phone') && !Validate::isPhoneNumber(Tools::getValue('phone'))) { - $this->errors[] = Tools::displayError('Invald phone number.'); - } elseif (Tools::getValue('phone') && Tools::strlen(Tools::getValue('phone')) > $rules['size']['phone']) { - $this->errors[] = sprintf(Tools::displayError('Phone number is too long. (%s chars max).'), $rules['size']['phone']); - } } if (!Tools::getValue('is_new_customer', 1)) { diff --git a/controllers/front/IdentityController.php b/controllers/front/IdentityController.php index 65ce13b27..917e301f4 100644 --- a/controllers/front/IdentityController.php +++ b/controllers/front/IdentityController.php @@ -88,17 +88,9 @@ class IdentityControllerCore extends FrontController $this->errors[] = Tools::displayError('Phone number is required.'); } } - $className = 'CartCustomerGuestDetail'; - $rules = call_user_func(array($className, 'getValidationRules'), $className); - if ($phone && !Validate::isPhoneNumber($phone)) { - $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)) { + $this->customer->phone = $phone; $this->customer->id_default_group = (int)$prev_id_default_group; $this->customer->firstname = Tools::ucwords($this->customer->firstname); diff --git a/controllers/front/OrderOpcController.php b/controllers/front/OrderOpcController.php index f551646e1..a162e96d8 100644 --- a/controllers/front/OrderOpcController.php +++ b/controllers/front/OrderOpcController.php @@ -119,16 +119,8 @@ class OrderOpcControllerCore extends ParentOrderController if (Configuration::get('PS_ONE_PHONE_AT_LEAST') && !$phone) { $this->errors[] = Tools::displayError('Phone number is a required field.', false); } - $className = 'CartCustomerGuestDetail'; - $rules = call_user_func(array($className, 'getValidationRules'), $className); - if (!Validate::isPhoneNumber($phone)) { - $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 = $phone; - } + $this->context->customer->phone = $phone; $_POST['lastname'] = $_POST['customer_lastname']; $_POST['firstname'] = $_POST['customer_firstname']; $this->errors = array_merge($this->errors, $this->context->customer->validateController()); @@ -387,8 +379,8 @@ class OrderOpcControllerCore extends ParentOrderController $this->ajaxDie($this->changeRoomDemands()); exit; break; - case 'submitCustomerGuestDetail': - $this->ajaxDie($this->submitCustomerGuestDetail()); + case 'getCustomerGuestDetail': + $this->ajaxDie($this->getCustomerGuestDetail()); exit; break; default: @@ -438,6 +430,10 @@ class OrderOpcControllerCore extends ParentOrderController parent::initContent(); + if (Tools::getValue('submitGuestDetails')) { + $this->submitCustomerGuestDetail(); + } + /* id_carrier is not defined in database before choosing a carrier, set it to a default one to match a potential cart _rule */ if (empty($this->context->cart->id_carrier)) { $checked = $this->context->cart->simulateCarrierSelectedOutput(); @@ -551,12 +547,12 @@ class OrderOpcControllerCore extends ParentOrderController $this->_assignPayment(); // GUEST BOOKING if ($this->isLogged) { - if ($id_customer_guest_detail = CartCustomerGuestDetail::getCartCustomerGuest($this->context->cart->id)) { + if ($idCustomerGuestDetail = CustomerGuestDetail::getCustomerGuestIdByIdCart($this->context->cart->id)) { $this->context->smarty->assign( - 'customer_guest_detail', CartCustomerGuestDetail::getCustomerGuestDetail($id_customer_guest_detail) + 'customer_guest_detail', CustomerGuestDetail::getCustomerGuestDetailById($idCustomerGuestDetail) ); } - $this->context->smarty->assign('id_customer_guest_detail', $id_customer_guest_detail); + $this->context->smarty->assign('id_customer_guest_detail', $idCustomerGuestDetail); } Tools::safePostVars(); @@ -1069,77 +1065,112 @@ class OrderOpcControllerCore extends ParentOrderController die('0'); } + public function getCustomerGuestDetail() + { + $response = array('status' => false); + $firstname = trim(Tools::getValue('firstname')); + $lastname = trim(Tools::getValue('lastname')); + $email = trim(Tools::getValue('email')); + $objCustomerGuestDetail = new CustomerGuestDetail(); + if ($guestDetails = $objCustomerGuestDetail->getCustomerGuestsByIdCustomer( + $this->context->cart->id_customer, + $firstname, + $lastname, + $email + )) { + $response['status'] = true; + $response['guest_details'] = $guestDetails; + } + + return json_encode($response); + } + + public function submitCustomerGuestDetail() { $customerGuestDetail = Tools::getValue('customer_guest_detail'); $this->context->cookie->__set('customer_details_proceeded', 0); $this->context->cookie->checkedTOS = false; if ($customerGuestDetail) { - if ($id_customer_guest_detail = CartCustomerGuestDetail::getCartCustomerGuest($this->context->cart->id)) { - $objCustomerGuestDetail = new CartCustomerGuestDetail($id_customer_guest_detail); - } else { - $objCustomerGuestDetail = new CartCustomerGuestDetail(); - } - + $customerGuestDetailErrors = array(); $customerGuestDetailGender = Tools::getValue('customer_guest_detail_gender'); $customerGuestDetailFirstname = Tools::getValue('customer_guest_detail_firstname'); $customerGuestDetailLastname = Tools::getValue('customer_guest_detail_lastname'); $customerGuestDetailEmail = Tools::getValue('customer_guest_detail_email'); $customerGuestDetailPhone = Tools::getValue('customer_guest_detail_phone'); - - $className = 'CartCustomerGuestDetail'; - $rules = call_user_func(array($className, 'getValidationRules'), $className); - - if (trim($customerGuestDetailGender) && Validate::isUnsignedInt($customerGuestDetailGender)) { - $objCustomerGuestDetail->id_gender = $customerGuestDetailGender; + if ($idCustomerGuestDetail = CustomerGuestDetail::getCustomerGuestByEmail($customerGuestDetailEmail, $this->context->cart->id)) { + $objCustomerGuestDetail = new CustomerGuestDetail($idCustomerGuestDetail); + } else if ($idCustomerGuestDetail = CustomerGuestDetail::getCustomerGuestByEmail($customerGuestDetailEmail, $this->context->customer->id, null)) { + $objCustomerGuestDetail = new CustomerGuestDetail($idCustomerGuestDetail); } else { - $result['errors']['customer_guest_detail_gender'] = Tools::displayError('Invalid gender'); + $objCustomerGuestDetail = new CustomerGuestDetail(); } - if (trim($customerGuestDetailFirstname) - && Validate::isName($customerGuestDetailFirstname) - && (!isset($rules['size']['firstname']) + $className = 'CustomerGuestDetail'; + $rules = call_user_func(array($className, 'getValidationRules'), $className); + + if (!(trim($customerGuestDetailGender) || !Validate::isUnsignedInt($customerGuestDetailGender))) { + $customerGuestDetailErrors[] = Tools::displayError('Invalid gender'); + } + + if (!trim($customerGuestDetailFirstname) + || !Validate::isName($customerGuestDetailFirstname) + || !(!isset($rules['size']['firstname']) || (isset($rules['size']['firstname']) && (Tools::strlen(trim($customerGuestDetailFirstname)) <= $rules['size']['firstname'])) ) ) { - $objCustomerGuestDetail->firstname = $customerGuestDetailFirstname; + $customerGuestDetailErrors[] = Tools::displayError('Invalid first name'); } - if (trim($customerGuestDetailLastname) - && Validate::isName($customerGuestDetailLastname) - && (!isset($rules['size']['lastname']) + if (!trim($customerGuestDetailLastname) + || !Validate::isName($customerGuestDetailLastname) + || !(!isset($rules['size']['lastname']) || (isset($rules['size']['lastname']) && (Tools::strlen(trim($customerGuestDetailLastname)) <= $rules['size']['lastname'])) ) ) { - $objCustomerGuestDetail->lastname = $customerGuestDetailLastname; + $customerGuestDetailErrors[] = Tools::displayError('Invalid last name'); } - if (trim($customerGuestDetailEmail) - && Validate::isEmail($customerGuestDetailEmail) - && (!isset($rules['size']['email']) + if (!trim($customerGuestDetailEmail) + || !Validate::isEmail($customerGuestDetailEmail) + || !(!isset($rules['size']['email']) || (isset($rules['size']['email']) && (Tools::strlen(trim($customerGuestDetailEmail)) <= $rules['size']['email'])) ) ) { - $objCustomerGuestDetail->email = $customerGuestDetailEmail; + $customerGuestDetailErrors[] = Tools::displayError('Invalid email'); } - if (trim($customerGuestDetailPhone) - && Validate::isPhoneNumber($customerGuestDetailPhone) - && (!isset($rules['size']['phone']) + if (!trim($customerGuestDetailPhone) + || !Validate::isPhoneNumber($customerGuestDetailPhone) + || !(!isset($rules['size']['phone']) || (isset($rules['size']['phone']) && (Tools::strlen(trim($customerGuestDetailPhone)) <= $rules['size']['phone'])) ) ) { - $objCustomerGuestDetail->phone = $customerGuestDetailPhone; + $customerGuestDetailErrors[] = Tools::displayError('Invalid phone'); } - $objCustomerGuestDetail->id_cart = $this->context->cart->id; - $objCustomerGuestDetail->save(); - } else { - if ($id_customer_guest_detail = CartCustomerGuestDetail::getCartCustomerGuest($this->context->cart->id)) { - if (Validate::isLoadedObject($objCustomerGuestDetail = new CartCustomerGuestDetail($id_customer_guest_detail))) { - $objCustomerGuestDetail->delete(); + if (empty($customerGuestDetailErrors)) { + $objCustomerGuestDetail->id_gender = $customerGuestDetailGender; + $objCustomerGuestDetail->firstname = $customerGuestDetailFirstname; + $objCustomerGuestDetail->lastname = $customerGuestDetailLastname; + $objCustomerGuestDetail->email = $customerGuestDetailEmail; + $objCustomerGuestDetail->phone = $customerGuestDetailPhone; + $objCustomerGuestDetail->id_customer = $this->context->customer->id; + if ($objCustomerGuestDetail->save()) { + if ($maxGuestAccountAllowed = Configuration::get('PS_CUSTOMER_GUEST_MAX_LIMIT')) { + $objCustomerGuestDetail->deleteCustomerGuestByIdCustomer($this->context->cart->id_customer, $maxGuestAccountAllowed); + } + // To prevent duplications for the same cart. + $objCustomerGuestDetail->deleteCustomerGuestInCart($this->context->cart->id); + $objCustomerGuestDetail->saveCustomerGuestInCart($this->context->cart->id, $objCustomerGuestDetail->id); + Tools::redirect($this->context->link->getPageLink('order-opc', null, $this->context->language->id, array('proceed_to_payment' => 1))); } } + + $this->context->smarty->assign('customerGuestDetailErrors', $customerGuestDetailErrors); + } else { + CustomerGuestDetail::deleteCustomerGuestInCart($this->context->cart->id); + Tools::redirect($this->context->link->getPageLink('order-opc', null, $this->context->language->id, array('proceed_to_payment' => 1))); } $this->context->cart->save(); diff --git a/install/data/db_structure.sql b/install/data/db_structure.sql index c4dc5ff7e..4e08a593e 100644 --- a/install/data/db_structure.sql +++ b/install/data/db_structure.sql @@ -687,9 +687,9 @@ CREATE TABLE `PREFIX_order_customer_guest_detail` ( PRIMARY KEY (`id_order_customer_guest_detail`) ) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8 COLLATION; -CREATE TABLE `PREFIX_cart_customer_guest_detail` ( +CREATE TABLE `PREFIX_customer_guest_detail` ( `id_customer_guest_detail` int(10) unsigned NOT NULL auto_increment, - `id_cart` int(10) unsigned NOT NULL, + `id_customer` int(10) unsigned NOT NULL, `id_gender` int(10) unsigned NOT NULL, `firstname` varchar(32) NOT NULL, `lastname` varchar(32) NOT NULL, @@ -700,6 +700,12 @@ CREATE TABLE `PREFIX_cart_customer_guest_detail` ( PRIMARY KEY (`id_customer_guest_detail`) ) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8 COLLATION; +CREATE TABLE `PREFIX_cart_customer_guest` ( + `id_customer_guest_detail` int(10) unsigned NOT NULL, + `id_cart` int(10) unsigned NOT NULL, + PRIMARY KEY (`id_customer_guest_detail`, `id_cart`) +) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8 COLLATION; + CREATE TABLE `PREFIX_customization` ( `id_customization` int(10) unsigned NOT NULL auto_increment, `id_product_attribute` int(10) unsigned NOT NULL DEFAULT '0', diff --git a/install/data/xml/configuration.xml b/install/data/xml/configuration.xml index 5b34881e3..844c20742 100644 --- a/install/data/xml/configuration.xml +++ b/install/data/xml/configuration.xml @@ -955,6 +955,9 @@ 0 + + + 5 diff --git a/js/admin/customers.js b/js/admin/customers.js index 5eaa94c7d..d29e97ed7 100644 --- a/js/admin/customers.js +++ b/js/admin/customers.js @@ -48,4 +48,129 @@ $(document).ready(function() { }); } }); + + $(document).on('click', '.edit-customer-guest-detail', function(e) { + e.preventDefault(); + GuestModal.show($(this).data('id_customer_guest_detail')); + }); + $(document).on('click', '.delete-customer-guest-detail', function(e) { + e.preventDefault(); + if (confirm(confirmTxt)) { + GuestModal.deleteGuest($(this).data('id_customer_guest_detail')); + } + }); + + const GuestModal = { + show: function(id_customer_guest_detail) { + $("#page-loader").show(); + $('#customer-guest-modal').remove(); + $.ajax({ + url: customer_controller_url, + method: 'POST', + dataType: 'json', + data: { + ajax : 1, + id_customer_guest_detail: id_customer_guest_detail, + action: 'InitGuestModal' + }, + beforeSend: function() { + $("#page-loader").show(); + }, + success: function(result) { + if (result.hasError == 0 && result.modalHtml) { + $('#footer').next('.bootstrap').append(result.modalHtml); + $('#customer-guest-modal').modal('show'); + } else { + showErrorMessage(txtSomeErr); + } + }, + complete: function() { + $("#page-loader").hide(); + } + }); + }, + close: function() { + $('#customer-guest-modal').modal('hide'); + }, + submit: function() { + $("#page-loader").show(); + GuestModal.hideErrors(); + $.ajax({ + headers: { + "cache-control": "no-cache" + }, + url: customer_controller_url, + method: 'POST', + dataType: 'json', + cache: false, + data: $('#customer-guest-details-form').serialize()+'&ajax=true&action=updateGuestDetails', + success: function(result) { + if (result.hasError == true) { + GuestModal.showErrors(result.errorsHtml); + } else { + if (result.msg) { + showSuccessMessage(result.msg); + } + let tr = $(''); + tr.append('' + result.data.email + '') + .append('' + result.data.firstname + '') + .append('' + result.data.lastname + '') + .append('' + result.data.phone + '') + .append('') + .append(''); + $('.customer_guest_detail_'+result.data.id).html($(tr).html()); + } + }, + complete: function() { + $("#page-loader").hide(); + } + }); + }, + deleteGuest: function(id_customer_guest_detail) { + $("#page-loader").show(); + GuestModal.hideErrors(); + $.ajax({ + headers: { + "cache-control": "no-cache" + }, + url: customer_controller_url, + method: 'POST', + dataType: 'json', + cache: false, + data: { + ajax : 1, + id_customer_guest_detail: id_customer_guest_detail, + action: 'DeleteGuest' + }, + success: function(result) { + if (result.hasError == true) { + showErrorMessage(result.msg); + } else if (result.msg) { + showSuccessMessage(result.msg); + $('.customer_guest_detail_'+id_customer_guest_detail).remove(); + if ($('.customer_guest_details').length == 0) { + $('.customer-guests').closest('.panel').hide(); + } else { + $('.customer-guests-count').text(parseInt($('.customer_guest_details').length)); + } + } + }, + complete: function() { + $("#page-loader").hide(); + } + }); + }, + showErrors: function(errorsHtml) { + $('#customer-guest-modal .errors-wrap').html(errorsHtml); + $('#customer-guest-modal .errors-wrap').show(200); + }, + hideErrors: function(cb) { + $('#customer-guest-modal .errors-wrap').hide(200); + $('#customer-guest-modal .errors-wrap').html(''); + } + }; + $(document).on('click', '.submitGuestInfoInfo', function(e) { + e.preventDefault(); + GuestModal.submit(); + }); }); diff --git a/modules/wkroomsearchblock/views/templates/hook/roomTypePageSearch.tpl b/modules/wkroomsearchblock/views/templates/hook/roomTypePageSearch.tpl index 993330afe..4ff2f46f8 100644 --- a/modules/wkroomsearchblock/views/templates/hook/roomTypePageSearch.tpl +++ b/modules/wkroomsearchblock/views/templates/hook/roomTypePageSearch.tpl @@ -35,7 +35,7 @@
- {$search_data['htl_dtl']['hotel_name']|escape:'htmlall':'UTF-8'}, {$search_data['htl_dtl']['city']|escape:'htmlall':'UTF-8'} {if !$search_data['order_date_restrict']} {$search_data['date_from']|escape:'htmlall':'UTF-8'|date_format:"%d %b %Y"} - {$search_data['date_to']|escape:'htmlall':'UTF-8'|date_format:"%d %b %Y"} ({1+$search_data['num_days']|escape:'htmlall':'UTF-8'} {l s='Days' mod='wkroomsearchblock'} {$search_data['num_days']|escape:'htmlall':'UTF-8'} {if $search_data['num_days'] > 1}{l s='Nights' mod='wkroomsearchblock'}{else}{l s='Night' mod='wkroomsearchblock'}{/if}) {/if} + {$search_data['htl_dtl']['hotel_name']|escape:'htmlall':'UTF-8'}, {$search_data['htl_dtl']['city']|escape:'htmlall':'UTF-8'} {if !$search_data['order_date_restrict']} {if (isset($search_data['date_from']))}{$search_data['date_from']|escape:'htmlall':'UTF-8'|date_format:"%d %b %Y"}{/if} - {if isset($search_data['date_to'])}{$search_data['date_to']|escape:'htmlall':'UTF-8'|date_format:"%d %b %Y"}{/if} ({1+$search_data['num_days']|escape:'htmlall':'UTF-8'} {l s='Days' mod='wkroomsearchblock'} {$search_data['num_days']|escape:'htmlall':'UTF-8'} {if $search_data['num_days'] > 1}{l s='Nights' mod='wkroomsearchblock'}{else}{l s='Night' mod='wkroomsearchblock'}{/if}) {/if}
diff --git a/themes/hotel-reservation-theme/css/order-opc.css b/themes/hotel-reservation-theme/css/order-opc.css index b3f1c7b6e..9baa5a9a4 100644 --- a/themes/hotel-reservation-theme/css/order-opc.css +++ b/themes/hotel-reservation-theme/css/order-opc.css @@ -682,3 +682,29 @@ line-height: 19px; color: #333; margin-bottom: 15px; } + +/* Customer guest suggetions Css */ +.customer_guest_detail_ul { + overflow-x: hidden; + overflow-y: auto; + max-height: 200px; + background: #fff; + z-index: 10; + box-shadow: 0 4px 5px rgba(0, 0, 0, 0.15); + position: absolute; + width: 90%;} +.customer_guest_detail_email_list{ + width: 92%;} +.customer_guest_detail_li { + display: block; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + padding: 10px;} +.customer_guest_detail_li.active { + color: #fff; + background-color: #379bf0;} +.customer_guest_detail_li:hover { + cursor: pointer; + background-color: #379bf0; + color: #fff;} diff --git a/themes/hotel-reservation-theme/js/order-opc.js b/themes/hotel-reservation-theme/js/order-opc.js index c828b6051..2db984950 100644 --- a/themes/hotel-reservation-theme/js/order-opc.js +++ b/themes/hotel-reservation-theme/js/order-opc.js @@ -94,9 +94,11 @@ $(document).ready(function() if ($("#customer_guest_detail:checked").val() == 1) { $('#checkout-guest-info-block').hide('slow'); $('#customer-guest-detail-container').show('slow'); + $('#customer_guest_detail_errors').show('slow'); } else { $('#customer-guest-detail-container').hide('slow'); $('#checkout-guest-info-block').show('slow'); + $('#customer_guest_detail_errors').hide('hide'); } } function validateCustomerGuestDetailForm() { @@ -115,16 +117,148 @@ $(document).ready(function() if ($("#customer_guest_detail:checked").val() == 1) { validateCustomerGuestDetailForm(); } + $(document).on('click', '.submit-guest-details', function(e) { + e.preventDefault(); + if ($('#customer_guest_detail').prop('checked')) { + validateCustomerGuestDetailForm(); + if ($('#customer_guest_detail_form').find('.form-error').length == 0) { + $('#customer_guest_detail_form').get(0).submit(); + } + } else { + $('#customer_guest_detail_form').get(0).submit(); + } + }); - $('#customer_guest_detail_form').on('change', function(e) { - $.ajax({ - type: 'POST', - url: orderOpcUrl, - async: false, - cache: false, - dataType : "json", - data: $(this).serialize()+'&method=submitCustomerGuestDetail&ajax=true&token=' + static_token - }); + function setCustomerGuestDetailForm(guestDetail) { + $('#customer_guest_detail_firstname').val(guestDetail.firstname); + $('#customer_guest_detail_lastname').val(guestDetail.lastname); + $('#customer_guest_detail_email').val(guestDetail.email); + $('#customer_guest_detail_phone').val(guestDetail.phone); + validateCustomerGuestDetailForm(); + $('.customer_guest_detail_ul').remove(); + } + + $(document).on('keyup', function(e) { + if (!$(e.target).attr('id') == 'customer_guest_detail_firstname' + || !$(e.target).attr('id') == 'customer_guest_detail_lastname' + || !$(e.target).attr('id') == 'customer_guest_detail_email' + ) { + $('.customer_guest_detail_ul').remove(); + } + }); + + $(document).on('click', function(e) { + if ($(e.target).hasClass('customer_guest_detail_li')) { + let guestDetail = $(e.target).data('guest_detail'); + setCustomerGuestDetailForm(guestDetail); + } + + $('.customer_guest_detail_ul').remove(); + }); + let debounceTimeout; + $(document).on('keyup', '#customer_guest_detail_firstname, #customer_guest_detail_lastname, #customer_guest_detail_email', function(e) { + var keyCode = e.keyCode || e.which; + if (keyCode == 40 || keyCode == 38) { + let activeElem = $(".customer_guest_detail_ul .active"); + let newActiveElem; + if (activeElem.length) { + if (keyCode == 40) { + newActiveElem = activeElem.next("li"); + if (!newActiveElem.length) { + newActiveElem = $(".customer_guest_detail_ul li:first"); // Loop back to first + } + } else if (keyCode == 38) { + newActiveElem = activeElem.prev("li"); + if (!newActiveElem.length) { + newActiveElem = $(".customer_guest_detail_ul li:last"); // Loop back to last + } + } + } else { + newActiveElem = keyCode == 40 ? $(".customer_guest_detail_ul li:first") : $(".customer_guest_detail_ul li:last"); + } + + activeElem.removeClass("active"); + newActiveElem.addClass("active"); + + return; + } else if (keyCode == 13) { + if ($('.customer_guest_detail_ul .active').length != 0) { + let guestDetail = $('.customer_guest_detail_ul .active').data('guest_detail'); + setCustomerGuestDetailForm(guestDetail); + } + } else if (!((keyCode < 65 || keyCode > 122) && (keyCode < 48 || keyCode > 57) && (keyCode != 8))) { + clearTimeout(debounceTimeout); // Clear the existing timeout + debounceTimeout = setTimeout(() => { + let firstName = ''; + let lastName = ''; + let email = ''; + if ($(e.target).prop('id') == 'customer_guest_detail_firstname') { + firstName = $('#customer_guest_detail_firstname').val(); + } else if ($(e.target).prop('id') == 'customer_guest_detail_lastname') { + lastName = $('#customer_guest_detail_lastname').val(); + } else if ($(e.target).prop('id') == 'customer_guest_detail_email') { + email = $('#customer_guest_detail_email').val(); + } + + let targetElem = $(this); + if ($.trim($(targetElem).val()) != '') { + customerGuestDetailAjax = $.ajax({ + type: 'POST', + url: orderOpcUrl, + async: false, + cache: false, + dataType : "json", + data: { + token : static_token, + ajax : true, + method : 'getCustomerGuestDetail', + firstname : firstName, + lastname : lastName, + email : email, + }, + success: function(data) { + $('.customer_guest_detail_ul').remove(); + if (data.status) { + let listElem = $('