Skip to content

Commit 7b938aa

Browse files
Remove address as required in booking/order flow
1 parent ce93a98 commit 7b938aa

File tree

8 files changed

+51
-85
lines changed

8 files changed

+51
-85
lines changed

classes/PaymentModule.php

-12
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,6 @@ public function validateOrder($id_cart, $id_order_state, $amount_paid, $payment_
181181
ShopUrl::resetMainDomainCache();
182182
$id_currency = $currency_special ? (int)$currency_special : (int)$this->context->cart->id_currency;
183183
$this->context->currency = new Currency((int)$id_currency, null, (int)$this->context->shop->id);
184-
if (Configuration::get('PS_TAX_ADDRESS_TYPE') == 'id_address_delivery') {
185-
$context_country = $this->context->country;
186-
}
187184

188185
$order_status = new OrderState((int)$id_order_state, (int)$this->context->language->id);
189186
if (!Validate::isLoadedObject($order_status)) {
@@ -463,15 +460,6 @@ public function validateOrder($id_cart, $id_order_state, $amount_paid, $payment_
463460
}
464461
}
465462

466-
// The country can only change if the address used for the calculation is the delivery address, and if multi-shipping is activated
467-
if (Configuration::get('PS_TAX_ADDRESS_TYPE') == 'id_address_delivery') {
468-
$this->context->country = $context_country;
469-
}
470-
471-
if (!$this->context->country->active) {
472-
PrestaShopLogger::addLog('PaymentModule::validateOrder - Country is not active', 3, null, 'Cart', (int)$id_cart, true);
473-
throw new PrestaShopException('The order address country is not active.');
474-
}
475463

476464
if (self::DEBUG_MODE) {
477465
PrestaShopLogger::addLog('PaymentModule::validateOrder - Payment is about to be added', 1, null, 'Cart', (int)$id_cart, true);

classes/checkoutProcess/CheckoutCustomerDetailsStep.php

+7-25
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,9 @@ public function handleRequest()
3333
if (Tools::getValue('proceed_to_customer_dtl')) {
3434
$this->step_is_reachable = 1;
3535
$this->step_is_current = 1;
36-
if ($idAddressDelivery) {
37-
if (!Validate::isLoadedObject($objAddress)) {
38-
if ($this->context->cookie->__get('customer_details_proceeded')) {
39-
$this->step_is_current = 0;
40-
$this->step_is_complete = 1;
41-
}
42-
}
36+
if ($this->context->cookie->__get('customer_details_proceeded')) {
37+
$this->step_is_current = 0;
38+
$this->step_is_complete = 1;
4339
}
4440
} elseif (Tools::getValue('proceed_to_payment')) {
4541
$guestInfoComplete = true;
@@ -52,34 +48,20 @@ public function handleRequest()
5248
}
5349
$this->step_is_reachable = 1;
5450
$this->step_is_current = 1;
55-
if ($idAddressDelivery && $guestInfoComplete) {
56-
if (Validate::isLoadedObject($objAddress)) {
57-
$this->step_is_current = 0;
58-
$this->step_is_complete = 1;
59-
$this->context->cookie->__set('customer_details_proceeded', 1);
60-
}
51+
if ($guestInfoComplete) {
52+
$this->step_is_current = 0;
53+
$this->step_is_complete = 1;
54+
$this->context->cookie->__set('customer_details_proceeded', 1);
6155
}
6256
} elseif ($this->context->cookie->__get('customer_details_proceeded')
6357
|| $this->context->cookie->__get('cart_summary_proceeded')
6458
) {
65-
if ($idAddressDelivery) {
66-
if (!Validate::isLoadedObject($objAddress)) {
67-
$this->context->cookie->__set('customer_details_proceeded', 0);
68-
$this->step_is_reachable = 1;
69-
$this->step_is_current = 1;
70-
}
71-
} else {
72-
$this->step_is_reachable = 1;
73-
$this->step_is_current = 1;
74-
$this->context->cookie->__set('customer_details_proceeded', 0);
75-
}
7659
} elseif ($this->context->customer->logged) {
7760
$this->step_is_reachable = 1;
7861
if ($idAddressDelivery) {
7962
$this->step_is_complete = 1;
8063
} else {
8164
$this->step_is_complete = 0;
82-
$this->step_is_current = 1;
8365
}
8466
}
8567
}

classes/controller/FrontController.php

+6-5
Original file line numberDiff line numberDiff line change
@@ -416,11 +416,12 @@ public function init()
416416

417417
$display_tax_label = $this->context->country->display_tax_label;
418418
if (isset($cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}) && $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}) {
419-
$infos = Address::getCountryAndState((int)$cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
420-
$country = new Country((int)$infos['id_country']);
421-
$this->context->country = $country;
422-
if (Validate::isLoadedObject($country)) {
423-
$display_tax_label = $country->display_tax_label;
419+
if ($infos = Address::getCountryAndState((int)$cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')})) {
420+
$country = new Country((int)$infos['id_country']);
421+
$this->context->country = $country;
422+
if (Validate::isLoadedObject($country)) {
423+
$display_tax_label = $country->display_tax_label;
424+
}
424425
}
425426
}
426427

classes/module/Module.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -2065,8 +2065,8 @@ public static function getPaypalIgnore()
20652065
public static function getPaymentModules()
20662066
{
20672067
$context = Context::getContext();
2068-
if (isset($context->cart)) {
2069-
$billing = new Address((int)$context->cart->id_address_invoice);
2068+
if (Validate::isLoadedObject($context->country)) {
2069+
$id_country = (int)$context->country->id;
20702070
}
20712071

20722072
$use_groups = Group::isFeatureActive();
@@ -2097,7 +2097,7 @@ public static function getPaymentModules()
20972097
LEFT JOIN `'._DB_PREFIX_.'hook_module` hm ON hm.`id_module` = m.`id_module`
20982098
LEFT JOIN `'._DB_PREFIX_.'hook` h ON hm.`id_hook` = h.`id_hook`
20992099
WHERE h.`name` = \''.pSQL($hook_payment).'\'
2100-
'.(isset($billing) && $frontend ? 'AND mc.id_country = '.(int)$billing->id_country : '').'
2100+
'.(isset($id_country) && $frontend ? 'AND mc.id_country = '.(int)$id_country : '').'
21012101
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).'
21022102
AND hm.id_shop IN('.implode(', ', $list).')
21032103
'.((count($groups) && $frontend && $use_groups) ? 'AND (mg.`id_group` IN ('.implode(', ', $groups).'))' : '').'

controllers/front/OrderOpcController.php

-3
Original file line numberDiff line numberDiff line change
@@ -735,9 +735,6 @@ protected function _getPaymentMethods()
735735
}
736736
$address_delivery = new Address($this->context->cart->id_address_delivery);
737737
$address_invoice = ($this->context->cart->id_address_delivery == $this->context->cart->id_address_invoice ? $address_delivery : new Address($this->context->cart->id_address_invoice));
738-
if (!$this->context->cart->id_address_delivery || !$this->context->cart->id_address_invoice || !Validate::isLoadedObject($address_delivery) || !Validate::isLoadedObject($address_invoice) || $address_invoice->deleted || $address_delivery->deleted) {
739-
return '<p class="warning">'.Tools::displayError('Error: Please select an address.').'</p>';
740-
}
741738
if (count($this->context->cart->getDeliveryOptionList()) == 0 && !$this->context->cart->isVirtualCart()) {
742739
if ($this->context->cart->isMultiAddressDelivery()) {
743740
return '<p class="warning">'.Tools::displayError('Error: None of your chosen carriers deliver to some of the addresses you have selected.').'</p>';

controllers/front/ParentOrderController.php

+33-35
Original file line numberDiff line numberDiff line change
@@ -399,56 +399,54 @@ protected function _assignAddress()
399399
Tools::redirect('');
400400
} elseif (!Customer::getAddressesTotalById($this->context->customer->id)) {
401401
$multi = (int)Tools::getValue('multi-shipping');
402-
Tools::redirect('index.php?controller=address&back='.urlencode('order.php?step=1'.($multi ? '&multi-shipping='.$multi : '')));
403402
}
404403

405404
$customer = $this->context->customer;
406405
if (Validate::isLoadedObject($customer)) {
407406
/* Getting customer addresses */
408-
$customerAddresses = $customer->getAddresses($this->context->language->id);
407+
if ($customerAddresses = $customer->getAddresses($this->context->language->id)) {
408+
// Getting a list of formated address fields with associated values
409+
$formatedAddressFieldsValuesList = array();
409410

410-
// Getting a list of formated address fields with associated values
411-
$formatedAddressFieldsValuesList = array();
411+
foreach ($customerAddresses as $i => $address) {
412+
if (!Address::isCountryActiveById((int)$address['id_address'])) {
413+
unset($customerAddresses[$i]);
414+
}
415+
$tmpAddress = new Address($address['id_address']);
416+
$formatedAddressFieldsValuesList[$address['id_address']]['ordered_fields'] = AddressFormat::getOrderedAddressFields($address['id_country']);
417+
$formatedAddressFieldsValuesList[$address['id_address']]['formated_fields_values'] = AddressFormat::getFormattedAddressFieldsValues(
418+
$tmpAddress,
419+
$formatedAddressFieldsValuesList[$address['id_address']]['ordered_fields']);
412420

413-
foreach ($customerAddresses as $i => $address) {
414-
if (!Address::isCountryActiveById((int)$address['id_address'])) {
415-
unset($customerAddresses[$i]);
421+
unset($tmpAddress);
416422
}
417-
$tmpAddress = new Address($address['id_address']);
418-
$formatedAddressFieldsValuesList[$address['id_address']]['ordered_fields'] = AddressFormat::getOrderedAddressFields($address['id_country']);
419-
$formatedAddressFieldsValuesList[$address['id_address']]['formated_fields_values'] = AddressFormat::getFormattedAddressFieldsValues(
420-
$tmpAddress,
421-
$formatedAddressFieldsValuesList[$address['id_address']]['ordered_fields']);
422423

423-
unset($tmpAddress);
424-
}
424+
$customerAddresses = array_values($customerAddresses);
425425

426-
$customerAddresses = array_values($customerAddresses);
426+
if (!count($customerAddresses) && !Tools::isSubmit('ajax')) {
427+
$bad_delivery = false;
428+
if (($bad_delivery = (bool)!Address::isCountryActiveById((int)$this->context->cart->id_address_delivery)) || !Address::isCountryActiveById((int)$this->context->cart->id_address_invoice)) {
429+
$params = array();
430+
if ($this->step) {
431+
$params['step'] = (int)$this->step;
432+
}
433+
if ($multi = (int)Tools::getValue('multi-shipping')) {
434+
$params['multi-shipping'] = $multi;
435+
}
436+
$back_url = $this->context->link->getPageLink('order', true, (int)$this->context->language->id, $params);
427437

428-
if (!count($customerAddresses) && !Tools::isSubmit('ajax')) {
429-
$bad_delivery = false;
430-
if (($bad_delivery = (bool)!Address::isCountryActiveById((int)$this->context->cart->id_address_delivery)) || !Address::isCountryActiveById((int)$this->context->cart->id_address_invoice)) {
431-
$params = array();
432-
if ($this->step) {
433-
$params['step'] = (int)$this->step;
434-
}
435-
if ($multi = (int)Tools::getValue('multi-shipping')) {
436-
$params['multi-shipping'] = $multi;
437-
}
438-
$back_url = $this->context->link->getPageLink('order', true, (int)$this->context->language->id, $params);
438+
$params = array('back' => $back_url, 'id_address' => ($bad_delivery ? (int)$this->context->cart->id_address_delivery : (int)$this->context->cart->id_address_invoice));
439+
if ($multi) {
440+
$params['multi-shipping'] = $multi;
441+
}
439442

440-
$params = array('back' => $back_url, 'id_address' => ($bad_delivery ? (int)$this->context->cart->id_address_delivery : (int)$this->context->cart->id_address_invoice));
441-
if ($multi) {
442-
$params['multi-shipping'] = $multi;
443443
}
444-
445-
Tools::redirect($this->context->link->getPageLink('address', true, (int)$this->context->language->id, $params));
446444
}
445+
$this->context->smarty->assign(array(
446+
'addresses' => $customerAddresses,
447+
'formatedAddressFieldsValuesList' => $formatedAddressFieldsValuesList)
448+
);
447449
}
448-
$this->context->smarty->assign(array(
449-
'addresses' => $customerAddresses,
450-
'formatedAddressFieldsValuesList' => $formatedAddressFieldsValuesList)
451-
);
452450

453451
/* Setting default addresses for cart */
454452
if (count($customerAddresses)) {

modules/bankwire/controllers/front/validation.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class BankwireValidationModuleFrontController extends ModuleFrontController
3535
public function postProcess()
3636
{
3737
$cart = $this->context->cart;
38-
if ($cart->id_customer == 0 || $cart->id_address_delivery == 0 || $cart->id_address_invoice == 0 || !$this->module->active)
38+
if ($cart->id_customer == 0 || !$this->module->active)
3939
Tools::redirect('index.php?controller=order&step=1');
4040

4141
// Check that this payment option is still available in case the customer changed his address just before the end of the checkout process

modules/cheque/controllers/front/validation.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function postProcess()
3333
{
3434
$cart = $this->context->cart;
3535

36-
if ($cart->id_customer == 0 || $cart->id_address_delivery == 0 || $cart->id_address_invoice == 0 || !$this->module->active)
36+
if ($cart->id_customer == 0 || !$this->module->active)
3737
Tools::redirect('index.php?controller=order&step=1');
3838

3939
// Check that this payment option is still available in case the customer changed his address just before the end of the checkout process

0 commit comments

Comments
 (0)