Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added feature Customer can now create booking with different name. #454

Merged
merged 5 commits into from
Dec 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -673,15 +673,27 @@
<input class="btn btn-default" type="submit" name="submitGuestToCustomer" value="{l s='Transform this guest into a customer'}" />
<p class="help-block">{l s='This feature will generate a random password and send an email to the customer.'}</p>
</form>
<dl class="panel list-detail">
<dt>{l s='Email'}</dt>
<dd><a href="mailto:{$customer->email}"><i class="icon-envelope-o"></i> {$customer->email}</a></dd>
{if $addresses.invoice->phone_mobile || $addresses.invoice->phone}
<dt>{l s='Phone'}</dt>
<dd><a href="tel:{if $addresses.invoice->phone_mobile}{$addresses.invoice->phone_mobile}{else}{$addresses.invoice->phone}{/if}"><i class="icon-envelope-o"></i> {if $addresses.invoice->phone_mobile}{$addresses.invoice->phone_mobile}{else}{$addresses.invoice->phone}{/if}</a></dd><br>
{/if}
</dl>
{else}
<div class="alert alert-warning">
{l s='A registered customer account has already claimed this email address'}
</div>
{/if}
{else}
<dl class="well list-detail">
<dl class="panel list-detail">
<dt>{l s='Email'}</dt>
<dd><a href="mailto:{$customer->email}"><i class="icon-envelope-o"></i> {$customer->email}</a></dd><br>
{if $addresses.invoice->phone_mobile || $addresses.invoice->phone}
<dt>{l s='Phone'}</dt>
<dd><a href="tel:{if $addresses.invoice->phone_mobile}{$addresses.invoice->phone_mobile}{else}{$addresses.invoice->phone}{/if}"><i class="icon-envelope-o"></i> {if $addresses.invoice->phone_mobile}{$addresses.invoice->phone_mobile}{else}{$addresses.invoice->phone}{/if}</a></dd><br>
{/if}
<dt>{l s='Account registered'}</dt>
<dd class="text-muted"><i class="icon-calendar-o"></i> {dateFormat date=$customer->date_add full=true}</dd>
<!-- <dt>{l s='Valid orders placed'}</dt>
Expand All @@ -695,6 +707,67 @@
<dd>{$customer->ape}</dd>
{/if} -->
</dl>
{if $customerGuestDetail}
<div class="panel">
<div class="panel-heading">
{l s='Traveller detail'}
</div>
<dl id="customer-guest-details">
<dt>{l s='Name'}</dt>
<dd class="guest_name">{$customerGuestDetail->gender->name} {$customerGuestDetail->firstname} {$customerGuestDetail->lastname}</dd>
<br>
<dt>{l s='Email'}</dt>
<dd class="guest_email"><a href="mailto:{$customerGuestDetail->email}"><i class="icon-envelope-o"></i> {$customerGuestDetail->email}</a></dd><br>
<dt>{l s='Phone'}</dt>
<dd class="guest_phone"><a href="tel:{$customerGuestDetail->phone}"><i class="icon-envelope-o"></i> {$customerGuestDetail->phone}</a></dd>
<div class="text-right">
<button id="edit_guest_details" class="btn btn-default">
<i class="icon-pencil"></i>
{l s='Edit'}
</button>
</div>
</dl>
<form id="customer-guest-details-form" style="display:none">
<dl>
<dt>{l s='Social title'}</dt>
<dd>
<select name="id_gender">
{foreach from=$genders key=k item=gender}
<option value="{$gender->id_gender}"{if $customerGuestDetail->id_gender == $gender->id_gender} selected="selected"{/if}>{$gender->name}</option>
{/foreach}
</select>
</dd><br>
<dt>{l s='First name'}</dt>
<dd>
<input type="text" value="{$customerGuestDetail->firstname}" name="firstname">
</dd><br>
<dt>{l s='Last name'}</dt>
<dd>
<input type="text" value="{$customerGuestDetail->lastname}" name="lastname">
</dd><br>
<dt>{l s='Email'}</dt>
<dd>
<input type="text" value="{$customerGuestDetail->email}" name="email">
</dd><br>
<dt>{l s='Phone'}</dt>
<dd>
<input type="text" value="{$customerGuestDetail->phone}" name="phone">
</dd>
</dl>
<div class="text-right">

<button id="cancle_edit_guest_details" class="btn btn-default">
<i class="icon-remove"></i>
{l s='cancel'}
</button>
<button id="submit_guest_details" class="btn btn-default">
<i class="icon-save"></i>
{l s='Save'}
</button>
</div>
</form>
</div>
{/if}
{/if}
</div>

Expand Down Expand Up @@ -1674,6 +1747,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();
Expand Down
83 changes: 83 additions & 0 deletions classes/CartCustomerGuestDetail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php
/**
* 2010-2022 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 <support@webkul.com>
* @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 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;
}
}
40 changes: 40 additions & 0 deletions classes/PaymentModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,22 @@ public function validateOrder($id_cart, $id_order_state, $amount_paid, $payment_
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)
Expand Down Expand Up @@ -1017,6 +1033,30 @@ public function validateOrder($id_cart, $id_order_state, $amount_paid, $payment_
null, _PS_MAIL_DIR_, false, (int)$order->id_shop
);
}
// send mail to customer guest if customer booked for someone other.
if ($id_customer_guest_detail = OrderCustomerGuestDetail::isCustomerGuestBooking($order->id)) {
if ($objOrderCustomerGuestDetail = new OrderCustomerGuestDetail(
$id_customer_guest_detail
)) {
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,
$objOrderCustomerGuestDetail->email,
$objOrderCustomerGuestDetail->firstname.' '.$objOrderCustomerGuestDetail->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
Expand Down
10 changes: 9 additions & 1 deletion classes/checkoutProcess/CheckoutCustomerDetailsStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,17 @@ public function handleRequest()
}
}
} elseif (Tools::getValue('proceed_to_payment')) {
$guestInfoComplete = true;
if ($id_customer_guest_detail = CartCustomerGuestDetail::getCartCustomerGuest($this->context->cart->id)) {
$guestInfoComplete = false;
$objCustomerGuestDetail = new CartCustomerGuestDetail($id_customer_guest_detail);
if ($objCustomerGuestDetail->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;
Expand Down
74 changes: 74 additions & 0 deletions classes/order/OrderCustomerGuestDetail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
/**
* 2010-2022 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 <support@webkul.com>
* @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;
}
}
Loading