首页 > 解决方案 > 在 Prestashop 1.7 中按顺序排列状态

问题描述

有谁知道在编辑或创建新客户地址时如何按字母顺序排列状态。

先感谢您

标签: prestashop-1.7

解决方案


我终于通过覆盖文件 State.php 解决了它

只需在 /overrides/classes/State.php 中创建一个新文件并粘贴以下代码:

<?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'
        );
    }
}

它只是将ORDER BY nameASC'添加到 SQL 查询中,然后按字母顺序获取状态。

此致


推荐阅读