Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed: The email selection process while creating new address for the customer and back button for the AdminAddressController. #1045

Merged
merged 9 commits into from
Jul 16, 2024
Merged
Original file line number Diff line number Diff line change
@@ -29,31 +29,29 @@
{if $input.name == 'vat_number'}
<div id="vat_area" style="display: visible">
{/if}

{if $input.type == 'text_customer' && !isset($customer)}
<label class="control-label col-lg-3 required" for="email">{l s='Customer email'}</label>
{else}
{$smarty.block.parent}
{/if}
{$smarty.block.parent}
{/block}

{block name="field"}
{block name="input"}
{if $input.type == 'text_customer'}
{if isset($customer)}
<div class="col-lg-9">
<a class="btn btn-default" href="?tab=AdminCustomers&amp;id_customer={$customer->id|intval}&amp;viewcustomer&amp;token={$tokenCustomer}">
<i class="icon-eye-open"></i> {$customer->lastname} {$customer->firstname} ({$customer->email})
</a>
</div>
<a class="btn btn-default" href="?tab=AdminCustomers&amp;id_customer={$customer->id|intval}&amp;viewcustomer&amp;token={$tokenCustomer}">
<i class="icon-eye-open"></i> {$customer->lastname} {$customer->firstname} ({$customer->email})
</a>
<input type="hidden" name="id_customer" value="{$customer->id}" />
<input type="hidden" name="email" value="{$customer->email}" />
{else}
<script type="text/javascript">
$('input[name=email]').live('blur', function(e)
{/if}
{else if $input.type == 'select' && $input.name == 'id_customer'}
{$smarty.block.parent}
<input type="hidden" name="email" id="email" value="">
<script type="text/javascript">
$('#id_customer').on('change', function(e)
{
var email = $(this).val();
if (email.length > 5)
{
var id_customer = parseInt($(this).val());
$('#email').val('');
if (!isNaN(id_customer)) {
var email = $(this).find('[value="'+id_customer+'"]').text();
$('#email').val(email);
var data = {};
data.email = email;
data.token = "{$token|escape:'html':'UTF-8'}";
@@ -66,31 +64,29 @@
data: data,
dataType: 'json',
async : true,
success: function(msg)
{
if (msg)
{
success: function(msg) {
if (msg) {
var infos = msg.infos.replace("\\'", "'").split('_');

$('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]);
} else {
resetCustomerRelatedAddressFields();
}
},
error: function(msg)
{
}
});
} else {
resetCustomerRelatedAddressFields();
}
});
</script>

<div class="col-lg-4">
<input type="hidden" name="id_customer" value="{$fields_value[$input.name]}" />
<input type="email" id="email" name="email" value="{$fields_value[$input.name]|escape:'html':'UTF-8'}"/>
</div>
{/if}
function resetCustomerRelatedAddressFields() {
$('input[name=firstname]').val('');
$('input[name=lastname]').val('');
$('input[name=company]').val('');
$('input[name=id_customer]').val('');
}
</script>
{else}
{$smarty.block.parent}
{/if}
35 changes: 26 additions & 9 deletions classes/Customer.php
Original file line number Diff line number Diff line change
@@ -294,21 +294,37 @@ public function delete()
}

/**
* Return customers list
* Returns a list of customers.
*
* @param null|bool $only_active Returns only active customers when true
* @return array Customers
* @param null|bool $active Optional. Filter customers by their active status. If null, no filter is applied.
* @param null|bool $deleted Optional. Filter customers by their deleted status. If null, no filter is applied.
* @param null|bool $havingAddress Optional. Filter customers having|not having address. If true, only customers having an address are returned.
* If false, only customers without an address are returned. If null, no filter is applied.
* @return array List of customers matching the specified criteria.
*/
public static function getCustomers($only_active = null)
public static function getCustomers($active = null, $deleted = null, $havingAddress = null)
{
$sql = 'SELECT `id_customer`, `email`, `firstname`, `lastname`
FROM `'._DB_PREFIX_.'customer`
WHERE 1 '.Shop::addSqlRestriction(Shop::SHARE_CUSTOMER).
($only_active ? ' AND `active` = 1' : '').'
ORDER BY `id_customer` ASC';
$sqlSelect = 'SELECT c.`id_customer`, c.`email`, c.`firstname`, c.`lastname`';
$sqlFrom = 'FROM `'._DB_PREFIX_.'customer` c';
$sqlJoin = '';
$sqlWhere = 'WHERE 1 '.Shop::addSqlRestriction(Shop::SHARE_CUSTOMER).
(!is_null($active) ? ' AND c.`active` = '.(int) $active: ' ' ).
(!is_null($deleted) ? ' AND c.`deleted` = '.(int) $deleted : ' ');
$sqlOrderBy = 'ORDER BY c.`id_customer` ASC';
$sqlGroupBy = 'GROUP BY c.`id_customer`';

if (!is_null($havingAddress)) {
$sqlJoin .= ' LEFT JOIN `'._DB_PREFIX_.'address` a
ON a.`id_customer` = c.`id_customer` AND a.`deleted`=0';
$sqlWhere .= (($havingAddress) ? ' AND a.`id_address` IS NOT NULL': ' AND a.`id_address` IS NULL');
}

$sql = $sqlSelect .' '. $sqlFrom.' '.$sqlJoin.' '.$sqlWhere.' '.$sqlGroupBy.' '.$sqlOrderBy;

return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
}


/**
* Return customer instance from its e-mail (optionnaly check password)
*
@@ -951,4 +967,5 @@ public function getWebserviceObjectList($sql_join, $sql_filter, $sql_sort, $sql_
$sql_filter .= Shop::addSqlRestriction(Shop::SHARE_CUSTOMER, 'main');
return parent::getWebserviceObjectList($sql_join, $sql_filter, $sql_sort, $sql_limit);
}

}
44 changes: 34 additions & 10 deletions controllers/admin/AdminAddressesController.php
Original file line number Diff line number Diff line change
@@ -112,18 +112,43 @@ public function initPageHeaderToolbar()

public function renderForm()
{
$customerField =array(
'type' => 'text_customer',
'label' => $this->l('Customer'),
'name' => 'id_customer',
'required' => false,
);
if ($this->loadObject(true)
&& !$this->object->id
&& !Tools::getValue('liteDisplaying')
) {
$customerEmails = array(array(
'email' => $this->l('Select Customer'),
'id_customer' => 0,
'id_address'=> 0
));
$customerEmails = array_merge($customerEmails, Customer::getCustomers(null, 0, 0));
$customerField = array(
'type' => 'select',
'label' => $this->l('Customer'),
'name' => 'id_customer',
'required' => true,
'class' => 'chosen',
'options' => array(
'query' => $customerEmails,
'id' => 'id_customer',
'name' => 'email'
),
);
}

$this->fields_form = array(
'legend' => array(
'title' => $this->l('Addresses'),
'icon' => 'icon-envelope-alt'
),
'input' => array(
array(
'type' => 'text_customer',
'label' => $this->l('Customer'),
'name' => 'id_customer',
'required' => false,
),
$customerField,
array(
'type' => 'text',
'label' => $this->l('Identification Number'),
@@ -191,9 +216,8 @@ public function renderForm()
}

$this->tpl_form_vars = array(
'customer' => isset($customer) ? $customer : null,
'tokenCustomer' => isset($token_customer) ? $token_customer : null,
'back_url' => urldecode(Tools::getValue('back'))
'customer' => (isset($customer) && ($this->object->id || Tools::getValue('liteDisplaying'))) ? $customer : null,
'tokenCustomer' => isset($token_customer) ? $token_customer : null
);

// Order address fields depending on country format
@@ -503,7 +527,7 @@ protected function processAddressFormat()
return $out;
}

/**
/**
* Method called when an ajax request is made
* @see AdminController::postProcess()
*/