由于 Magento 安装中的属性数量,我遇到了 MySQL 中的行限制问题,因此我将扩展“Mage_Catalog_Model_Resource_Product_Flat_Indexer”类的扩展名放在一起,使用以下代码将字符限制重写为 64。
protected function _MySQLCharLimit()
{
if (!$this->_isFlatTableExists($store)) {
$sql = "CREATE TABLE {$tableNameQuote} (n";
foreach ( $columns as $field => $fieldProp ) {
if ( $fieldProp['type'] == "varchar(255)" )
$fieldProp['type'] = "varchar(64)";
$sql .= sprintf( " %s,n",
$this->_sqlColunmDefinition( $field, $fieldProp ) );
}
foreach ($addIndexes as $indexName => $indexProp) {
$sql .= sprintf(' ADD %s,',
$this->_sqlIndexDefinition( $indexName, $indexProp ) );
}
$sql = rtrim($sql, ",");
$sql = str_replace( "varchar(255)","varchar(64)",$sql );
$this->_getWriteAdapter()->query( $sql );
}
}
我从这里得到的http://www.sonassi.com/knowledge-base/magento-kb/mysql-limitations-on-the-flat-catalogue-in-magento/。
在尝试重新索引后,我注意到它把我送到了一个空白页面,当我点击返回时,“产品平面数据”索引卡在处理中。
我通过 SSH 从“shell”文件夹运行 indexer.php,它报告了这个错误:
PHP 致命错误:在第 296 行的 Mage/Catalog/Model/Product/Flat/Indexer.php 中的非对象上调用成员函数 reindexAll()
有没有人知道出了什么问题或我该如何纠正这个问题?谢谢。
编辑:完整代码
<?php
class GDModules_MySQLCharLimit_Catalog_Model_Resource_Product_Flat_Indexer extends Mage_Catalog_Model_Resource_Product_Flat_Indexer
{
public function mySQLCharLimit()
{
if (!$this->_isFlatTableExists($store)) {
$sql = "CREATE TABLE {$tableNameQuote} (n";
foreach ( $columns as $field => $fieldProp ) {
if ( $fieldProp['type'] == "varchar(255)" )
$fieldProp['type'] = "varchar(64)";
$sql .= sprintf( " %s,n",
$this->_sqlColunmDefinition( $field, $fieldProp ) );
}
foreach ($addIndexes as $indexName => $indexProp) {
$sql .= sprintf(' ADD %s,',
$this->_sqlIndexDefinition( $indexName, $indexProp ) );
}
$sql = rtrim($sql, ",");
$sql = str_replace( "varchar(255)","varchar(64)",$sql );
$this->_getWriteAdapter()->query( $sql );
}
}
}
XML
<?xml version="1.0" encoding="UTF-8"?>
<!-- The root node for Magento module configuration -->
<config>
<!--
The module's node contains basic
information about each Magento module
-->
<modules>
<!--
This must exactly match the namespace and module's folder
names, with directory separators replaced by underscores
-->
<GDModules_MySQLCharLimit>
<!-- The version of our module, starting at 0.0.1 -->
<version>0.0.1</version>
</GDModules_MySQLCharLimit>
</modules>
<!-- Configure our module's behaviour in the global scope -->
<global>
<!-- Defining models -->
<models>
<catalog_resource>
<rewrite>
<product_flat_indexer>GDModules_MySQLCharLimit_Catalog_Model_Resource_Product_Flat_Indexer</product_flat_indexer>
</rewrite>
</catalog_resource>
</models>
</global>
</config>