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 9dd21e42e..28280d9ba 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");
@@ -1152,6 +1153,7 @@
else
{
$('#addresses_err').hide();
+ $("#new_address").hide();
$('#address_delivery, #address_invoice').show();
//by webkul
@@ -1159,8 +1161,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..296c9addc 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();
@@ -488,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/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/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/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
-
-
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 4244145fe..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'}
@@ -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"}
@@ -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 724519bcb..66570d7aa 100644
--- a/themes/hotel-reservation-theme/my-account.tpl
+++ b/themes/hotel-reservation-theme/my-account.tpl
@@ -35,15 +35,12 @@