Merge pull request #467 from shreesh-webkul/gli-567

Removed option to create multiple address of customer
This commit is contained in:
Rohit Jain
2022-12-25 17:38:32 +05:30
committed by GitHub
12 changed files with 60 additions and 28 deletions

View File

@@ -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 @@
</script>
<div class="col-lg-4">
<input type="hidden" name="id_customer" value="{$fields_value[$input.id_customer]}" />
<input type="email" id="email" name="email" value="{$fields_value[$input.name]|escape:'html':'UTF-8'}"/>
</div>
{/if}

View File

@@ -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);

View File

@@ -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;
}
/**

View File

@@ -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
*

View File

@@ -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;

View File

@@ -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.');

View File

@@ -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.'));
}

View File

@@ -30,12 +30,5 @@
<city>Paris </city>
<other/>
</address>
<address id="My_address" id_country="US" id_state="FL" id_customer="John" id_manufacturer="" id_supplier="" id_warehouse="0" alias="My address" lastname="DOE" firstname="John" postcode="33133" phone="0102030405" phone_mobile="" vat_number="" dni="" active="1">
<company>My Company</company>
<address1>16, Main street</address1>
<address2>2nd floor</address2>
<city>Miami</city>
<other/>
</address>
</entities>
</entity_address>

View File

@@ -31,7 +31,6 @@
<li><a href="{$link->getPageLink('history', true)|escape:'html'}" title="">{l s='My orders' mod='blockmyaccount'}</a></li>
{if $returnAllowed}<li><a href="{$link->getPageLink('order-follow', true)|escape:'html'}" title="{l s='My merchandise returns' mod='blockmyaccount'}">{l s='My merchandise returns' mod='blockmyaccount'}</a></li>{/if}
<li><a href="{$link->getPageLink('order-slip', true)|escape:'html'}" title="{l s='My credit slips' mod='blockmyaccount'}">{l s='My credit slips' mod='blockmyaccount'}</a></li>
<li><a href="{$link->getPageLink('addresses', true)|escape:'html'}" title="{l s='My addresses' mod='blockmyaccount'}">{l s='My addresses' mod='blockmyaccount'}</a></li>
<li><a href="{$link->getPageLink('identity', true)|escape:'html'}" title="{l s='My personal info' mod='blockmyaccount'}">{l s='My personal info' mod='blockmyaccount'}</a></li>
{if $voucherAllowed}<li><a href="{$link->getPageLink('discount', true)|escape:'html'}" title="{l s='My vouchers' mod='blockmyaccount'}">{l s='My vouchers' mod='blockmyaccount'}</a></li>{/if}
{$HOOK_BLOCK_MY_ACCOUNT}

View File

@@ -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}
<div class="box">
<h1 class="page-subheading">{l s='Your addresses'}</h1>
<h1 class="page-subheading">{l s='Your address'}</h1>
<p class="info-title">
{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}
</p>
{include file="$tpl_dir./errors.tpl"}
@@ -199,8 +199,8 @@
</div>
<ul class="footer_links clearfix">
<li>
<a class="btn btn-defaul button button-small" href="{$link->getPageLink('addresses', true)|escape:'html':'UTF-8'}">
<span><i class="icon-chevron-left"></i> {l s='Back to your addresses'}</span>
<a class="btn btn-defaul button button-small" href="{$link->getPageLink('my-account', true)|escape:'html':'UTF-8'}">
<span><i class="icon-chevron-left"></i> {l s='Back to your account'}</span>
</a>
</li>
</ul>

View File

@@ -48,11 +48,6 @@
<a href="{$link->getPageLink('order-slip', true)|escape:'html':'UTF-8'}" title="{l s='My credit slips' mod='blockmyaccount'}"> {l s='My credit slips' mod='blockmyaccount'}
</a>
</li>
<li>
<a href="{$link->getPageLink('addresses', true)|escape:'html':'UTF-8'}" title="{l s='My addresses' mod='blockmyaccount'}">
{l s='My addresses' mod='blockmyaccount'}
</a>
</li>
<li>
<a href="{$link->getPageLink('identity', true)|escape:'html':'UTF-8'}" title="{l s='My personal info' mod='blockmyaccount'}">
{l s='My personal info' mod='blockmyaccount'}

View File

@@ -35,15 +35,12 @@
<div class="row addresses-lists">
<div class="col-xs-12 col-sm-6 col-lg-4">
<ul class="myaccount-link-list">
{if $has_customer_an_address}
<li><a href="{$link->getPageLink('address', true)|escape:'html':'UTF-8'}" title="{l s='Add my first address'}"><i class="icon-building"></i><span>{l s='Add my first address'}</span></a></li>
{/if}
<li><a href="{$link->getPageLink('address', true)|escape:'html':'UTF-8'}" title="{l s='My address'}"><i class="icon-building"></i><span>{l s='My address'}</span></a></li>
<li><a href="{$link->getPageLink('history', true)|escape:'html':'UTF-8'}" title="{l s='Orders'}"><i class="icon-list-ol"></i><span>{l s='Order history and details'}</span></a></li>
{if $refundAllowed}
<li><a href="{$link->getPageLink('order-follow', true)|escape:'html':'UTF-8'}" title="{l s='Booking Refund Requests'}"><i class="icon-refresh"></i><span>{l s='Booking Refund Requests'}</span></a></li>
{/if}
<li><a href="{$link->getPageLink('order-slip', true)|escape:'html':'UTF-8'}" title="{l s='Credit slips'}"><i class="icon-file-o"></i><span>{l s='My credit slips'}</span></a></li>
<li><a href="{$link->getPageLink('addresses', true)|escape:'html':'UTF-8'}" title="{l s='Addresses'}"><i class="icon-building"></i><span>{l s='My addresses'}</span></a></li>
<li><a href="{$link->getPageLink('identity', true)|escape:'html':'UTF-8'}" title="{l s='Information'}"><i class="icon-user"></i><span>{l s='My personal information'}</span></a></li>
</ul>
</div>