optimized the function getCustomers() to get the customers list for address creation
This commit is contained in:
@@ -296,16 +296,28 @@ class CustomerCore extends ObjectModel
|
||||
/**
|
||||
* Return customers list
|
||||
*
|
||||
* @param null|bool $only_active Returns only active customers when true
|
||||
* @param null|bool $only_active Returns customers by active status
|
||||
* @param null|bool $havingAddress Returns customers having | not having address
|
||||
* @param null|bool $deleted Returns customers by deleted status
|
||||
* @return array Customers
|
||||
*/
|
||||
public static function getCustomers($only_active = null)
|
||||
public static function getCustomers($only_active = null, $havingAddress = null, $deleted = 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';
|
||||
$sqlWhere = 'WHERE 1 '.Shop::addSqlRestriction(Shop::SHARE_CUSTOMER).
|
||||
(!is_null($only_active) ? ' AND c.`active` = '.(int) $only_active: ' ' ).
|
||||
(!is_null($deleted) ? ' AND c.`deleted` = '.(int) $deleted : ' ');
|
||||
$sqlOrderBY = 'ORDER BY c.`id_customer` ASC';
|
||||
|
||||
if (!is_null($havingAddress)) {
|
||||
$sqlFrom .= ' LEFT JOIN `'._DB_PREFIX_.'address` a
|
||||
ON a.`id_customer` = c.`id_customer` AND a.`deleted`=0';
|
||||
$sqlWhere .= (($havingAddress) ? ' AND a.`id_address` !='.(int) 0: ' AND ISNULL(a.`id_address`)');
|
||||
}
|
||||
|
||||
$sql = $sqlSelect .' '. $sqlFrom.' '. $sqlWhere.' '.$sqlOrderBY;
|
||||
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
|
||||
}
|
||||
|
||||
@@ -952,18 +964,4 @@ class CustomerCore extends ObjectModel
|
||||
return parent::getWebserviceObjectList($sql_join, $sql_filter, $sql_sort, $sql_limit);
|
||||
}
|
||||
|
||||
public static function getAllCustomers($withAddress = null, $active = null, $deleted = null)
|
||||
{
|
||||
return Db::getInstance()->executeS(
|
||||
'SELECT c.`firstname`, c.`lastname`, c.`id_customer`, c.`email`, a.`id_address`
|
||||
FROM `'._DB_PREFIX_.'customer` c
|
||||
LEFT JOIN `'._DB_PREFIX_.'address` a
|
||||
ON a.`id_customer` = c.`id_customer` AND a.`deleted`=0
|
||||
WHERE 1 '.
|
||||
(!is_null($deleted) ? ' AND c.`deleted` = '.(int) $deleted : ' ').
|
||||
(!is_null($active) ? ' AND c.`active` = '.(int) $active: ' ' ).
|
||||
(!is_null($withAddress) ? (($withAddress) ? ' AND a.`id_address` !='.(int) 0: ' AND ISNULL(a.`id_address`)'): ' ' )
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ class AdminAddressesControllerCore extends AdminController
|
||||
|
||||
public function renderForm()
|
||||
{
|
||||
$customerSelectField =array(
|
||||
$customerField =array(
|
||||
'type' => 'text_customer',
|
||||
'label' => $this->l('Customer'),
|
||||
'name' => 'id_customer',
|
||||
@@ -120,14 +120,15 @@ class AdminAddressesControllerCore extends AdminController
|
||||
);
|
||||
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::getAllCustomers(false, null, 0));
|
||||
$customerSelectField = array(
|
||||
$customerEmails = array_merge($customerEmails, Customer::getCustomers(null, false, 0));
|
||||
$customerField = array(
|
||||
'type' => 'select',
|
||||
'label' => $this->l('Customer'),
|
||||
'name' => 'id_customer',
|
||||
@@ -146,7 +147,7 @@ class AdminAddressesControllerCore extends AdminController
|
||||
'icon' => 'icon-envelope-alt'
|
||||
),
|
||||
'input' => array(
|
||||
$customerSelectField,
|
||||
$customerField,
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Identification Number'),
|
||||
@@ -214,7 +215,7 @@ class AdminAddressesControllerCore extends AdminController
|
||||
}
|
||||
|
||||
$this->tpl_form_vars = array(
|
||||
'customer' => (isset($customer) && $this->object->id) ? $customer : null,
|
||||
'customer' => (isset($customer) && ($this->object->id || Tools::getValue('liteDisplaying'))) ? $customer : null,
|
||||
'tokenCustomer' => isset($token_customer) ? $token_customer : null
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user