Jump to content

Front end - addresses list alphabetical order


marrac

Recommended Posts

Hello.

It´s possible please to reorder the addresses list alphabetically and not by id?

I found this code in customer.php but I don't know where to add ORDER BY name to sort the addresses alphabetically:

public function getAddresses($id_lang)
    {
        $share_order = (bool)Context::getContext()->shop->getGroup()->share_order;
        $cache_id = 'Customer::getAddresses'.(int)$this->id.'-'.(int)$id_lang.'-'.$share_order;
        if (!Cache::isStored($cache_id)) {
            $sql = 'SELECT DISTINCT a.*, cl.`name` AS country, s.name AS state, s.iso_code AS state_iso
                    FROM `'._DB_PREFIX_.'address` a
                    LEFT JOIN `'._DB_PREFIX_.'country` c ON (a.`id_country` = c.`id_country`)
                    LEFT JOIN `'._DB_PREFIX_.'country_lang` cl ON (c.`id_country` = cl.`id_country`)
                    LEFT JOIN `'._DB_PREFIX_.'state` s ON (s.`id_state` = a.`id_state`)
                    
                    '.($share_order ? '' : Shop::addSqlAssociation('country', 'c')).'
                    WHERE `id_lang` = '.(int)$id_lang.' AND `id_customer` = '.(int)$this->id.' AND a.`deleted` = 0';
                

            $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
            Cache::store($cache_id, $result);
            return $result;
        }
        return Cache::retrieve($cache_id);
    }

Prestashop 1.6.1.12

Thanks for help.

Link to comment
Share on other sites

Quote

ORDER BY name to sort the addresses alphabetically ?

When you look in the database and in the ps_address table, there are several columns.
You choose according to which you want to sort the addresses.
For example, you want to sort addresses by alias name.
The code will be: (ORDER BY a.alias ASC)

 public function getAddresses($id_lang)
 {
        $share_order = (bool)Context::getContext()->shop->getGroup()->share_order;
        $cache_id = 'Customer::getAddresses'.(int)$this->id.'-'.(int)$id_lang.'-'.$share_order;
        if (!Cache::isStored($cache_id)) {
            $sql = 'SELECT DISTINCT a.*, cl.`name` AS country, s.name AS state, s.iso_code AS state_iso
                    FROM `'._DB_PREFIX_.'address` a
                    LEFT JOIN `'._DB_PREFIX_.'country` c ON (a.`id_country` = c.`id_country`)
                    LEFT JOIN `'._DB_PREFIX_.'country_lang` cl ON (c.`id_country` = cl.`id_country`)
                    LEFT JOIN `'._DB_PREFIX_.'state` s ON (s.`id_state` = a.`id_state`)
                    
                    '.($share_order ? '' : Shop::addSqlAssociation('country', 'c')).'
                    WHERE `id_lang` = '.(int)$id_lang.' AND `id_customer` = '.(int)$this->id.' AND a.`deleted` = 0 ORDER BY a.alias ASC';
                

            $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
            Cache::store($cache_id, $result);
            return $result;
        }
        return Cache::retrieve($cache_id);
} 

 

Edited by Guest (see edit history)
Link to comment
Share on other sites

56 minutes ago, Guest said:

When you look in the database and in the ps_address table, there are several columns.
You choose according to which you want to sort the addresses.
For example, you want to sort addresses by alias name.
The code will be: (ORDER BY a.alias ASC)


 public function getAddresses($id_lang)
 {
        $share_order = (bool)Context::getContext()->shop->getGroup()->share_order;
        $cache_id = 'Customer::getAddresses'.(int)$this->id.'-'.(int)$id_lang.'-'.$share_order;
        if (!Cache::isStored($cache_id)) {
            $sql = 'SELECT DISTINCT a.*, cl.`name` AS country, s.name AS state, s.iso_code AS state_iso
                    FROM `'._DB_PREFIX_.'address` a
                    LEFT JOIN `'._DB_PREFIX_.'country` c ON (a.`id_country` = c.`id_country`)
                    LEFT JOIN `'._DB_PREFIX_.'country_lang` cl ON (c.`id_country` = cl.`id_country`)
                    LEFT JOIN `'._DB_PREFIX_.'state` s ON (s.`id_state` = a.`id_state`)
                    
                    '.($share_order ? '' : Shop::addSqlAssociation('country', 'c')).'
                    WHERE `id_lang` = '.(int)$id_lang.' AND `id_customer` = '.(int)$this->id.' AND a.`deleted` = 0 ORDER BY a.alias ASC';
                

            $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
            Cache::store($cache_id, $result);
            return $result;
        }
        return Cache::retrieve($cache_id);
} 

 

Dobry den.

Dekuju vam mnohokrat za pomoc, ono to funguje. A ja se s tim mordoval 2 dny bez vysledku.

Jde to nejak upravit aby to bylo serazene i v sloupci Fakturacni adresa? Tam je zo serazene obracene.

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...