2014-05-16 16 views
0

검색에 불필요한 테이블을 추가하고 나는 오토바이를 다른 플러그인을 추가하는 플러그인을 복제. 두 플러그인은 잘 작동하지만 검색시 치명적인 오류가 발생합니다. 어떻게 든 그들은 검색시 다른 불필요한 테이블을 추가합니다 (플러그인을 디버깅 할 때 테이블을 봅니다). 예를 들어 자동차 카테고리를 검색 할 때 검색어가 오토바이 표를 추가합니다. 자동차 테이블이 아닌 자동차 테이블을 추가합니다. 그렇지 않으면 오토바이 카테고리를 검색 할 때 쿼리가 자동차 테이블을 추가합니다. 그것은 나를 혼란스럽게 만든다. 결과는 결코 바뀌지 않습니다. 이거 버그 야? 나는이 문제를 해결Osclass 플러그인 내가 <a href="http://market.osclass.org/plugins/cars-attributes_7" rel="nofollow">cars plugin</a> 사용

답변

0

Osclass 3.3.2을 사용하고 있습니다. 내 솔루션이 깨끗한 아니지만 그것은 나를 위해 작동합니다. 내가에/Search.php 파일을 편집해야 OC-포함/osclass/모델/디렉토리. addTable과 addConditions의 두 함수를 복제했습니다. 카테고리 ID 인 새 매개 변수를 추가했습니다. 그래서 수 있습니다 : addTableNew ($ 테이블, $의 CATID) 및 addConditionsNew ($ 조건, $ 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); 

} 

}

관련 문제