From 117d98280c3799c04a7c1cf9accdf4ca8b8dc108 Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Sat, 26 Nov 2022 16:31:50 +0530 Subject: [PATCH 1/4] added booking for someone else feature --- .../controllers/orders/helpers/view/view.tpl | 27 +++++- classes/BookingStayingGuest.php | 71 +++++++++++++++ classes/Cart.php | 3 + classes/PaymentModule.php | 29 ++++++ .../CheckoutCustomerDetailsStep.php | 10 ++- classes/order/Order.php | 4 + controllers/admin/AdminOrdersController.php | 7 ++ controllers/front/OrderOpcController.php | 42 +++++++++ install/data/db_structure.sql | 15 ++++ js/validate.js | 10 ++- .../hotel-reservation-theme/js/order-opc.js | 38 ++++++++ themes/hotel-reservation-theme/order-opc.tpl | 89 ++++++++++++++----- 12 files changed, 316 insertions(+), 29 deletions(-) create mode 100644 classes/BookingStayingGuest.php diff --git a/admin/themes/default/template/controllers/orders/helpers/view/view.tpl b/admin/themes/default/template/controllers/orders/helpers/view/view.tpl index 15a2ef097..66dd53a9c 100644 --- a/admin/themes/default/template/controllers/orders/helpers/view/view.tpl +++ b/admin/themes/default/template/controllers/orders/helpers/view/view.tpl @@ -669,15 +669,27 @@

{l s='This feature will generate a random password and send an email to the customer.'}

+
+
{l s='Email'}
+
{$customer->email}
+ {if $addresses.invoice->phone_mobile || $addresses.invoice->phone} +
{l s='Phone'}
+
{if $addresses.invoice->phone_mobile}{$addresses.invoice->phone_mobile}{else}{$addresses.invoice->phone}{/if}

+ {/if} +
{else}
{l s='A registered customer account has already claimed this email address'}
{/if} {else} -
+
{l s='Email'}
{$customer->email}

+ {if $addresses.invoice->phone_mobile || $addresses.invoice->phone} +
{l s='Phone'}
+
{if $addresses.invoice->phone_mobile}{$addresses.invoice->phone_mobile}{else}{$addresses.invoice->phone}{/if}

+ {/if}
{l s='Account registered'}
{dateFormat date=$customer->date_add full=true}
+ {if $order->id_booking_staying_guest} +
+
+ {l s='Staying guest'} +
+
{l s='Name'}
+
{$bookingStayingGuest->firstname} {$bookingStayingGuest->lastname}

+
{l s='Email'}
+
{$bookingStayingGuest->email}

+
{l s='Phone'}
+
{$bookingStayingGuest->phone}
+
+ {/if} {/if} diff --git a/classes/BookingStayingGuest.php b/classes/BookingStayingGuest.php new file mode 100644 index 000000000..4d297b70e --- /dev/null +++ b/classes/BookingStayingGuest.php @@ -0,0 +1,71 @@ + +* @copyright 2010-2022 Webkul IN +* @license https://store.webkul.com/license.html +*/ + +class BookingStayingGuestCore extends ObjectModel +{ + public $id_booking_staying_guest; + public $id_gender; + public $firstname; + public $lastname; + public $email; + public $phone; + public $date_add; + public $date_upd; + + public static $definition = array( + 'table' => 'booking_staying_guest', + 'primary' => 'id_booking_staying_guest', + 'fields' => array( + '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 getBookingStayingGuestInfo($id_booking_staying_guest) + { + return Db::getInstance()->getRow(' + SELECT * FROM `'._DB_PREFIX_.'booking_staying_guest` + WHERE `id_booking_staying_guest` = '.(int)$id_booking_staying_guest + ); + } + + 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; + } + return $isValid; + } +} \ No newline at end of file diff --git a/classes/Cart.php b/classes/Cart.php index 18b2c15cf..9e5669df0 100644 --- a/classes/Cart.php +++ b/classes/Cart.php @@ -88,6 +88,8 @@ class CartCore extends ObjectModel */ public $is_advance_payment; + public $id_booking_staying_guest; + protected static $_nbProducts = array(); protected static $_isVirtualCart = array(); @@ -116,6 +118,7 @@ class CartCore extends ObjectModel 'id_currency' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true), 'id_customer' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), 'id_guest' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), + 'id_booking_staying_guest' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), 'id_lang' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true), 'recyclable' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), 'gift' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), diff --git a/classes/PaymentModule.php b/classes/PaymentModule.php index 39b850a28..07ae42212 100644 --- a/classes/PaymentModule.php +++ b/classes/PaymentModule.php @@ -362,6 +362,11 @@ abstract class PaymentModuleCore extends Module $order->advance_paid_amount = (float)Tools::ps_round((float)$this->context->cart->getOrderTotal(true, Cart::BOTH, $order->product_list, $id_carrier), _PS_PRICE_COMPUTE_PRECISION_); } + // save staying guest information + if ($this->context->cart->id_booking_staying_guest) { + $order->id_booking_staying_guest = (int)$this->context->cart->id_booking_staying_guest; + } + // Creating order $result = $order->add(); @@ -1017,6 +1022,30 @@ abstract class PaymentModuleCore extends Module null, _PS_MAIL_DIR_, false, (int)$order->id_shop ); } + // send mail to staying guest if customer booked for someone other. + if ($order->id_booking_staying_guest) { + if ($stayingGuestInfo = BookingStayingGuest::getBookingStayingGuestInfo( + $order->id_booking_staying_guest + )) { + if (Validate::isEmail($stayingGuestInfo['email'])) { + $data['{firstname}'] = $stayingGuestInfo['firstname']; + $data['{lastname}'] = $stayingGuestInfo['lastname']; + $data['{email}'] = $stayingGuestInfo['email']; + Mail::Send( + (int)$order->id_lang, + 'order_conf', + Mail::l('Order confirmation', (int)$order->id_lang), + $data, + $stayingGuestInfo['email'], + $stayingGuestInfo['firstname'].' '.$stayingGuestInfo['lastname'], + null, + null, + $file_attachement, + null, _PS_MAIL_DIR_, false, (int)$order->id_shop + ); + } + } + } } if (Configuration::get('PS_ORDER_CONF_MAIL_TO_SUPERADMIN')){ // send superadmin information diff --git a/classes/checkoutProcess/CheckoutCustomerDetailsStep.php b/classes/checkoutProcess/CheckoutCustomerDetailsStep.php index 6b6263651..543f2e286 100644 --- a/classes/checkoutProcess/CheckoutCustomerDetailsStep.php +++ b/classes/checkoutProcess/CheckoutCustomerDetailsStep.php @@ -42,9 +42,17 @@ class CheckoutCustomerDetailsStep extends AbstractCheckoutStep } } } elseif (Tools::getValue('proceed_to_payment')) { + $guestInfoComplete = true; + if ($this->context->cart->id_booking_staying_guest) { + $guestInfoComplete = false; + $objBookingStayingGuest = new BookingStayingGuest($this->context->cart->id_booking_staying_guest); + if ($objBookingStayingGuest->validateGuestInfo()) { + $guestInfoComplete = true; + } + } $this->step_is_reachable = 1; $this->step_is_current = 1; - if ($idAddressDelivery) { + if ($idAddressDelivery && $guestInfoComplete) { if (Validate::isLoadedObject($objAddress)) { $this->step_is_current = 0; $this->step_is_complete = 1; diff --git a/classes/order/Order.php b/classes/order/Order.php index 548e58610..5f108da9e 100644 --- a/classes/order/Order.php +++ b/classes/order/Order.php @@ -59,6 +59,9 @@ class OrderCore extends ObjectModel /** @var int Customer id */ public $id_customer; + /** @var int Staying guest id */ + public $id_booking_staying_guest; + /** @var int Carrier id */ public $id_carrier; @@ -206,6 +209,7 @@ class OrderCore extends ObjectModel 'id_shop' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), 'id_lang' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true), 'id_customer' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true), + 'id_booking_staying_guest' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), 'id_carrier' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), 'current_state' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), 'secure_key' => array('type' => self::TYPE_STRING, 'validate' => 'isMd5'), diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index a7e150ecc..3b43d4eb9 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -1334,6 +1334,12 @@ class AdminOrdersControllerCore extends AdminController $this->toolbar_title .= ' - '.sprintf($this->l('Shop: %s'), $shop->name); } + // get details if booking is done for some other guest + $bookingStayingGuest = false; + if ($order->id_booking_staying_guest) { + $bookingStayingGuest = new BookingStayingGuest($order->id_booking_staying_guest); + } + // gets warehouses to ship products, if and only if advanced stock management is activated $warehouse_list = null; @@ -1516,6 +1522,7 @@ class AdminOrdersControllerCore extends AdminController 'cart' => new Cart($order->id_cart), 'customer' => $customer, 'gender' => $gender, + 'bookingStayingGuest' => $bookingStayingGuest, 'customer_addresses' => $customer->getAddresses($this->context->language->id), 'addresses' => array( 'delivery' => $addressDelivery, diff --git a/controllers/front/OrderOpcController.php b/controllers/front/OrderOpcController.php index a4660529c..5cac05ba3 100644 --- a/controllers/front/OrderOpcController.php +++ b/controllers/front/OrderOpcController.php @@ -317,6 +317,10 @@ class OrderOpcControllerCore extends ParentOrderController $this->ajaxDie($this->changeRoomDemands()); exit; break; + case 'submitBookingStayingGuest': + $this->ajaxDie($this->submitBookingStayingGuest()); + exit; + break; default: throw new PrestaShopException('Unknown method "'.Tools::getValue('method').'"'); } @@ -477,6 +481,13 @@ class OrderOpcControllerCore extends ParentOrderController $this->_assignCarrier(); // PAYMENT $this->_assignPayment(); + // GUEST BOOKING + if ($this->isLogged) { + if ($this->context->cart->id_booking_staying_guest) { + $this->context->smarty->assign('booking_staying_guest', BookingStayingGuest::getBookingStayingGuestInfo($this->context->cart->id_booking_staying_guest)); + } + $this->context->smarty->assign('id_booking_staying_guest', $this->context->cart->id_booking_staying_guest); + } Tools::safePostVars(); $newsletter = Configuration::get('PS_CUSTOMER_NWSL') || (Module::isInstalled('blocknewsletter') && Module::getInstanceByName('blocknewsletter')->active); @@ -964,4 +975,35 @@ class OrderOpcControllerCore extends ParentOrderController } die('0'); } + + public function submitBookingStayingGuest() + { + $booking_staying_guest = Tools::getValue('booking_staying_guest'); + $this->context->cookie->__set('customer_details_proceeded', 0); + $this->context->cookie->checkedTOS = false; + if ($booking_staying_guest) { + if ($this->context->cart->id_booking_staying_guest) { + $objBookingStayingGuest = new BookingStayingGuest($this->context->cart->id_booking_staying_guest); + } else { + $objBookingStayingGuest = new BookingStayingGuest(); + } + $booking_staying_guest_gender = Tools::getValue('booking_staying_guest_gender'); + $booking_staying_guest_firstname = Tools::getValue('booking_staying_guest_firstname'); + $booking_staying_guest_lastname = Tools::getValue('booking_staying_guest_lastname'); + $booking_staying_guest_email = Tools::getValue('booking_staying_guest_email'); + $booking_staying_guest_phone = Tools::getValue('booking_staying_guest_phone'); + $objBookingStayingGuest->id_gender = $booking_staying_guest_gender; + $objBookingStayingGuest->firstname = $booking_staying_guest_firstname; + $objBookingStayingGuest->lastname = $booking_staying_guest_lastname; + $objBookingStayingGuest->email = $booking_staying_guest_email; + $objBookingStayingGuest->phone = $booking_staying_guest_phone; + $objBookingStayingGuest->save(); + $this->context->cart->id_booking_staying_guest = $objBookingStayingGuest->id; + } else { + $objBookingStayingGuest = new BookingStayingGuest($this->context->cart->id_booking_staying_guest); + $objBookingStayingGuest->delete(); + $this->context->cart->id_booking_staying_guest = false; + } + $this->context->cart->save(); + } } diff --git a/install/data/db_structure.sql b/install/data/db_structure.sql index a3aa8160d..b32447bdb 100644 --- a/install/data/db_structure.sql +++ b/install/data/db_structure.sql @@ -182,6 +182,7 @@ CREATE TABLE `PREFIX_cart` ( `id_currency` int(10) unsigned NOT NULL, `id_customer` int(10) unsigned NOT NULL, `id_guest` int(10) unsigned NOT NULL, + `id_booking_staying_guest` int(10) unsigned NOT NULL, `secure_key` varchar(32) NOT NULL DEFAULT '-1', `recyclable` tinyint(1) unsigned NOT NULL DEFAULT '1', `gift` tinyint(1) unsigned NOT NULL DEFAULT '0', @@ -673,6 +674,19 @@ CREATE TABLE `PREFIX_customer_thread` ( KEY `id_product` (`id_product`) ) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8 COLLATION; +CREATE TABLE `PREFIX_booking_staying_guest` ( + `id_booking_staying_guest` int(10) unsigned NOT NULL auto_increment, + `id_cart` int(10) unsigned NOT NULL, + `id_order` int(10) unsigned NOT NULL, + `id_gender` int(10) unsigned NOT NULL, + `firstname` varchar(32) NOT NULL, + `lastname` varchar(32) NOT NULL, + `email` varchar(128) NOT NULL, + `phone` varchar(32) DEFAULT NULL, + `date_add` datetime NOT NULL, + `date_upd` datetime NOT NULL, + PRIMARY KEY (`id_booking_staying_guest`) +) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8 COLLATION; CREATE TABLE `PREFIX_customization` ( `id_customization` int(10) unsigned NOT NULL auto_increment, @@ -1098,6 +1112,7 @@ CREATE TABLE `PREFIX_orders` ( `id_carrier` int(10) unsigned NOT NULL, `id_lang` int(10) unsigned NOT NULL, `id_customer` int(10) unsigned NOT NULL, + `id_booking_staying_guest` int(10) unsigned NOT NULL, `id_cart` int(10) unsigned NOT NULL, `id_currency` int(10) unsigned NOT NULL, `id_address_delivery` int(10) unsigned NOT NULL, diff --git a/js/validate.js b/js/validate.js index 85b041fbb..a724f516b 100644 --- a/js/validate.js +++ b/js/validate.js @@ -192,12 +192,16 @@ function validate_field(that) } else if($(that).attr('data-validate')) var result = window['validate_' + $(that).attr('data-validate')]($(that).val()); - - if (result) + if (result) { $(that).parent().removeClass('form-error').addClass('form-ok'); - else + return true; + } else { $(that).parent().addClass('form-error').removeClass('form-ok'); + return false; + } + } + return true; } $(document).on('focusout', 'input.validate, textarea.validate', function() { diff --git a/themes/hotel-reservation-theme/js/order-opc.js b/themes/hotel-reservation-theme/js/order-opc.js index 728a14494..2c11ef492 100644 --- a/themes/hotel-reservation-theme/js/order-opc.js +++ b/themes/hotel-reservation-theme/js/order-opc.js @@ -50,6 +50,44 @@ $(document).ready(function() $("#partial_data").slideDown(); }); + // staying guest booking + function initGuestbookingcontainer() { + if ($("#booking_staying_guest:checked").val() == 1) { + $('#customer_info_container').hide('slow'); + $('#booking_staying_guest_container').show('slow'); + } else { + $('#booking_staying_guest_container').hide('slow'); + $('#customer_info_container').show('slow'); + } + } + function validateBookingStayingGuestForm() { + $('#booking_staying_guest_form input.validate').each(function (index, element) { + if (!validate_field(element)) { + if ($('#cgv').prop('checked') == 1) { + $('#cgv').trigger('click'); + } + } + }); + } + initGuestbookingcontainer(); + $("#booking_staying_guest").on('change',function() { + initGuestbookingcontainer(); + }); + if ($("#booking_staying_guest:checked").val() == 1) { + validateBookingStayingGuestForm(); + } + + $('#booking_staying_guest_form').on('change', function(e) { + $.ajax({ + type: 'POST', + url: orderOpcUrl, + async: false, + cache: false, + dataType : "json", + data: $(this).serialize()+'&method=submitBookingStayingGuest&ajax=true&token=' + static_token + }); + }); + // GUEST CHECKOUT / NEW ACCOUNT MANAGEMENT if ((typeof isLogged == 'undefined' || !isLogged) || (typeof isGuest !== 'undefined' && isGuest)) { diff --git a/themes/hotel-reservation-theme/order-opc.tpl b/themes/hotel-reservation-theme/order-opc.tpl index 76312fcaa..2e0696581 100644 --- a/themes/hotel-reservation-theme/order-opc.tpl +++ b/themes/hotel-reservation-theme/order-opc.tpl @@ -78,33 +78,74 @@
{if $is_logged || $isGuest} -
-
{l s='Name'}
-
{$guestInformations['firstname']} {$guestInformations['lastname']}
-
-
-
{l s='Email'}
-
{$guestInformations['email']}
-
- {if (isset($delivery->phone_mobile) && $delivery->phone_mobile) || (isset($delivery->phone) && $delivery->phone)} -
-
- {if isset($delivery->phone_mobile) && $delivery->phone_mobile} - {l s='Mobile Number'} - {else} - {l s='Phone Number'} - {/if} +
+ {if $is_logged} +

+ + +

+ {/if} +
+
+
+ + +
+
+ + +
+
+ + +
-
- {if isset($delivery->phone_mobile) && $delivery->phone_mobile} - {$delivery->phone_mobile|escape:'html':'UTF-8'} - {else} - {$delivery->phone|escape:'html':'UTF-8'} - {/if} +
+
+ + +
+
+
+
+ + +
- {/if} - +
+
+
{l s='Name'}
+
{$guestInformations['firstname']} {$guestInformations['lastname']}
+
+
+
{l s='Email'}
+
{$guestInformations['email']}
+
+ {if (isset($delivery->phone_mobile) && $delivery->phone_mobile) || (isset($delivery->phone) && $delivery->phone)} +
+
+ {if isset($delivery->phone_mobile) && $delivery->phone_mobile} + {l s='Mobile Number'} + {else} + {l s='Phone Number'} + {/if} +
+
+ {if isset($delivery->phone_mobile) && $delivery->phone_mobile} + {$delivery->phone_mobile|escape:'html':'UTF-8'} + {else} + {$delivery->phone|escape:'html':'UTF-8'} + {/if} +
+
+ {/if} +
+ {* proceed only if no order restrict errors are there *} {if !$orderRestrictErr}
From 9bf2cdf42f332c8d4886a2cb74b0fd5e17ac7ce7 Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Sun, 25 Dec 2022 11:55:59 +0530 Subject: [PATCH 2/4] udpated changes --- .../controllers/orders/helpers/view/view.tpl | 10 ++-- classes/Cart.php | 4 +- ...ayingGuest.php => CustomerGuestDetail.php} | 25 ++++++--- classes/PaymentModule.php | 26 +++++----- .../CheckoutCustomerDetailsStep.php | 6 +-- classes/order/Order.php | 6 +-- controllers/admin/AdminOrdersController.php | 8 +-- controllers/front/OrderOpcController.php | 52 +++++++++---------- install/data/db_structure.sql | 20 +++++-- .../hotel-reservation-theme/js/order-opc.js | 22 ++++---- themes/hotel-reservation-theme/order-opc.tpl | 22 ++++---- 11 files changed, 111 insertions(+), 90 deletions(-) rename classes/{BookingStayingGuest.php => CustomerGuestDetail.php} (70%) diff --git a/admin/themes/default/template/controllers/orders/helpers/view/view.tpl b/admin/themes/default/template/controllers/orders/helpers/view/view.tpl index 66dd53a9c..3d9c89ec6 100644 --- a/admin/themes/default/template/controllers/orders/helpers/view/view.tpl +++ b/admin/themes/default/template/controllers/orders/helpers/view/view.tpl @@ -703,17 +703,17 @@
{$customer->ape}
{/if} -->
- {if $order->id_booking_staying_guest} + {if $order->id_customer_guest_detail}
- {l s='Staying guest'} + {l s='Guest'}
{l s='Name'}
-
{$bookingStayingGuest->firstname} {$bookingStayingGuest->lastname}

+
{$customerGuestDetail->firstname} {$customerGuestDetail->lastname}

{l s='Email'}
-
{$bookingStayingGuest->email}

+
{$customerGuestDetail->email}

{l s='Phone'}
-
{$bookingStayingGuest->phone}
+
{$customerGuestDetail->phone}
{/if} {/if} diff --git a/classes/Cart.php b/classes/Cart.php index 9e5669df0..361942ff4 100644 --- a/classes/Cart.php +++ b/classes/Cart.php @@ -88,7 +88,7 @@ class CartCore extends ObjectModel */ public $is_advance_payment; - public $id_booking_staying_guest; + public $id_customer_guest_detail; protected static $_nbProducts = array(); protected static $_isVirtualCart = array(); @@ -118,7 +118,7 @@ class CartCore extends ObjectModel 'id_currency' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true), 'id_customer' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), 'id_guest' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), - 'id_booking_staying_guest' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), + 'id_customer_guest_detail' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), 'id_lang' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true), 'recyclable' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), 'gift' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), diff --git a/classes/BookingStayingGuest.php b/classes/CustomerGuestDetail.php similarity index 70% rename from classes/BookingStayingGuest.php rename to classes/CustomerGuestDetail.php index 4d297b70e..f78f8b231 100644 --- a/classes/BookingStayingGuest.php +++ b/classes/CustomerGuestDetail.php @@ -18,9 +18,9 @@ * @license https://store.webkul.com/license.html */ -class BookingStayingGuestCore extends ObjectModel +class CustomerGuestDetailCore extends ObjectModel { - public $id_booking_staying_guest; + public $id_customer_guest_detail; public $id_gender; public $firstname; public $lastname; @@ -30,9 +30,10 @@ class BookingStayingGuestCore extends ObjectModel public $date_upd; public static $definition = array( - 'table' => 'booking_staying_guest', - 'primary' => 'id_booking_staying_guest', + '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), @@ -43,11 +44,21 @@ class BookingStayingGuestCore extends ObjectModel ), ); - public static function getBookingStayingGuestInfo($id_booking_staying_guest) + public static function getCustomerGuests($id_customer) { return Db::getInstance()->getRow(' - SELECT * FROM `'._DB_PREFIX_.'booking_staying_guest` - WHERE `id_booking_staying_guest` = '.(int)$id_booking_staying_guest + SELECT `id_customer_guest_detail`, `id_gender`, `firstname`, `lastname`, `email`, `phone` + FROM `'._DB_PREFIX_.'customer_guest_detail` + WHERE `id_customer` = '.(int)$id_customer + ); + } + + public static function getCustomerGuestDetail($id_customer_guest_detail) + { + return Db::getInstance()->getRow(' + SELECT `id_gender`, `firstname`, `lastname`, `email`, `phone` + FROM `'._DB_PREFIX_.'customer_guest_detail` + WHERE `id_customer_guest_detail` = '.(int)$id_customer_guest_detail ); } diff --git a/classes/PaymentModule.php b/classes/PaymentModule.php index 07ae42212..df6969c94 100644 --- a/classes/PaymentModule.php +++ b/classes/PaymentModule.php @@ -362,9 +362,9 @@ abstract class PaymentModuleCore extends Module $order->advance_paid_amount = (float)Tools::ps_round((float)$this->context->cart->getOrderTotal(true, Cart::BOTH, $order->product_list, $id_carrier), _PS_PRICE_COMPUTE_PRECISION_); } - // save staying guest information - if ($this->context->cart->id_booking_staying_guest) { - $order->id_booking_staying_guest = (int)$this->context->cart->id_booking_staying_guest; + // save customer guest information + if ($this->context->cart->id_customer_guest_detail) { + $order->id_customer_guest_detail = (int)$this->context->cart->id_customer_guest_detail; } // Creating order @@ -1022,22 +1022,22 @@ abstract class PaymentModuleCore extends Module null, _PS_MAIL_DIR_, false, (int)$order->id_shop ); } - // send mail to staying guest if customer booked for someone other. - if ($order->id_booking_staying_guest) { - if ($stayingGuestInfo = BookingStayingGuest::getBookingStayingGuestInfo( - $order->id_booking_staying_guest + // send mail to customer guest if customer booked for someone other. + if ($order->id_customer_guest_detail) { + if ($customerGuestDetail = CustomerGuestDetail::getCustomerGuestDetail( + $order->id_customer_guest_detail )) { - if (Validate::isEmail($stayingGuestInfo['email'])) { - $data['{firstname}'] = $stayingGuestInfo['firstname']; - $data['{lastname}'] = $stayingGuestInfo['lastname']; - $data['{email}'] = $stayingGuestInfo['email']; + if (Validate::isEmail($customerGuestDetail['email'])) { + $data['{firstname}'] = $customerGuestDetail['firstname']; + $data['{lastname}'] = $customerGuestDetail['lastname']; + $data['{email}'] = $customerGuestDetail['email']; Mail::Send( (int)$order->id_lang, 'order_conf', Mail::l('Order confirmation', (int)$order->id_lang), $data, - $stayingGuestInfo['email'], - $stayingGuestInfo['firstname'].' '.$stayingGuestInfo['lastname'], + $customerGuestDetail['email'], + $customerGuestDetail['firstname'].' '.$customerGuestDetail['lastname'], null, null, $file_attachement, diff --git a/classes/checkoutProcess/CheckoutCustomerDetailsStep.php b/classes/checkoutProcess/CheckoutCustomerDetailsStep.php index 543f2e286..00d908283 100644 --- a/classes/checkoutProcess/CheckoutCustomerDetailsStep.php +++ b/classes/checkoutProcess/CheckoutCustomerDetailsStep.php @@ -43,10 +43,10 @@ class CheckoutCustomerDetailsStep extends AbstractCheckoutStep } } elseif (Tools::getValue('proceed_to_payment')) { $guestInfoComplete = true; - if ($this->context->cart->id_booking_staying_guest) { + if ($this->context->cart->id_customer_guest_detail) { $guestInfoComplete = false; - $objBookingStayingGuest = new BookingStayingGuest($this->context->cart->id_booking_staying_guest); - if ($objBookingStayingGuest->validateGuestInfo()) { + $objCustomerGuestDetail = new CustomerGuestDetail($this->context->cart->id_customer_guest_detail); + if ($objCustomerGuestDetail->validateGuestInfo()) { $guestInfoComplete = true; } } diff --git a/classes/order/Order.php b/classes/order/Order.php index 5f108da9e..7bbbe06f2 100644 --- a/classes/order/Order.php +++ b/classes/order/Order.php @@ -59,8 +59,8 @@ class OrderCore extends ObjectModel /** @var int Customer id */ public $id_customer; - /** @var int Staying guest id */ - public $id_booking_staying_guest; + /** @var int Customer guest id */ + public $id_customer_guest_detail; /** @var int Carrier id */ public $id_carrier; @@ -209,7 +209,7 @@ class OrderCore extends ObjectModel 'id_shop' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), 'id_lang' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true), 'id_customer' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true), - 'id_booking_staying_guest' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), + 'id_customer_guest_detail' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), 'id_carrier' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), 'current_state' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), 'secure_key' => array('type' => self::TYPE_STRING, 'validate' => 'isMd5'), diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index 3b43d4eb9..d500a73ee 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -1335,9 +1335,9 @@ class AdminOrdersControllerCore extends AdminController } // get details if booking is done for some other guest - $bookingStayingGuest = false; - if ($order->id_booking_staying_guest) { - $bookingStayingGuest = new BookingStayingGuest($order->id_booking_staying_guest); + $customerGuestDetail = false; + if ($order->id_customer_guest_detail) { + $customerGuestDetail = new CustomerGuestDetail($order->id_customer_guest_detail); } // gets warehouses to ship products, if and only if advanced stock management is activated @@ -1522,7 +1522,7 @@ class AdminOrdersControllerCore extends AdminController 'cart' => new Cart($order->id_cart), 'customer' => $customer, 'gender' => $gender, - 'bookingStayingGuest' => $bookingStayingGuest, + 'customerGuestDetail' => $customerGuestDetail, 'customer_addresses' => $customer->getAddresses($this->context->language->id), 'addresses' => array( 'delivery' => $addressDelivery, diff --git a/controllers/front/OrderOpcController.php b/controllers/front/OrderOpcController.php index 5cac05ba3..03d94e09d 100644 --- a/controllers/front/OrderOpcController.php +++ b/controllers/front/OrderOpcController.php @@ -317,8 +317,8 @@ class OrderOpcControllerCore extends ParentOrderController $this->ajaxDie($this->changeRoomDemands()); exit; break; - case 'submitBookingStayingGuest': - $this->ajaxDie($this->submitBookingStayingGuest()); + case 'submitCustomerGuestDetail': + $this->ajaxDie($this->submitCustomerGuestDetail()); exit; break; default: @@ -483,10 +483,10 @@ class OrderOpcControllerCore extends ParentOrderController $this->_assignPayment(); // GUEST BOOKING if ($this->isLogged) { - if ($this->context->cart->id_booking_staying_guest) { - $this->context->smarty->assign('booking_staying_guest', BookingStayingGuest::getBookingStayingGuestInfo($this->context->cart->id_booking_staying_guest)); + if ($this->context->cart->id_customer_guest_detail) { + $this->context->smarty->assign('customer_guest_detail', CustomerGuestDetail::getCustomerGuestDetail($this->context->cart->id_customer_guest_detail)); } - $this->context->smarty->assign('id_booking_staying_guest', $this->context->cart->id_booking_staying_guest); + $this->context->smarty->assign('id_customer_guest_detail', $this->context->cart->id_customer_guest_detail); } Tools::safePostVars(); @@ -976,33 +976,33 @@ class OrderOpcControllerCore extends ParentOrderController die('0'); } - public function submitBookingStayingGuest() + public function submitCustomerGuestDetail() { - $booking_staying_guest = Tools::getValue('booking_staying_guest'); + $customer_guest_detail = Tools::getValue('customer_guest_detail'); $this->context->cookie->__set('customer_details_proceeded', 0); $this->context->cookie->checkedTOS = false; - if ($booking_staying_guest) { - if ($this->context->cart->id_booking_staying_guest) { - $objBookingStayingGuest = new BookingStayingGuest($this->context->cart->id_booking_staying_guest); + if ($customer_guest_detail) { + if ($this->context->cart->id_customer_guest_detail) { + $objCustomerGuestDetail = new CustomerGuestDetail($this->context->cart->id_customer_guest_detail); } else { - $objBookingStayingGuest = new BookingStayingGuest(); + $objCustomerGuestDetail = new CustomerGuestDetail(); } - $booking_staying_guest_gender = Tools::getValue('booking_staying_guest_gender'); - $booking_staying_guest_firstname = Tools::getValue('booking_staying_guest_firstname'); - $booking_staying_guest_lastname = Tools::getValue('booking_staying_guest_lastname'); - $booking_staying_guest_email = Tools::getValue('booking_staying_guest_email'); - $booking_staying_guest_phone = Tools::getValue('booking_staying_guest_phone'); - $objBookingStayingGuest->id_gender = $booking_staying_guest_gender; - $objBookingStayingGuest->firstname = $booking_staying_guest_firstname; - $objBookingStayingGuest->lastname = $booking_staying_guest_lastname; - $objBookingStayingGuest->email = $booking_staying_guest_email; - $objBookingStayingGuest->phone = $booking_staying_guest_phone; - $objBookingStayingGuest->save(); - $this->context->cart->id_booking_staying_guest = $objBookingStayingGuest->id; + $customer_guest_detail_gender = Tools::getValue('customer_guest_detail_gender'); + $customer_guest_detail_firstname = Tools::getValue('customer_guest_detail_firstname'); + $customer_guest_detail_lastname = Tools::getValue('customer_guest_detail_lastname'); + $customer_guest_detail_email = Tools::getValue('customer_guest_detail_email'); + $customer_guest_detail_phone = Tools::getValue('customer_guest_detail_phone'); + $objCustomerGuestDetail->id_gender = $customer_guest_detail_gender; + $objCustomerGuestDetail->firstname = $customer_guest_detail_firstname; + $objCustomerGuestDetail->lastname = $customer_guest_detail_lastname; + $objCustomerGuestDetail->email = $customer_guest_detail_email; + $objCustomerGuestDetail->phone = $customer_guest_detail_phone; + $objCustomerGuestDetail->save(); + $this->context->cart->id_customer_guest_detail = $objCustomerGuestDetail->id; } else { - $objBookingStayingGuest = new BookingStayingGuest($this->context->cart->id_booking_staying_guest); - $objBookingStayingGuest->delete(); - $this->context->cart->id_booking_staying_guest = false; + $objCustomerGuestDetail = new CustomerGuestDetail($this->context->cart->id_customer_guest_detail); + $objCustomerGuestDetail->delete(); + $this->context->cart->id_customer_guest_detail = false; } $this->context->cart->save(); } diff --git a/install/data/db_structure.sql b/install/data/db_structure.sql index b32447bdb..331237fe1 100644 --- a/install/data/db_structure.sql +++ b/install/data/db_structure.sql @@ -182,7 +182,6 @@ CREATE TABLE `PREFIX_cart` ( `id_currency` int(10) unsigned NOT NULL, `id_customer` int(10) unsigned NOT NULL, `id_guest` int(10) unsigned NOT NULL, - `id_booking_staying_guest` int(10) unsigned NOT NULL, `secure_key` varchar(32) NOT NULL DEFAULT '-1', `recyclable` tinyint(1) unsigned NOT NULL DEFAULT '1', `gift` tinyint(1) unsigned NOT NULL DEFAULT '0', @@ -674,9 +673,21 @@ CREATE TABLE `PREFIX_customer_thread` ( KEY `id_product` (`id_product`) ) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8 COLLATION; -CREATE TABLE `PREFIX_booking_staying_guest` ( - `id_booking_staying_guest` int(10) unsigned NOT NULL auto_increment, +CREATE TABLE `PREFIX_order_customer_guest_detail` ( + `id_customer_guest_detail` int(10) unsigned NOT NULL auto_increment, `id_cart` int(10) unsigned NOT NULL, + `id_gender` int(10) unsigned NOT NULL, + `firstname` varchar(32) NOT NULL, + `lastname` varchar(32) NOT NULL, + `email` varchar(128) NOT NULL, + `phone` varchar(32) DEFAULT NULL, + `date_add` datetime NOT NULL, + `date_upd` datetime NOT NULL, + PRIMARY KEY (`id_customer_guest_detail`) +) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8 COLLATION; + +CREATE TABLE `PREFIX_cart_customer_guest_detail` ( + `id_customer_guest_detail` int(10) unsigned NOT NULL auto_increment, `id_order` int(10) unsigned NOT NULL, `id_gender` int(10) unsigned NOT NULL, `firstname` varchar(32) NOT NULL, @@ -685,7 +696,7 @@ CREATE TABLE `PREFIX_booking_staying_guest` ( `phone` varchar(32) DEFAULT NULL, `date_add` datetime NOT NULL, `date_upd` datetime NOT NULL, - PRIMARY KEY (`id_booking_staying_guest`) + PRIMARY KEY (`id_customer_guest_detail`) ) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8 COLLATION; CREATE TABLE `PREFIX_customization` ( @@ -1112,7 +1123,6 @@ CREATE TABLE `PREFIX_orders` ( `id_carrier` int(10) unsigned NOT NULL, `id_lang` int(10) unsigned NOT NULL, `id_customer` int(10) unsigned NOT NULL, - `id_booking_staying_guest` int(10) unsigned NOT NULL, `id_cart` int(10) unsigned NOT NULL, `id_currency` int(10) unsigned NOT NULL, `id_address_delivery` int(10) unsigned NOT NULL, diff --git a/themes/hotel-reservation-theme/js/order-opc.js b/themes/hotel-reservation-theme/js/order-opc.js index 2c11ef492..0bf99bd8f 100644 --- a/themes/hotel-reservation-theme/js/order-opc.js +++ b/themes/hotel-reservation-theme/js/order-opc.js @@ -50,18 +50,18 @@ $(document).ready(function() $("#partial_data").slideDown(); }); - // staying guest booking + // customer guest booking function initGuestbookingcontainer() { - if ($("#booking_staying_guest:checked").val() == 1) { + if ($("#customer_guest_detail:checked").val() == 1) { $('#customer_info_container').hide('slow'); - $('#booking_staying_guest_container').show('slow'); + $('#customer_guest_detail_container').show('slow'); } else { - $('#booking_staying_guest_container').hide('slow'); + $('#customer_guest_detail_container').hide('slow'); $('#customer_info_container').show('slow'); } } - function validateBookingStayingGuestForm() { - $('#booking_staying_guest_form input.validate').each(function (index, element) { + function validateCustomerGuestDetailForm() { + $('#customer_guest_detail_form input.validate').each(function (index, element) { if (!validate_field(element)) { if ($('#cgv').prop('checked') == 1) { $('#cgv').trigger('click'); @@ -70,21 +70,21 @@ $(document).ready(function() }); } initGuestbookingcontainer(); - $("#booking_staying_guest").on('change',function() { + $("#customer_guest_detail").on('change',function() { initGuestbookingcontainer(); }); - if ($("#booking_staying_guest:checked").val() == 1) { - validateBookingStayingGuestForm(); + if ($("#customer_guest_detail:checked").val() == 1) { + validateCustomerGuestDetailForm(); } - $('#booking_staying_guest_form').on('change', function(e) { + $('#customer_guest_detail_form').on('change', function(e) { $.ajax({ type: 'POST', url: orderOpcUrl, async: false, cache: false, dataType : "json", - data: $(this).serialize()+'&method=submitBookingStayingGuest&ajax=true&token=' + static_token + data: $(this).serialize()+'&method=submitCustomerGuestDetail&ajax=true&token=' + static_token }); }); diff --git a/themes/hotel-reservation-theme/order-opc.tpl b/themes/hotel-reservation-theme/order-opc.tpl index 2e0696581..eb1959b54 100644 --- a/themes/hotel-reservation-theme/order-opc.tpl +++ b/themes/hotel-reservation-theme/order-opc.tpl @@ -78,46 +78,46 @@
{if $is_logged || $isGuest} -
+ {if $is_logged}

- - + +

{/if} -
+
- {foreach from=$genders key=k item=gender} - + {/foreach}
- +
- +
- +
- +
-
+
{l s='Name'}
{$guestInformations['firstname']} {$guestInformations['lastname']}
From 8935b0a6703ab8b171e1ccaa911e03910a6fae8e Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Mon, 26 Dec 2022 14:41:07 +0530 Subject: [PATCH 3/4] created indivisual table of guest detail for cart and order --- .../controllers/orders/helpers/view/view.tpl | 113 ++++++++++++++++-- classes/Cart.php | 3 - ...Detail.php => CartCustomerGuestDetail.php} | 19 +-- classes/PaymentModule.php | 39 +++--- .../CheckoutCustomerDetailsStep.php | 4 +- classes/order/Order.php | 4 - classes/order/OrderCustomerGuestDetail.php | 74 ++++++++++++ controllers/admin/AdminOrdersController.php | 49 +++++++- controllers/front/OrderDetailController.php | 7 ++ controllers/front/OrderOpcController.php | 59 +++++---- install/data/db_structure.sql | 8 +- .../hotel-reservation-theme/order-detail.tpl | 37 ++++-- 12 files changed, 335 insertions(+), 81 deletions(-) rename classes/{CustomerGuestDetail.php => CartCustomerGuestDetail.php} (81%) create mode 100644 classes/order/OrderCustomerGuestDetail.php diff --git a/admin/themes/default/template/controllers/orders/helpers/view/view.tpl b/admin/themes/default/template/controllers/orders/helpers/view/view.tpl index 3d9c89ec6..80fcb197a 100644 --- a/admin/themes/default/template/controllers/orders/helpers/view/view.tpl +++ b/admin/themes/default/template/controllers/orders/helpers/view/view.tpl @@ -703,18 +703,66 @@
{$customer->ape}
{/if} --> - {if $order->id_customer_guest_detail} -
+ {if $customerGuestDetail} +
{l s='Guest'}
-
{l s='Name'}
-
{$customerGuestDetail->firstname} {$customerGuestDetail->lastname}

-
{l s='Email'}
-
{$customerGuestDetail->email}

-
{l s='Phone'}
-
{$customerGuestDetail->phone}
-
+
+
{l s='Name'}
+
{$customerGuestDetail->gender->name} {$customerGuestDetail->firstname} {$customerGuestDetail->lastname}
+
+
{l s='Email'}
+
{$customerGuestDetail->email}

+
{l s='Phone'}
+
{$customerGuestDetail->phone}
+
+ +
+
+ +
+
{l s='Social title'}
+
+ +

+
{l s='First name'}
+
+ +

+
{l s='Last name'}
+
+ +

+
{l s='Email'}
+
+ +

+
{l s='Phone'}
+
+ +
+
+
+ + + +
+ +
{/if} {/if}
@@ -1695,6 +1743,53 @@ /*END*/ + // for updating customer guest details + $('#edit_guest_details').on('click', function(e) { + e.preventDefault(); + $('#customer-guest-details-form').show(); + $('#customer-guest-details').hide(); + }); + + $('#cancle_edit_guest_details').on('click', function(e) { + e.preventDefault(); + $('#customer-guest-details-form').hide(); + $('#customer-guest-details').show(); + }); + + $('#submit_guest_details').on('click', function(e) { + e.preventDefault(); + $.ajax({ + type: 'POST', + headers: { + "cache-control": "no-cache" + }, + url: "{$link->getAdminLink('AdminOrders')|addslashes}", + dataType: 'JSON', + cache: false, + data: $('#customer-guest-details-form').serialize()+'&ajax=true&id_order='+id_order+'&action=updateGuestDetails', + success: function(result) { + if (result.success) { + if (result.msg) { + showSuccessMessage(result.msg); + } + if (result.data.guest_name) { + $('#customer-guest-details .guest_name').text(result.data.guest_name); + } + if (result.data.guest_email) { + $('#customer-guest-details .guest_email a').attr('href', 'mailto:'+result.data.guest_email).text(result.data.guest_email); + } + if (result.data.guest_phone) { + $('#customer-guest-details .guest_phone a').attr('href', 'tel'+result.data.guest_phone).text(result.data.guest_phone); + } + $('#customer-guest-details-form').hide(); + $('#customer-guest-details').show(); + } else if (result.errors) { + showErrorMessage(result.errors); + } + } + }); + }); + $(".textarea-autosize").autosize(); var date = new Date(); diff --git a/classes/Cart.php b/classes/Cart.php index 361942ff4..18b2c15cf 100644 --- a/classes/Cart.php +++ b/classes/Cart.php @@ -88,8 +88,6 @@ class CartCore extends ObjectModel */ public $is_advance_payment; - public $id_customer_guest_detail; - protected static $_nbProducts = array(); protected static $_isVirtualCart = array(); @@ -118,7 +116,6 @@ class CartCore extends ObjectModel 'id_currency' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true), 'id_customer' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), 'id_guest' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), - 'id_customer_guest_detail' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), 'id_lang' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true), 'recyclable' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), 'gift' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), diff --git a/classes/CustomerGuestDetail.php b/classes/CartCustomerGuestDetail.php similarity index 81% rename from classes/CustomerGuestDetail.php rename to classes/CartCustomerGuestDetail.php index f78f8b231..d21c56c68 100644 --- a/classes/CustomerGuestDetail.php +++ b/classes/CartCustomerGuestDetail.php @@ -18,9 +18,10 @@ * @license https://store.webkul.com/license.html */ -class CustomerGuestDetailCore extends ObjectModel +class CartCustomerGuestDetailCore extends ObjectModel { public $id_customer_guest_detail; + public $id_cart; public $id_gender; public $firstname; public $lastname; @@ -30,10 +31,10 @@ class CustomerGuestDetailCore extends ObjectModel public $date_upd; public static $definition = array( - 'table' => 'customer_guest_detail', + 'table' => 'cart_customer_guest_detail', 'primary' => 'id_customer_guest_detail', 'fields' => array( - 'id_customer' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), + '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), @@ -44,12 +45,12 @@ class CustomerGuestDetailCore extends ObjectModel ), ); - public static function getCustomerGuests($id_customer) + public static function getCartCustomerGuest($id_cart) { - return Db::getInstance()->getRow(' - SELECT `id_customer_guest_detail`, `id_gender`, `firstname`, `lastname`, `email`, `phone` - FROM `'._DB_PREFIX_.'customer_guest_detail` - WHERE `id_customer` = '.(int)$id_customer + return Db::getInstance()->getValue(' + SELECT `id_customer_guest_detail` + FROM `'._DB_PREFIX_.'cart_customer_guest_detail` + WHERE `id_cart` = '.(int)$id_cart ); } @@ -57,7 +58,7 @@ class CustomerGuestDetailCore extends ObjectModel { return Db::getInstance()->getRow(' SELECT `id_gender`, `firstname`, `lastname`, `email`, `phone` - FROM `'._DB_PREFIX_.'customer_guest_detail` + FROM `'._DB_PREFIX_.'cart_customer_guest_detail` WHERE `id_customer_guest_detail` = '.(int)$id_customer_guest_detail ); } diff --git a/classes/PaymentModule.php b/classes/PaymentModule.php index df6969c94..2a696c1ee 100644 --- a/classes/PaymentModule.php +++ b/classes/PaymentModule.php @@ -362,11 +362,6 @@ abstract class PaymentModuleCore extends Module $order->advance_paid_amount = (float)Tools::ps_round((float)$this->context->cart->getOrderTotal(true, Cart::BOTH, $order->product_list, $id_carrier), _PS_PRICE_COMPUTE_PRECISION_); } - // save customer guest information - if ($this->context->cart->id_customer_guest_detail) { - $order->id_customer_guest_detail = (int)$this->context->cart->id_customer_guest_detail; - } - // Creating order $result = $order->add(); @@ -375,6 +370,22 @@ abstract class PaymentModuleCore extends Module throw new PrestaShopException('Can\'t save Order'); } + // 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 + ))) { + $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_order = (int)$order->id; + $objOrderCustomerGuestDetail->save(); + } + } + // Amount paid by customer is not the right one -> Status = payment error // We don't use the following condition to avoid the float precision issues : http://www.php.net/manual/en/language.types.float.php // if ($order->total_paid != $order->total_paid_real) @@ -1023,21 +1034,21 @@ abstract class PaymentModuleCore extends Module ); } // send mail to customer guest if customer booked for someone other. - if ($order->id_customer_guest_detail) { - if ($customerGuestDetail = CustomerGuestDetail::getCustomerGuestDetail( - $order->id_customer_guest_detail + if ($id_customer_guest_detail = OrderCustomerGuestDetail::isCustomerGuestBooking($order->id)) { + if ($objOrderCustomerGuestDetail = new OrderCustomerGuestDetail( + $id_customer_guest_detail )) { - if (Validate::isEmail($customerGuestDetail['email'])) { - $data['{firstname}'] = $customerGuestDetail['firstname']; - $data['{lastname}'] = $customerGuestDetail['lastname']; - $data['{email}'] = $customerGuestDetail['email']; + if (Validate::isEmail($objOrderCustomerGuestDetail->email)) { + $data['{firstname}'] = $objOrderCustomerGuestDetail->firstname; + $data['{lastname}'] = $objOrderCustomerGuestDetail->lastname; + $data['{email}'] = $objOrderCustomerGuestDetail->email; Mail::Send( (int)$order->id_lang, 'order_conf', Mail::l('Order confirmation', (int)$order->id_lang), $data, - $customerGuestDetail['email'], - $customerGuestDetail['firstname'].' '.$customerGuestDetail['lastname'], + $objOrderCustomerGuestDetail->email, + $objOrderCustomerGuestDetail->firstname.' '.$objOrderCustomerGuestDetail->lastname, null, null, $file_attachement, diff --git a/classes/checkoutProcess/CheckoutCustomerDetailsStep.php b/classes/checkoutProcess/CheckoutCustomerDetailsStep.php index 00d908283..7ec1fef59 100644 --- a/classes/checkoutProcess/CheckoutCustomerDetailsStep.php +++ b/classes/checkoutProcess/CheckoutCustomerDetailsStep.php @@ -43,9 +43,9 @@ class CheckoutCustomerDetailsStep extends AbstractCheckoutStep } } elseif (Tools::getValue('proceed_to_payment')) { $guestInfoComplete = true; - if ($this->context->cart->id_customer_guest_detail) { + if ($id_customer_guest_detail = CartCustomerGuestDetail::getCartCustomerGuest($this->context->cart->id)) { $guestInfoComplete = false; - $objCustomerGuestDetail = new CustomerGuestDetail($this->context->cart->id_customer_guest_detail); + $objCustomerGuestDetail = new CartCustomerGuestDetail($id_customer_guest_detail); if ($objCustomerGuestDetail->validateGuestInfo()) { $guestInfoComplete = true; } diff --git a/classes/order/Order.php b/classes/order/Order.php index 7bbbe06f2..548e58610 100644 --- a/classes/order/Order.php +++ b/classes/order/Order.php @@ -59,9 +59,6 @@ class OrderCore extends ObjectModel /** @var int Customer id */ public $id_customer; - /** @var int Customer guest id */ - public $id_customer_guest_detail; - /** @var int Carrier id */ public $id_carrier; @@ -209,7 +206,6 @@ class OrderCore extends ObjectModel 'id_shop' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), 'id_lang' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true), 'id_customer' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true), - 'id_customer_guest_detail' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), 'id_carrier' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), 'current_state' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), 'secure_key' => array('type' => self::TYPE_STRING, 'validate' => 'isMd5'), diff --git a/classes/order/OrderCustomerGuestDetail.php b/classes/order/OrderCustomerGuestDetail.php new file mode 100644 index 000000000..9f7013bdd --- /dev/null +++ b/classes/order/OrderCustomerGuestDetail.php @@ -0,0 +1,74 @@ + +* @copyright 2010-2022 Webkul IN +* @license https://store.webkul.com/license.html +*/ + +class OrderCustomerGuestDetailCore extends ObjectModel +{ + public $id_order_customer_guest_detail; + public $id_order; + public $id_gender; + public $firstname; + public $lastname; + public $email; + public $phone; + public $date_add; + public $date_upd; + + public static $definition = array( + 'table' => 'order_customer_guest_detail', + 'primary' => 'id_order_customer_guest_detail', + 'fields' => array( + 'id_order' => 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 isCustomerGuestBooking($id_order) + { + return Db::getInstance()->getValue(' + SELECT `id_order_customer_guest_detail` + FROM `'._DB_PREFIX_.'order_customer_guest_detail` + WHERE `id_order` = '.(int)$id_order + ); + } + + 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; + } + return $isValid; + } +} \ No newline at end of file diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index d500a73ee..08be801d0 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -1336,8 +1336,9 @@ class AdminOrdersControllerCore extends AdminController // get details if booking is done for some other guest $customerGuestDetail = false; - if ($order->id_customer_guest_detail) { - $customerGuestDetail = new CustomerGuestDetail($order->id_customer_guest_detail); + if ($id_customer_guest_detail = OrderCustomerGuestDetail::isCustomerGuestBooking($order->id)) { + $customerGuestDetail = new OrderCustomerGuestDetail($id_customer_guest_detail); + $customerGuestDetail->gender = new Gender($customerGuestDetail->id_gender, $this->context->language->id); } // gets warehouses to ship products, if and only if advanced stock management is activated @@ -1523,6 +1524,7 @@ class AdminOrdersControllerCore extends AdminController 'customer' => $customer, 'gender' => $gender, 'customerGuestDetail' => $customerGuestDetail, + 'genders' => Gender::getGenders(), 'customer_addresses' => $customer->getAddresses($this->context->language->id), 'addresses' => array( 'delivery' => $addressDelivery, @@ -1592,6 +1594,49 @@ class AdminOrdersControllerCore extends AdminController return parent::renderView(); } + public function ajaxProcessUpdateGuestDetails() + { + $response = array( + 'success' => false + ); + if (Validate::isLoadedObject($order = new Order(Tools::getValue('id_order')))) { + if ($id_customer_guest_detail = OrderCustomerGuestDetail::isCustomerGuestBooking($order->id)) { + if (Validate::isLoadedObject($objCustomerGuestDetail = new OrderCustomerGuestDetail($id_customer_guest_detail))) { + $id_gender = Tools::getValue('id_gender'); + $firstname = Tools::getValue('firstname'); + $lastname = Tools::getValue('lastname'); + $email = Tools::getValue('email'); + $phone = Tools::getValue('phone'); + $objCustomerGuestDetail->id_gender = $id_gender; + $objCustomerGuestDetail->firstname = $firstname; + $objCustomerGuestDetail->lastname = $lastname; + $objCustomerGuestDetail->email = $email; + $objCustomerGuestDetail->phone = $phone; + if ($objCustomerGuestDetail->validateGuestInfo()) { + if ($objCustomerGuestDetail->save()) { + $response['success'] = true; + $gender = new Gender($objCustomerGuestDetail->id_gender, $this->context->language->id); + $response['data']['guest_name'] = $gender->name.' '.$objCustomerGuestDetail->firstname.' '.$objCustomerGuestDetail->lastname ; + $response['data']['guest_email'] = $objCustomerGuestDetail->email; + $response['data']['guest_phone'] = $objCustomerGuestDetail->phone; + $response['msg'] = $this->l('Guest details are updated.'); + } else { + $response['errors'][] = $this->l('Unable to save guest details.'); + } + } else { + $response['errors'][] = $this->l('Invalid guest details, please check and try again.'); + } + } else { + $response['errors'][] = $this->l('Guest details not found.'); + } + } else { + $response['errors'][] = $this->l('Guest details not found.'); + } + } + + $this->ajaxDie(json_encode($response)); + } + public function ajaxProcessSearchProducts() { Context::getContext()->customer = new Customer((int)Tools::getValue('id_customer')); diff --git a/controllers/front/OrderDetailController.php b/controllers/front/OrderDetailController.php index 120a32022..07d84ff97 100644 --- a/controllers/front/OrderDetailController.php +++ b/controllers/front/OrderDetailController.php @@ -275,6 +275,12 @@ class OrderDetailControllerCore extends FrontController $customer = new Customer($order->id_customer); + $customerGuestDetail = false; + if ($id_customer_guest_detail = OrderCustomerGuestDetail::isCustomerGuestBooking($order->id)) { + $customerGuestDetail = new OrderCustomerGuestDetail($id_customer_guest_detail); + } + + //by webkul to show order details properly on order history page if (Module::isInstalled('hotelreservationsystem')) { @@ -457,6 +463,7 @@ class OrderDetailControllerCore extends FrontController 'shop_name' => strval(Configuration::get('PS_SHOP_NAME')), 'order' => $order, 'guestInformations' => (array)new Customer($order->id_customer), + 'customerGuestDetail' => $customerGuestDetail, 'currency' => new Currency($order->id_currency), 'order_state' => (int) $id_order_state, 'invoiceAllowed' => (int) Configuration::get('PS_INVOICE'), diff --git a/controllers/front/OrderOpcController.php b/controllers/front/OrderOpcController.php index 03d94e09d..2112ae0ba 100644 --- a/controllers/front/OrderOpcController.php +++ b/controllers/front/OrderOpcController.php @@ -483,10 +483,12 @@ class OrderOpcControllerCore extends ParentOrderController $this->_assignPayment(); // GUEST BOOKING if ($this->isLogged) { - if ($this->context->cart->id_customer_guest_detail) { - $this->context->smarty->assign('customer_guest_detail', CustomerGuestDetail::getCustomerGuestDetail($this->context->cart->id_customer_guest_detail)); + if ($id_customer_guest_detail = CartCustomerGuestDetail::getCartCustomerGuest($this->context->cart->id)) { + $this->context->smarty->assign( + 'customer_guest_detail', CartCustomerGuestDetail::getCustomerGuestDetail($id_customer_guest_detail) + ); } - $this->context->smarty->assign('id_customer_guest_detail', $this->context->cart->id_customer_guest_detail); + $this->context->smarty->assign('id_customer_guest_detail', $id_customer_guest_detail); } Tools::safePostVars(); @@ -978,31 +980,44 @@ class OrderOpcControllerCore extends ParentOrderController public function submitCustomerGuestDetail() { - $customer_guest_detail = Tools::getValue('customer_guest_detail'); + $customerGuestDetail = Tools::getValue('customer_guest_detail'); $this->context->cookie->__set('customer_details_proceeded', 0); $this->context->cookie->checkedTOS = false; - if ($customer_guest_detail) { - if ($this->context->cart->id_customer_guest_detail) { - $objCustomerGuestDetail = new CustomerGuestDetail($this->context->cart->id_customer_guest_detail); + if ($customerGuestDetail) { + if ($id_customer_guest_detail = CartCustomerGuestDetail::getCartCustomerGuest($this->context->cart->id)) { + $objCustomerGuestDetail = new CartCustomerGuestDetail($id_customer_guest_detail); } else { - $objCustomerGuestDetail = new CustomerGuestDetail(); + $objCustomerGuestDetail = new CartCustomerGuestDetail(); } - $customer_guest_detail_gender = Tools::getValue('customer_guest_detail_gender'); - $customer_guest_detail_firstname = Tools::getValue('customer_guest_detail_firstname'); - $customer_guest_detail_lastname = Tools::getValue('customer_guest_detail_lastname'); - $customer_guest_detail_email = Tools::getValue('customer_guest_detail_email'); - $customer_guest_detail_phone = Tools::getValue('customer_guest_detail_phone'); - $objCustomerGuestDetail->id_gender = $customer_guest_detail_gender; - $objCustomerGuestDetail->firstname = $customer_guest_detail_firstname; - $objCustomerGuestDetail->lastname = $customer_guest_detail_lastname; - $objCustomerGuestDetail->email = $customer_guest_detail_email; - $objCustomerGuestDetail->phone = $customer_guest_detail_phone; + + $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'); + if (trim($customerGuestDetailGender) && Validate::isUnsignedInt($customerGuestDetailGender)) { + $objCustomerGuestDetail->id_gender = $customerGuestDetailGender; + } + if (trim($customerGuestDetailFirstname) && Validate::isName($customerGuestDetailFirstname)) { + $objCustomerGuestDetail->firstname = $customerGuestDetailFirstname; + } + if (trim($customerGuestDetailLastname) && Validate::isName($customerGuestDetailLastname)) { + $objCustomerGuestDetail->lastname = $customerGuestDetailLastname; + } + if (trim($customerGuestDetailEmail) && Validate::isEmail($customerGuestDetailEmail)) { + $objCustomerGuestDetail->email = $customerGuestDetailEmail; + } + if (trim($customerGuestDetailPhone) && Validate::isPhoneNumber($customerGuestDetailPhone)) { + $objCustomerGuestDetail->phone = $customerGuestDetailPhone; + } + $objCustomerGuestDetail->id_cart = $this->context->cart->id; $objCustomerGuestDetail->save(); - $this->context->cart->id_customer_guest_detail = $objCustomerGuestDetail->id; } else { - $objCustomerGuestDetail = new CustomerGuestDetail($this->context->cart->id_customer_guest_detail); - $objCustomerGuestDetail->delete(); - $this->context->cart->id_customer_guest_detail = false; + if ($id_customer_guest_detail = CartCustomerGuestDetail::getCartCustomerGuest($this->context->cart->id)) { + if (Validate::isLoadedObject($objCustomerGuestDetail = new CartCustomerGuestDetail($id_customer_guest_detail))) { + $objCustomerGuestDetail->delete(); + } + } } $this->context->cart->save(); } diff --git a/install/data/db_structure.sql b/install/data/db_structure.sql index 331237fe1..e6942a0bd 100644 --- a/install/data/db_structure.sql +++ b/install/data/db_structure.sql @@ -674,8 +674,8 @@ CREATE TABLE `PREFIX_customer_thread` ( ) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8 COLLATION; CREATE TABLE `PREFIX_order_customer_guest_detail` ( - `id_customer_guest_detail` int(10) unsigned NOT NULL auto_increment, - `id_cart` int(10) unsigned NOT NULL, + `id_order_customer_guest_detail` int(10) unsigned NOT NULL auto_increment, + `id_order` int(10) unsigned NOT NULL, `id_gender` int(10) unsigned NOT NULL, `firstname` varchar(32) NOT NULL, `lastname` varchar(32) NOT NULL, @@ -683,12 +683,12 @@ CREATE TABLE `PREFIX_order_customer_guest_detail` ( `phone` varchar(32) DEFAULT NULL, `date_add` datetime NOT NULL, `date_upd` datetime NOT NULL, - PRIMARY KEY (`id_customer_guest_detail`) + PRIMARY KEY (`id_order_customer_guest_detail`) ) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8 COLLATION; CREATE TABLE `PREFIX_cart_customer_guest_detail` ( `id_customer_guest_detail` int(10) unsigned NOT NULL auto_increment, - `id_order` int(10) unsigned NOT NULL, + `id_cart` int(10) unsigned NOT NULL, `id_gender` int(10) unsigned NOT NULL, `firstname` varchar(32) NOT NULL, `lastname` varchar(32) NOT NULL, diff --git a/themes/hotel-reservation-theme/order-detail.tpl b/themes/hotel-reservation-theme/order-detail.tpl index bcfc6d8cd..3571a1205 100644 --- a/themes/hotel-reservation-theme/order-detail.tpl +++ b/themes/hotel-reservation-theme/order-detail.tpl @@ -93,23 +93,36 @@
    -
  • {l s='Customer Details'}

  • - {if isset($address_invoice->firstname) && $address_invoice->firstname} -
  • {l s='Name'}
    {$address_invoice->firstname|escape:'html':'UTF-8'} {$address_invoice->lastname|escape:'html':'UTF-8'}
  • - {/if} - {if isset($guestInformations['email']) && $guestInformations['email']} -
  • {l s='Email'}
    {$guestInformations['email']|escape:'html':'UTF-8'}
  • - {/if} - {if isset($address_invoice->phone_mobile) && $address_invoice->phone_mobile} -
  • {l s='Mobile Number'}
    {$address_invoice->phone_mobile|escape:'html':'UTF-8'}
  • - {/if} - {if isset($address_invoice->phone) && $address_invoice->phone} -
  • {l s='Phone Number'}
    {$address_invoice->phone|escape:'html':'UTF-8'}
  • +
  • {l s='Guest Details'}

  • + {if $customerGuestDetail} + {if isset($customerGuestDetail->firstname) && $customerGuestDetail->firstname} +
  • {l s='Name'}
    {$customerGuestDetail->firstname|escape:'html':'UTF-8'} {$customerGuestDetail->lastname|escape:'html':'UTF-8'}
  • + {/if} + {if isset($customerGuestDetail->email) && $customerGuestDetail->email} +
  • {l s='Email'}
    {$customerGuestDetail->email|escape:'html':'UTF-8'}
  • + {/if} + {if isset($customerGuestDetail->phone) && $customerGuestDetail->phone} +
  • {l s='Mobile Number'}
    {$customerGuestDetail->phone|escape:'html':'UTF-8'}
  • + {/if} + {else} + {if isset($address_invoice->firstname) && $address_invoice->firstname} +
  • {l s='Name'}
    {$address_invoice->firstname|escape:'html':'UTF-8'} {$address_invoice->lastname|escape:'html':'UTF-8'}
  • + {/if} + {if isset($guestInformations['email']) && $guestInformations['email']} +
  • {l s='Email'}
    {$guestInformations['email']|escape:'html':'UTF-8'}
  • + {/if} + {if isset($address_invoice->phone_mobile) && $address_invoice->phone_mobile} +
  • {l s='Mobile Number'}
    {$address_invoice->phone_mobile|escape:'html':'UTF-8'}
  • + {/if} + {if isset($address_invoice->phone) && $address_invoice->phone} +
  • {l s='Phone Number'}
    {$address_invoice->phone|escape:'html':'UTF-8'}
  • + {/if} {/if}
+ {$HOOK_ORDERDETAILDISPLAYED} {if !$is_guest}
{/if} From db67ea8b740684c8ec1bda0c85019c03a5b53506 Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Wed, 28 Dec 2022 16:53:41 +0530 Subject: [PATCH 4/4] updated traveller details block --- .../default/template/controllers/orders/helpers/view/view.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin/themes/default/template/controllers/orders/helpers/view/view.tpl b/admin/themes/default/template/controllers/orders/helpers/view/view.tpl index 3291b4477..c51a0fea6 100644 --- a/admin/themes/default/template/controllers/orders/helpers/view/view.tpl +++ b/admin/themes/default/template/controllers/orders/helpers/view/view.tpl @@ -710,7 +710,7 @@ {if $customerGuestDetail}
- {l s='Guest'} + {l s='Traveller detail'}
{l s='Name'}