开发者

Magento change database query collation

I have a Magento 1.5.1.0 installation, and some of the products in the catalog has swedish c开发者_运维技巧haracters at the start of the product name. This causes an incorrect sort when sorting by name. Ä and Å becomes A, and Ö becomes O.

This means the sorting will be like:

A
Å
Ä
B
[...]

This is because the database is using the collation utf8_general_ci. I've found you can override what collation MySQL uses when executing a query, but I just can not find a good way to get it into the Magento code. Should this perhaps be done on the Zend level?


Go to your \app\etc\local.xml, find default_setup section and add <initStatements> tag with your query there (or change if it is already present). So, it will look like:

<default_setup>
    <connection>
        <host><![CDATA[your_host]]></host>
        <username><![CDATA[user]]></username>
        <password><![CDATA[password]]></password>
        <dbname><![CDATA[db]]></dbname>
        <initStatements><![CDATA[SET NAMES 'utf8' COLLATE 'utf8_unicode_ci']]></initStatements>
        <model><![CDATA[mysql4]]></model>
        <type><![CDATA[pdo_mysql]]></type>
        <pdoType><![CDATA[]]></pdoType>
        <active>1</active>
    </connection>
</default_setup>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜