问题
Does anyone know how can you order alphabetically states when you are editing o creating a new customer address.
Thank you in advance
回答1:
I finally solved it by overriding the file State.php
Just create a new file inside /overrides/classes/State.php and paste this code:
<?php class State extends StateCore {
/**
* Get states by Country ID.
*
* @param int $idCountry Country ID
* @param bool $active true if the state must be active
*
* @return array|false|mysqli_result|PDOStatement|resource|null
*/
public static function getStatesByIdCountry($idCountry, $active = false)
{
if (empty($idCountry)) {
die(Tools::displayError());
}
return Db::getInstance()->executeS(
'SELECT *
FROM `' . _DB_PREFIX_ . 'state` s
WHERE s.`id_country` = ' . (int) $idCountry . ($active ? ' AND s.active = 1' : '') . '
ORDER BY `name` ASC'
);
}
}
It just adds ORDER BY name
ASC' to the SQL query, then it gets the states ordered alphabetically.
Best regards
来源:https://stackoverflow.com/questions/62771234/order-states-aphabetically-in-prestashop-1-7