From 776d72a0a2f8ba2cd9daf62565e670f86ec770b5 Mon Sep 17 00:00:00 2001 From: shreesh arora Date: Fri, 14 Jan 2022 00:40:41 +0530 Subject: [PATCH 1/3] removed multiple address option --- .../default/template/controllers/orders/form.tpl | 5 +++-- classes/Address.php | 15 +++++++++++++++ classes/Customer.php | 15 +++++++++++++++ controllers/admin/AdminAddressesController.php | 12 ++++++++++++ controllers/front/AddressController.php | 6 +++--- themes/hotel-reservation-theme/address.tpl | 2 +- themes/hotel-reservation-theme/my-account.tpl | 8 ++++---- 7 files changed, 53 insertions(+), 10 deletions(-) diff --git a/admin/themes/default/template/controllers/orders/form.tpl b/admin/themes/default/template/controllers/orders/form.tpl index 1d80ec936..9bcf5985a 100644 --- a/admin/themes/default/template/controllers/orders/form.tpl +++ b/admin/themes/default/template/controllers/orders/form.tpl @@ -1152,6 +1152,7 @@ else { $('#addresses_err').hide(); + $("#new_address").hide(); $('#address_delivery, #address_invoice').show(); //by webkul @@ -1159,8 +1160,8 @@ } /*Changed by webkul to make delivery and invoice addresses same*/ - $('#id_address_delivery').html(addresses_delivery_options); - $('#id_address_invoice').html(addresses_delivery_options); + $('#id_address_delivery').html(addresses_delivery_options).hide(); + $('#id_address_invoice').html(addresses_delivery_options).hide(); $('#address_delivery_detail').html(address_delivery_detail); $('#address_invoice_detail').html(address_delivery_detail); $('#edit_delivery_address').attr('href', delivery_address_edit_link); diff --git a/classes/Address.php b/classes/Address.php index f1258d791..f8c03294a 100644 --- a/classes/Address.php +++ b/classes/Address.php @@ -178,6 +178,12 @@ class AddressCore extends ObjectModel */ public function add($autodate = true, $null_values = false) { + // for customer address we need to check of customer address already exists. + if ($this->id_customer) { + if ($id_address = Customer::getCustomerIdAddress($this->id_customer)) { + return false; + } + } if (!parent::add($autodate, $null_values)) { return false; } @@ -243,6 +249,15 @@ class AddressCore extends ObjectModel public function validateController($htmlentities = true) { $errors = parent::validateController($htmlentities); + + // for customer address we need to check of customer address already exists. + if ($idCustomer = Tools::getValue('id_customer')) { + if ($id_address = Customer::getCustomerIdAddress($idCustomer)) { + + $errors[] = sprintf(Tools::displayError('Customer address already exists. Id address: #%d'), $id_address); + } + } + return $errors; } /** diff --git a/classes/Customer.php b/classes/Customer.php index f075491e3..519b96b23 100644 --- a/classes/Customer.php +++ b/classes/Customer.php @@ -465,6 +465,21 @@ class CustomerCore extends ObjectModel return Cache::retrieve($cache_id); } + public static function getCustomerIdAddress($id_customer) + { + $cache_id = 'Customer::getCustomerIdAddress'.(int)$id_customer; + if (!Cache::isStored($cache_id)) { + $sql = 'SELECT id_address + FROM `'._DB_PREFIX_.'address` a + WHERE `id_customer` = '.(int)$id_customer.' AND a.`deleted` = 0'; + + $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql); + Cache::store($cache_id, $result); + return $result; + } + return Cache::retrieve($cache_id); + } + /** * Count the number of addresses for a customer * diff --git a/controllers/admin/AdminAddressesController.php b/controllers/admin/AdminAddressesController.php index 0c503b10f..256c4cc90 100644 --- a/controllers/admin/AdminAddressesController.php +++ b/controllers/admin/AdminAddressesController.php @@ -344,12 +344,24 @@ class AdminAddressesControllerCore extends AdminController return parent::renderForm(); } + // public function postProcess() + // { + + // $address = new Address(); + // $this->errors = $address->validateController(); + + // return parent::postProcess(); + // } + public function processSave() { if (Tools::getValue('submitFormAjax')) { $this->redirect_after = false; } + $address = new Address(); + $this->errors = $address->validateController(); + // Transform e-mail in id_customer for parent processing if (Validate::isEmail(Tools::getValue('email'))) { $customer = new Customer(); diff --git a/controllers/front/AddressController.php b/controllers/front/AddressController.php index 55b3d0f51..b80f6ca1b 100644 --- a/controllers/front/AddressController.php +++ b/controllers/front/AddressController.php @@ -68,7 +68,7 @@ class AddressControllerCore extends FrontController $id_address = (int)$this->context->cart->id_address_invoice; } } else { - $id_address = (int)Tools::getValue('id_address', 0); + $id_address = Customer::getCustomerIdAddress($this->context->customer->id); } // Initialize address @@ -91,7 +91,7 @@ class AddressControllerCore extends FrontController } elseif ($this->ajax) { exit; } else { - Tools::redirect('index.php?controller=addresses'); + // Tools::redirect('index.php?controller=addresses'); } } } @@ -241,7 +241,7 @@ class AddressControllerCore extends FrontController $mod = Tools::getValue('mod'); Tools::redirect('index.php?controller='.$back.($mod ? '&back='.$mod : '')); } else { - Tools::redirect('index.php?controller=addresses'); + Tools::redirect('index.php?controller=address'); } } $this->errors[] = Tools::displayError('An error occurred while updating your address.'); diff --git a/themes/hotel-reservation-theme/address.tpl b/themes/hotel-reservation-theme/address.tpl index 4244145fe..defcd8b52 100644 --- a/themes/hotel-reservation-theme/address.tpl +++ b/themes/hotel-reservation-theme/address.tpl @@ -34,7 +34,7 @@ {if isset($address->alias)}"{$address->alias|escape:'html':'UTF-8'}"{/if} {/if} {else} - {l s='To add a new address, please fill out the form below.'} + {l s='To add an address, please fill out the form below.'} {/if}

{include file="$tpl_dir./errors.tpl"} diff --git a/themes/hotel-reservation-theme/my-account.tpl b/themes/hotel-reservation-theme/my-account.tpl index 724519bcb..5cb2b5d43 100644 --- a/themes/hotel-reservation-theme/my-account.tpl +++ b/themes/hotel-reservation-theme/my-account.tpl @@ -35,15 +35,15 @@
From 479a88f4e2bad3957d9f42934621bef5726f56cc Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Mon, 5 Dec 2022 17:11:14 +0530 Subject: [PATCH 2/3] updated address page --- controllers/front/AddressesController.php | 2 ++ modules/blockmyaccount/blockmyaccount.tpl | 1 - themes/hotel-reservation-theme/address.tpl | 8 ++++---- .../modules/blockmyaccount/blockmyaccount.tpl | 5 ----- themes/hotel-reservation-theme/my-account.tpl | 3 --- 5 files changed, 6 insertions(+), 13 deletions(-) diff --git a/controllers/front/AddressesController.php b/controllers/front/AddressesController.php index 27e81f944..aa5365316 100644 --- a/controllers/front/AddressesController.php +++ b/controllers/front/AddressesController.php @@ -50,6 +50,8 @@ class AddressesControllerCore extends FrontController { parent::init(); + Tools::redirect($this->context->link->getPageLink('address')); + if (!Validate::isLoadedObject($this->context->customer)) { die(Tools::displayError('The customer could not be found.')); } diff --git a/modules/blockmyaccount/blockmyaccount.tpl b/modules/blockmyaccount/blockmyaccount.tpl index 6980f7fdc..0282a0d05 100644 --- a/modules/blockmyaccount/blockmyaccount.tpl +++ b/modules/blockmyaccount/blockmyaccount.tpl @@ -31,7 +31,6 @@
  • {l s='My orders' mod='blockmyaccount'}
  • {if $returnAllowed}
  • {l s='My merchandise returns' mod='blockmyaccount'}
  • {/if}
  • {l s='My credit slips' mod='blockmyaccount'}
  • -
  • {l s='My addresses' mod='blockmyaccount'}
  • {l s='My personal info' mod='blockmyaccount'}
  • {if $voucherAllowed}
  • {l s='My vouchers' mod='blockmyaccount'}
  • {/if} {$HOOK_BLOCK_MY_ACCOUNT} diff --git a/themes/hotel-reservation-theme/address.tpl b/themes/hotel-reservation-theme/address.tpl index defcd8b52..44b8f74e0 100644 --- a/themes/hotel-reservation-theme/address.tpl +++ b/themes/hotel-reservation-theme/address.tpl @@ -22,9 +22,9 @@ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA *} -{capture name=path}{l s='Your addresses'}{/capture} +{capture name=path}{l s='Your address'}{/capture}
    -

    {l s='Your addresses'}

    +

    {l s='Your address'}

    {if isset($id_address) && (isset($smarty.post.alias) || isset($address->alias))} {l s='Modify address'} @@ -199,8 +199,8 @@

    diff --git a/themes/hotel-reservation-theme/modules/blockmyaccount/blockmyaccount.tpl b/themes/hotel-reservation-theme/modules/blockmyaccount/blockmyaccount.tpl index 34feb4486..cbb0dc8c1 100644 --- a/themes/hotel-reservation-theme/modules/blockmyaccount/blockmyaccount.tpl +++ b/themes/hotel-reservation-theme/modules/blockmyaccount/blockmyaccount.tpl @@ -48,11 +48,6 @@ {l s='My credit slips' mod='blockmyaccount'} -
  • - - {l s='My addresses' mod='blockmyaccount'} - -
  • {l s='My personal info' mod='blockmyaccount'} diff --git a/themes/hotel-reservation-theme/my-account.tpl b/themes/hotel-reservation-theme/my-account.tpl index 5cb2b5d43..66570d7aa 100644 --- a/themes/hotel-reservation-theme/my-account.tpl +++ b/themes/hotel-reservation-theme/my-account.tpl @@ -35,15 +35,12 @@
    From a2fea8aa6cd2b3025b17fd9a9053c6ed65cc1b42 Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Sun, 25 Dec 2022 10:19:59 +0530 Subject: [PATCH 3/3] updated admin address and order page --- .../template/controllers/addresses/helpers/form/form.tpl | 2 ++ admin/themes/default/template/controllers/orders/form.tpl | 1 + controllers/admin/AdminAddressesController.php | 2 +- install/fixtures/fashion/data/address.xml | 7 ------- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/admin/themes/default/template/controllers/addresses/helpers/form/form.tpl b/admin/themes/default/template/controllers/addresses/helpers/form/form.tpl index d416d2a07..ea72d4782 100644 --- a/admin/themes/default/template/controllers/addresses/helpers/form/form.tpl +++ b/admin/themes/default/template/controllers/addresses/helpers/form/form.tpl @@ -71,6 +71,7 @@ $('input[name=firstname]').val(infos[0]); $('input[name=lastname]').val(infos[1]); $('input[name=company]').val(infos[2]); + $('input[name=id_customer]').val(infos[3]); } }, error: function(msg) @@ -82,6 +83,7 @@
    +
    {/if} diff --git a/admin/themes/default/template/controllers/orders/form.tpl b/admin/themes/default/template/controllers/orders/form.tpl index 9bcf5985a..3f421b6df 100644 --- a/admin/themes/default/template/controllers/orders/form.tpl +++ b/admin/themes/default/template/controllers/orders/form.tpl @@ -1145,6 +1145,7 @@ { $('#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"); diff --git a/controllers/admin/AdminAddressesController.php b/controllers/admin/AdminAddressesController.php index 256c4cc90..296c9addc 100644 --- a/controllers/admin/AdminAddressesController.php +++ b/controllers/admin/AdminAddressesController.php @@ -500,7 +500,7 @@ class AdminAddressesControllerCore extends AdminController $customer = Customer::searchByName($email); if (!empty($customer)) { $customer = $customer['0']; - echo json_encode(array('infos' => pSQL($customer['firstname']).'_'.pSQL($customer['lastname']).'_'.pSQL($customer['company']))); + echo json_encode(array('infos' => pSQL($customer['firstname']).'_'.pSQL($customer['lastname']).'_'.pSQL($customer['company']).'_'.pSQL($customer['id_customer']))); } } die; diff --git a/install/fixtures/fashion/data/address.xml b/install/fixtures/fashion/data/address.xml index b37587575..d4cee69e2 100644 --- a/install/fixtures/fashion/data/address.xml +++ b/install/fixtures/fashion/data/address.xml @@ -30,12 +30,5 @@ Paris -
    - My Company - 16, Main street - 2nd floor - Miami - -