From 776d72a0a2f8ba2cd9daf62565e670f86ec770b5 Mon Sep 17 00:00:00 2001
From: shreesh arora
Date: Fri, 14 Jan 2022 00:40:41 +0530
Subject: [PATCH] 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 @@