Skip to content

Commit

Permalink
Merge pull request #881 from shreesh-webkul/gli-1078
Browse files Browse the repository at this point in the history
Improvement: Address is not required in booking/order flow
  • Loading branch information
rohit053 authored Mar 17, 2024
2 parents 4bd100b + cca6697 commit 54f3f80
Show file tree
Hide file tree
Showing 20 changed files with 113 additions and 212 deletions.
7 changes: 0 additions & 7 deletions admin/themes/default/template/controllers/orders/form.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -1425,21 +1425,14 @@
});
if (addresses.length == 0)
{
$('#addresses_err').show().html('{l s='You must add at least one address to process the order.'}');
$('#address_delivery, #address_invoice').hide();
$("#new_address").show();
//by webkul (if there is no address then order can not be created)
$("button[name=\"submitAddOrder\"]").attr("disabled", "disabled");
}
else
{
$('#addresses_err').hide();
$("#new_address").hide();
$('#address_delivery, #address_invoice').show();
//by webkul
$("button[name=\"submitAddOrder\"]").removeAttr("disabled");
}
/*Changed by webkul to make delivery and invoice addresses same*/
Expand Down
6 changes: 3 additions & 3 deletions classes/Hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,9 @@ public static function getHookModuleExecList($hook_name = null)
}
// For payment modules, we check that they are available in the contextual country
elseif ($frontend) {
if (Validate::isLoadedObject($context->country)) {
$sql->where('((h.`name` = "displayPayment" OR h.`name` = "displayPaymentEU") AND (SELECT `id_country` FROM `'._DB_PREFIX_.'module_country` mc WHERE mc.`id_module` = m.`id_module` AND `id_country` = '.(int)$context->country->id.' AND `id_shop` = '.(int)$context->shop->id.' LIMIT 1) = '.(int)$context->country->id.')');
}
// if (Validate::isLoadedObject($context->country)) {
// $sql->where('((h.`name` = "displayPayment" OR h.`name` = "displayPaymentEU") AND (SELECT `id_country` FROM `'._DB_PREFIX_.'module_country` mc WHERE mc.`id_module` = m.`id_module` AND `id_country` = '.(int)$context->country->id.' AND `id_shop` = '.(int)$context->shop->id.' LIMIT 1) = '.(int)$context->country->id.')');
// }
if (Validate::isLoadedObject($context->currency)) {
$sql->where('((h.`name` = "displayPayment" OR h.`name` = "displayPaymentEU") AND (SELECT `id_currency` FROM `'._DB_PREFIX_.'module_currency` mcr WHERE mcr.`id_module` = m.`id_module` AND `id_currency` IN ('.(int)$context->currency->id.', -1, -2) LIMIT 1) IN ('.(int)$context->currency->id.', -1, -2))');
}
Expand Down
20 changes: 0 additions & 20 deletions classes/PaymentModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,6 @@ public function validateOrder($id_cart, $id_order_state, $amount_paid, $payment_
ShopUrl::resetMainDomainCache();
$id_currency = $currency_special ? (int)$currency_special : (int)$this->context->cart->id_currency;
$this->context->currency = new Currency((int)$id_currency, null, (int)$this->context->shop->id);
if (Configuration::get('PS_TAX_ADDRESS_TYPE') == 'id_address_delivery') {
$context_country = $this->context->country;
}

$order_status = new OrderState((int)$id_order_state, (int)$this->context->language->id);
if (!Validate::isLoadedObject($order_status)) {
Expand Down Expand Up @@ -274,14 +271,6 @@ public function validateOrder($id_cart, $id_order_state, $amount_paid, $payment_
$order = new Order();
$order->product_list = $package['product_list'];

if (Configuration::get('PS_TAX_ADDRESS_TYPE') == 'id_address_delivery') {
$address = new Address((int)$id_address);
$this->context->country = new Country((int)$address->id_country, (int)$this->context->cart->id_lang);
if (!$this->context->country->active && $this->name != 'wsorder') {
throw new PrestaShopException('The delivery address country is not active.');
}
}

$carrier = null;
if (!$this->context->cart->isVirtualCart() && isset($package['id_carrier'])) {
$carrier = new Carrier((int)$package['id_carrier'], (int)$this->context->cart->id_lang);
Expand Down Expand Up @@ -463,15 +452,6 @@ public function validateOrder($id_cart, $id_order_state, $amount_paid, $payment_
}
}

// The country can only change if the address used for the calculation is the delivery address, and if multi-shipping is activated
if (Configuration::get('PS_TAX_ADDRESS_TYPE') == 'id_address_delivery') {
$this->context->country = $context_country;
}

if (!$this->context->country->active && $this->name != 'wsorder') {
PrestaShopLogger::addLog('PaymentModule::validateOrder - Country is not active', 3, null, 'Cart', (int)$id_cart, true);
throw new PrestaShopException('The order address country is not active.');
}

if (self::DEBUG_MODE) {
PrestaShopLogger::addLog('PaymentModule::validateOrder - Payment is about to be added', 1, null, 'Cart', (int)$id_cart, true);
Expand Down
32 changes: 7 additions & 25 deletions classes/checkoutProcess/CheckoutCustomerDetailsStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,9 @@ public function handleRequest()
if (Tools::getValue('proceed_to_customer_dtl')) {
$this->step_is_reachable = 1;
$this->step_is_current = 1;
if ($idAddressDelivery) {
if (!Validate::isLoadedObject($objAddress)) {
if ($this->context->cookie->__get('customer_details_proceeded')) {
$this->step_is_current = 0;
$this->step_is_complete = 1;
}
}
if ($this->context->cookie->__get('customer_details_proceeded')) {
$this->step_is_current = 0;
$this->step_is_complete = 1;
}
} elseif (Tools::getValue('proceed_to_payment')) {
$guestInfoComplete = true;
Expand All @@ -52,34 +48,20 @@ public function handleRequest()
}
$this->step_is_reachable = 1;
$this->step_is_current = 1;
if ($idAddressDelivery && $guestInfoComplete) {
if (Validate::isLoadedObject($objAddress)) {
$this->step_is_current = 0;
$this->step_is_complete = 1;
$this->context->cookie->__set('customer_details_proceeded', 1);
}
if ($guestInfoComplete) {
$this->step_is_current = 0;
$this->step_is_complete = 1;
$this->context->cookie->__set('customer_details_proceeded', 1);
}
} elseif ($this->context->cookie->__get('customer_details_proceeded')
|| $this->context->cookie->__get('cart_summary_proceeded')
) {
if ($idAddressDelivery) {
if (!Validate::isLoadedObject($objAddress)) {
$this->context->cookie->__set('customer_details_proceeded', 0);
$this->step_is_reachable = 1;
$this->step_is_current = 1;
}
} else {
$this->step_is_reachable = 1;
$this->step_is_current = 1;
$this->context->cookie->__set('customer_details_proceeded', 0);
}
} elseif ($this->context->customer->logged) {
$this->step_is_reachable = 1;
if ($idAddressDelivery) {
$this->step_is_complete = 1;
} else {
$this->step_is_complete = 0;
$this->step_is_current = 1;
}
}
}
Expand Down
11 changes: 6 additions & 5 deletions classes/controller/FrontController.php
Original file line number Diff line number Diff line change
Expand Up @@ -417,11 +417,12 @@ public function init()

$display_tax_label = $this->context->country->display_tax_label;
if (isset($cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}) && $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}) {
$infos = Address::getCountryAndState((int)$cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
$country = new Country((int)$infos['id_country']);
$this->context->country = $country;
if (Validate::isLoadedObject($country)) {
$display_tax_label = $country->display_tax_label;
if ($infos = Address::getCountryAndState((int)$cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')})) {
$country = new Country((int)$infos['id_country']);
$this->context->country = $country;
if (Validate::isLoadedObject($country)) {
$display_tax_label = $country->display_tax_label;
}
}
}

Expand Down
4 changes: 0 additions & 4 deletions classes/module/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -2069,9 +2069,6 @@ public static function getPaypalIgnore()
public static function getPaymentModules()
{
$context = Context::getContext();
if (isset($context->cart)) {
$billing = new Address((int)$context->cart->id_address_invoice);
}

$use_groups = Group::isFeatureActive();

Expand Down Expand Up @@ -2101,7 +2098,6 @@ public static function getPaymentModules()
LEFT JOIN `'._DB_PREFIX_.'hook_module` hm ON hm.`id_module` = m.`id_module`
LEFT JOIN `'._DB_PREFIX_.'hook` h ON hm.`id_hook` = h.`id_hook`
WHERE h.`name` = \''.pSQL($hook_payment).'\'
'.(isset($billing) && $frontend ? 'AND mc.id_country = '.(int)$billing->id_country : '').'
AND (SELECT COUNT(*) FROM '._DB_PREFIX_.'module_shop ms WHERE ms.id_module = m.id_module AND ms.id_shop IN('.implode(', ', $list).')) = '.count($list).'
AND hm.id_shop IN('.implode(', ', $list).')
'.((count($groups) && $frontend && $use_groups) ? 'AND (mg.`id_group` IN ('.implode(', ', $groups).'))' : '').'
Expand Down
7 changes: 0 additions & 7 deletions controllers/admin/AdminCustomerPreferencesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,6 @@ public function __construct()
'cast' => 'intval',
'type' => 'bool'
),
'PS_CUSTOMER_ADDRESS_CREATION' => array(
'title' => $this->l('Address creation during checkout'),
'hint' => $this->l('If disabled, Address form will not appear to user during checkout process. So by default hotel address, which rooms guest has in his cart will be considered as user address. Else user has to fill adress details.'),
'validation' => 'isBool',
'cast' => 'intval',
'type' => 'bool'
),
),
'submit' => array('title' => $this->l('Save')),
),
Expand Down
52 changes: 21 additions & 31 deletions controllers/admin/AdminOrdersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1173,39 +1173,29 @@ public function postProcess()
Context::getContext()->currency = new Currency((int)$cart->id_currency);
Context::getContext()->customer = new Customer((int)$cart->id_customer);

$bad_delivery = false;
if (($bad_delivery = (bool)!Address::isCountryActiveById((int)$cart->id_address_delivery))
|| !Address::isCountryActiveById((int)$cart->id_address_invoice)) {
if ($bad_delivery) {
$this->errors[] = Tools::displayError('This booking address country is not active.');
} else {
$this->errors[] = Tools::displayError('This invoice address country is not active.');
}
} else {
$employee = new Employee((int)Context::getContext()->cookie->id_employee);
$payment_module->validateOrder(
(int)$cart->id,
(int)$id_order_state,
$cart->getOrderTotal(true, Cart::BOTH),
$payment_module->displayName,
$this->l('Manual order -- Employee:').' '.
substr($employee->firstname, 0, 1).'. '.$employee->lastname,
array(),
null,
false,
$cart->secure_key
);
$employee = new Employee((int)Context::getContext()->cookie->id_employee);
$payment_module->validateOrder(
(int)$cart->id,
(int)$id_order_state,
$cart->getOrderTotal(true, Cart::BOTH),
$payment_module->displayName,
$this->l('Manual order -- Employee:').' '.
substr($employee->firstname, 0, 1).'. '.$employee->lastname,
array(),
null,
false,
$cart->secure_key
);

if (isset($this->context->cookie->id_cart)) {
unset($this->context->cookie->id_cart);
}
if (isset($this->context->cookie->id_guest)) {
unset($this->context->cookie->id_guest);
}
if (isset($this->context->cookie->id_cart)) {
unset($this->context->cookie->id_cart);
}
if (isset($this->context->cookie->id_guest)) {
unset($this->context->cookie->id_guest);
}

if ($payment_module->currentOrder) {
Tools::redirectAdmin(self::$currentIndex.'&id_order='.$payment_module->currentOrder.'&vieworder'.'&token='.$this->token.'&conf=3');
}
if ($payment_module->currentOrder) {
Tools::redirectAdmin(self::$currentIndex.'&id_order='.$payment_module->currentOrder.'&vieworder'.'&token='.$this->token.'&conf=3');
}
} else {
$this->errors[] = Tools::displayError('You do not have permission to add this.');
Expand Down
28 changes: 14 additions & 14 deletions controllers/admin/AdminPaymentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,13 @@ public function renderView()
'identifier' => 'id_group',
'icon' => 'icon-group',
),
array('items' =>Country::getCountries($this->context->language->id),
'title' => $this->l('Country restrictions'),
'desc' => $this->l('Please mark each checkbox for the country, or countries, in which you want the payment module(s) to be available.'),
'name_id' => 'country',
'identifier' => 'id_country',
'icon' => 'icon-globe',
)
// array('items' =>Country::getCountries($this->context->language->id),
// 'title' => $this->l('Country restrictions'),
// 'desc' => $this->l('Please mark each checkbox for the country, or countries, in which you want the payment module(s) to be available.'),
// 'name_id' => 'country',
// 'identifier' => 'id_country',
// 'icon' => 'icon-globe',
// )
);

foreach ($lists as $key_list => $list) {
Expand Down Expand Up @@ -243,13 +243,13 @@ public function renderView()
}

// If is a country list and the country is limited, remove it from list
if ($name_id == 'country'
&& isset($module->limited_countries)
&& !empty($module->limited_countries)
&& is_array($module->limited_countries)
&& !(in_array(strtoupper($item['iso_code']), array_map('strtoupper', $module->limited_countries)))) {
$list['items'][$key_item]['check_list'][$key_module] = null;
}
// if ($name_id == 'country'
// && isset($module->limited_countries)
// && !empty($module->limited_countries)
// && is_array($module->limited_countries)
// && !(in_array(strtoupper($item['iso_code']), array_map('strtoupper', $module->limited_countries)))) {
// $list['items'][$key_item]['check_list'][$key_module] = null;
// }
}
}
// update list
Expand Down
37 changes: 5 additions & 32 deletions controllers/front/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,10 @@ protected function processSubmitAccount()
$firstnameAddress = Tools::getValue('firstname');
$_POST['lastname'] = Tools::getValue('customer_lastname', $lastnameAddress);
$_POST['firstname'] = Tools::getValue('customer_firstname', $firstnameAddress);
$addresses_types = array('address');
$addresses_types = [];
if (Configuration::get('PS_REGISTRATION_PROCESS_TYPE')) {
$addresses_types[] = 'address';
}

if (!Configuration::get('PS_ORDER_PROCESS_TYPE') && Configuration::get('PS_GUEST_CHECKOUT_ENABLED') && Tools::getValue('invoice_address')) {
$addresses_types[] = 'address_invoice';
Expand All @@ -435,36 +438,6 @@ protected function processSubmitAccount()
$this->errors[] = Tools::displayError('You must register at least one phone number.');
}

// if PS_CUSTOMER_ADDRESS_CREATION is disabled And customer has no addresses then create customer address
// with the details of first hotel which rooms he has in cart
if (!Configuration::get('PS_CUSTOMER_ADDRESS_CREATION')
&& isset($this->context->cart->id)
&& $this->context->cart->id
) {
if (Module::isInstalled('hotelreservationsystem')) {
include_once _PS_MODULE_DIR_.'hotelreservationsystem/define.php';
$objHtlCart = new HotelCartBookingData();
if ($htlCartInfo = $objHtlCart->getCartCurrentDataByCartId($this->context->cart->id)) {
if (isset($htlCartInfo[0]['id_hotel']) && ($idHotel = $htlCartInfo[0]['id_hotel'])) {
if ($address_info = HotelBranchInformation::getAddress($idHotel)) {
$_POST['lastname'] = Tools::getValue('customer_lastname');
$_POST['firstname'] = Tools::getValue('customer_firstname');
$_POST['address1'] = $address_info['address1'];
$_POST['city'] = $address_info['city'];
$_POST['postcode'] = $address_info['postcode'];
$_POST['alias'] = 'My address';
$_POST['id_country'] = $address_info['id_country'];
$_POST['id_state'] = $address_info['id_state'];
$_POST['auto_generated'] = true;
// if form is shorter then address name will be customer name
$lastnameAddress = $_POST['lastname'];
$firstnameAddress = $_POST['firstname'];
}
}
}
}
}
// End
$this->errors = array_unique(array_merge($this->errors, $customer->validateController()));

// Check the requires fields which are settings in the BO
Expand Down Expand Up @@ -576,7 +549,7 @@ protected function processSubmitAccount()
}

if ($country->need_identification_number) {
if (!Configuration::get('PS_CUSTOMER_ADDRESS_CREATION')) {
if (!Configuration::get('PS_REGISTRATION_PROCESS_TYPE')) {
$$addresses_type->dni = null;
} elseif (!Tools::getValue('dni') || !Validate::isDniLite(Tools::getValue('dni'))) {
$this->errors[] = Tools::displayError('The identification number is incorrect or has already been used.');
Expand Down
Loading

0 comments on commit 54f3f80

Please sign in to comment.