Order States aphabetically in Prestashop 1.7

▼魔方 西西 提交于 2021-01-07 06:26:36

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!