From 7b938aa0232ecfdbc242dc592bc5a638e7c45312 Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Mon, 20 Nov 2023 16:01:54 +0530 Subject: [PATCH 1/5] Remove address as required in booking/order flow --- classes/PaymentModule.php | 12 ---- .../CheckoutCustomerDetailsStep.php | 32 ++------- classes/controller/FrontController.php | 11 +-- classes/module/Module.php | 6 +- controllers/front/OrderOpcController.php | 3 - controllers/front/ParentOrderController.php | 68 +++++++++---------- .../bankwire/controllers/front/validation.php | 2 +- .../cheque/controllers/front/validation.php | 2 +- 8 files changed, 51 insertions(+), 85 deletions(-) diff --git a/classes/PaymentModule.php b/classes/PaymentModule.php index 3e89319f2..fbca539bf 100644 --- a/classes/PaymentModule.php +++ b/classes/PaymentModule.php @@ -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)) { @@ -463,15 +460,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) { - 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); diff --git a/classes/checkoutProcess/CheckoutCustomerDetailsStep.php b/classes/checkoutProcess/CheckoutCustomerDetailsStep.php index b8933ae06..6bccd6e83 100644 --- a/classes/checkoutProcess/CheckoutCustomerDetailsStep.php +++ b/classes/checkoutProcess/CheckoutCustomerDetailsStep.php @@ -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; @@ -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; } } } diff --git a/classes/controller/FrontController.php b/classes/controller/FrontController.php index 2f19b9f61..ae6ab2da5 100644 --- a/classes/controller/FrontController.php +++ b/classes/controller/FrontController.php @@ -416,11 +416,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; + } } } diff --git a/classes/module/Module.php b/classes/module/Module.php index 04c4a2cbe..3ed023503 100644 --- a/classes/module/Module.php +++ b/classes/module/Module.php @@ -2065,8 +2065,8 @@ public static function getPaypalIgnore() public static function getPaymentModules() { $context = Context::getContext(); - if (isset($context->cart)) { - $billing = new Address((int)$context->cart->id_address_invoice); + if (Validate::isLoadedObject($context->country)) { + $id_country = (int)$context->country->id; } $use_groups = Group::isFeatureActive(); @@ -2097,7 +2097,7 @@ 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 : '').' + '.(isset($id_country) && $frontend ? 'AND mc.id_country = '.(int)$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).'))' : '').' diff --git a/controllers/front/OrderOpcController.php b/controllers/front/OrderOpcController.php index 17ef02dcb..e74ed1ed7 100644 --- a/controllers/front/OrderOpcController.php +++ b/controllers/front/OrderOpcController.php @@ -735,9 +735,6 @@ protected function _getPaymentMethods() } $address_delivery = new Address($this->context->cart->id_address_delivery); $address_invoice = ($this->context->cart->id_address_delivery == $this->context->cart->id_address_invoice ? $address_delivery : new Address($this->context->cart->id_address_invoice)); - 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) { - return '

'.Tools::displayError('Error: Please select an address.').'

'; - } if (count($this->context->cart->getDeliveryOptionList()) == 0 && !$this->context->cart->isVirtualCart()) { if ($this->context->cart->isMultiAddressDelivery()) { return '

'.Tools::displayError('Error: None of your chosen carriers deliver to some of the addresses you have selected.').'

'; diff --git a/controllers/front/ParentOrderController.php b/controllers/front/ParentOrderController.php index eb2bf17d7..7bac1b5d9 100644 --- a/controllers/front/ParentOrderController.php +++ b/controllers/front/ParentOrderController.php @@ -399,56 +399,54 @@ protected function _assignAddress() Tools::redirect(''); } elseif (!Customer::getAddressesTotalById($this->context->customer->id)) { $multi = (int)Tools::getValue('multi-shipping'); - Tools::redirect('index.php?controller=address&back='.urlencode('order.php?step=1'.($multi ? '&multi-shipping='.$multi : ''))); } $customer = $this->context->customer; if (Validate::isLoadedObject($customer)) { /* Getting customer addresses */ - $customerAddresses = $customer->getAddresses($this->context->language->id); + if ($customerAddresses = $customer->getAddresses($this->context->language->id)) { + // Getting a list of formated address fields with associated values + $formatedAddressFieldsValuesList = array(); - // Getting a list of formated address fields with associated values - $formatedAddressFieldsValuesList = array(); + foreach ($customerAddresses as $i => $address) { + if (!Address::isCountryActiveById((int)$address['id_address'])) { + unset($customerAddresses[$i]); + } + $tmpAddress = new Address($address['id_address']); + $formatedAddressFieldsValuesList[$address['id_address']]['ordered_fields'] = AddressFormat::getOrderedAddressFields($address['id_country']); + $formatedAddressFieldsValuesList[$address['id_address']]['formated_fields_values'] = AddressFormat::getFormattedAddressFieldsValues( + $tmpAddress, + $formatedAddressFieldsValuesList[$address['id_address']]['ordered_fields']); - foreach ($customerAddresses as $i => $address) { - if (!Address::isCountryActiveById((int)$address['id_address'])) { - unset($customerAddresses[$i]); + unset($tmpAddress); } - $tmpAddress = new Address($address['id_address']); - $formatedAddressFieldsValuesList[$address['id_address']]['ordered_fields'] = AddressFormat::getOrderedAddressFields($address['id_country']); - $formatedAddressFieldsValuesList[$address['id_address']]['formated_fields_values'] = AddressFormat::getFormattedAddressFieldsValues( - $tmpAddress, - $formatedAddressFieldsValuesList[$address['id_address']]['ordered_fields']); - unset($tmpAddress); - } + $customerAddresses = array_values($customerAddresses); - $customerAddresses = array_values($customerAddresses); + if (!count($customerAddresses) && !Tools::isSubmit('ajax')) { + $bad_delivery = false; + if (($bad_delivery = (bool)!Address::isCountryActiveById((int)$this->context->cart->id_address_delivery)) || !Address::isCountryActiveById((int)$this->context->cart->id_address_invoice)) { + $params = array(); + if ($this->step) { + $params['step'] = (int)$this->step; + } + if ($multi = (int)Tools::getValue('multi-shipping')) { + $params['multi-shipping'] = $multi; + } + $back_url = $this->context->link->getPageLink('order', true, (int)$this->context->language->id, $params); - if (!count($customerAddresses) && !Tools::isSubmit('ajax')) { - $bad_delivery = false; - if (($bad_delivery = (bool)!Address::isCountryActiveById((int)$this->context->cart->id_address_delivery)) || !Address::isCountryActiveById((int)$this->context->cart->id_address_invoice)) { - $params = array(); - if ($this->step) { - $params['step'] = (int)$this->step; - } - if ($multi = (int)Tools::getValue('multi-shipping')) { - $params['multi-shipping'] = $multi; - } - $back_url = $this->context->link->getPageLink('order', true, (int)$this->context->language->id, $params); + $params = array('back' => $back_url, 'id_address' => ($bad_delivery ? (int)$this->context->cart->id_address_delivery : (int)$this->context->cart->id_address_invoice)); + if ($multi) { + $params['multi-shipping'] = $multi; + } - $params = array('back' => $back_url, 'id_address' => ($bad_delivery ? (int)$this->context->cart->id_address_delivery : (int)$this->context->cart->id_address_invoice)); - if ($multi) { - $params['multi-shipping'] = $multi; } - - Tools::redirect($this->context->link->getPageLink('address', true, (int)$this->context->language->id, $params)); } + $this->context->smarty->assign(array( + 'addresses' => $customerAddresses, + 'formatedAddressFieldsValuesList' => $formatedAddressFieldsValuesList) + ); } - $this->context->smarty->assign(array( - 'addresses' => $customerAddresses, - 'formatedAddressFieldsValuesList' => $formatedAddressFieldsValuesList) - ); /* Setting default addresses for cart */ if (count($customerAddresses)) { diff --git a/modules/bankwire/controllers/front/validation.php b/modules/bankwire/controllers/front/validation.php index 5df9b7411..e9cd89014 100644 --- a/modules/bankwire/controllers/front/validation.php +++ b/modules/bankwire/controllers/front/validation.php @@ -35,7 +35,7 @@ class BankwireValidationModuleFrontController extends ModuleFrontController public function postProcess() { $cart = $this->context->cart; - if ($cart->id_customer == 0 || $cart->id_address_delivery == 0 || $cart->id_address_invoice == 0 || !$this->module->active) + if ($cart->id_customer == 0 || !$this->module->active) Tools::redirect('index.php?controller=order&step=1'); // Check that this payment option is still available in case the customer changed his address just before the end of the checkout process diff --git a/modules/cheque/controllers/front/validation.php b/modules/cheque/controllers/front/validation.php index f280abd3f..8c79afea1 100644 --- a/modules/cheque/controllers/front/validation.php +++ b/modules/cheque/controllers/front/validation.php @@ -33,7 +33,7 @@ public function postProcess() { $cart = $this->context->cart; - if ($cart->id_customer == 0 || $cart->id_address_delivery == 0 || $cart->id_address_invoice == 0 || !$this->module->active) + if ($cart->id_customer == 0 || !$this->module->active) Tools::redirect('index.php?controller=order&step=1'); // Check that this payment option is still available in case the customer changed his address just before the end of the checkout process From 8cff333d57c62bb98e99db471ddf0cddd46f927b Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Mon, 20 Nov 2023 16:14:45 +0530 Subject: [PATCH 2/5] hide invoice address panel when customer address was not available while booking --- pdf/invoice.addresses-tab.tpl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pdf/invoice.addresses-tab.tpl b/pdf/invoice.addresses-tab.tpl index 1e17a445e..d4d9f0701 100644 --- a/pdf/invoice.addresses-tab.tpl +++ b/pdf/invoice.addresses-tab.tpl @@ -22,6 +22,7 @@ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA *} +{if $invoice_address}