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}