0

我使用汽车插件并复制该插件以添加另一个插件,摩托车。这两个插件运行良好,但搜索时出现致命错误。不知何故,他们在搜索时添加了另一个不需要的表(我在调试插件时看到了这些表)。例如,当我搜索汽车类别时,查询添加摩托车表。我只是添加汽车表而不是摩托车表。否则当我搜索摩托车类别时,查询添加汽车表。这让我很困惑。结果永远不会正确。这是一个错误吗?我正在使用 Osclass 3.3.2

4

1 回答 1

0

我解决了这个问题。可能是我的解决方案不干净,但对我有用。我必须在 /oc-includes/osclass/model/ 目录中编辑 Search.php 文件。我复制了两个函数,addTable 和 addConditions。但我添加了一个新参数,即类别 ID。所以它将是: addTableNew($tables,$catID) 和 addConditionsNew($conditions,$catID)

public function addTableNew($tables,$catID)
    {
        if(is_array($tables)) {
            foreach($tables as $table) {
                $table = trim($table);
                if($table!='' && in_array($catID, $this->categories)) {
                    $this->tables[] = $table;
                }
            }
        } else {
            $tables = trim($tables);
            if($tables!='' && in_array($catID, $this->categories)) {
                $this->tables[] = $tables;
            }
        }
    }

public function addConditionsNew($conditions,$catID)
    {
        if(is_array($conditions)) {
            foreach($conditions as $condition) {
                $condition = trim($condition);
                if($condition!='') {
                    if(in_array($catID, $this->categories)) {
                        $this->conditions[] = $condition;
                    }
                }
            }
        } else {
            $conditions = trim($conditions);
            if($conditions!='') {
                if(in_array($catID, $this->categories)) {
                    $this->conditions[] = $conditions;
                }
            }
        }
    }

然后在每个插件目录上的 index.php 文件中。我更改了 cars_search_conditions 函数和 motorbikes_search_conditions 函数。

function cars_search_conditions($params) {
// we need conditions and search tables (only if we're using our custom tables)
$cats = ModelCars::newInstance()->getCategoryId('Cars');    //-->search the category id in the database
$catID = $cats['fk_i_category_id'];
$has_conditions = false ;
foreach($params as $key => $value) {
    // we may want to have param-specific searches
    switch($key) {
        case 'make':
            if( is_numeric($value) ) {
                Search::newInstance()->addConditionsNew(sprintf("%st_item_car_attr.fk_i_make_id = %d", DB_TABLE_PREFIX, $value),$catID);
                $has_conditions = true;
            }
        break;
        //others search param
    }
}

// Only if we have some values at the params we add our table and link with the ID of the item.
if($has_conditions) {
    Search::newInstance()->addConditionsNew(sprintf("%st_item.pk_i_id = %st_item_car_attr.fk_i_item_id ", DB_TABLE_PREFIX, DB_TABLE_PREFIX),$catID);
    Search::newInstance()->addTableNew(sprintf("%st_item_car_attr", DB_TABLE_PREFIX),$catID);
}

}

function motorbikes_search_conditions($params) {
// we need conditions and search tables (only if we're using our custom tables)fk_i_category_id
$cats = ModelMotorBikes::newInstance()->getCategoryId('Motorbikes');
$catID = $cats['fk_i_category_id'];
$has_conditions = false ;
foreach($params as $key => $value) {
    // we may want to have param-specific searches
    switch($key) {
        case 'make':
            if( is_numeric($value) ) {
                Search::newInstance()->addConditionsNew(sprintf("%st_item_motorbike_attr.fk_i_motorbike_make_id = %d", DB_TABLE_PREFIX, $value),$catID);
                $has_conditions = true;
            }
        break;
        //others search param
    }
}

// Only if we have some values at the params we add our table and link with the ID of the item.
if($has_conditions) {
    Search::newInstance()->addConditionsNew(sprintf("%st_item.pk_i_id = %st_item_motorbike_attr.fk_i_motorbike_item_id ", DB_TABLE_PREFIX, DB_TABLE_PREFIX),$catID);
    Search::newInstance()->addTableNew(sprintf("%st_item_motorbike_attr", DB_TABLE_PREFIX),$catID);

}

}

于 2014-05-17T04:17:51.443 回答