我修改了magento的高级搜索 app \ code \ core \ Mage \ CatalogSearch \ Model \ Mysql4 以使用一些自定义条件,因为我希望搜索使用AND代替某些属性IN < / p>
但是,它没有返回任何东西。 这是我修改过的查询:
if(in_array($value,$cSizeArray) && isset($_GET['condom_size'])){
$select->where("{$tableAlias}.`value` IN(?)", $value);
}elseif(in_array($value,$lSizeArray) && isset($_GET['lubepack'])){
$select->where("{$tableAlias}.`value` IN(?)", $value);
}else{
if($tableAlias == 'ast_types' || $tableAlias== 'ast_lubetype'){
$condition = "( ";
foreach($value as $v){
$condition.=" {$tableAlias}.`value`= $v AND";
}
$condition = substr($condition,0,-3);
$condition .= " ) ";
$select->where($condition);
}else{
$select->where("{$tableAlias}.`value` IN(?)", $value);
}
}
这是我使用echo $select
得到的查询:
`SELECT DISTINCT `e`.*, `price_index`.`price`, `price_index`.`tax_class_id`, `price_index`.`final_price`, IF(`price_index`.`tier_price`, LEAST(`price_index`.`min_price`, `price_index`.`tier_price`), `price_index`.`min_price`) AS `minimal_price`, `price_index`.`min_price`, `price_index`.`max_price`, `price_index`.`tier_price`, `cat_index`.`position` AS `cat_index_position` FROM `catalog_product_entity` AS `e`
INNER JOIN `catalog_product_index_price` AS `price_index` ON price_index.entity_id = e.entity_id AND price_index.website_id = '1' AND price_index.customer_group_id = 0
INNER JOIN `catalog_category_product_index` AS `cat_index` ON cat_index.product_id=e.entity_id AND cat_index.store_id='3' AND cat_index.visibility IN(3, 4) AND cat_index.category_id='2'
INNER JOIN `catalog_product_index_eav` AS `ast_types` ON e.entity_id=ast_types.entity_id AND ast_types.attribute_id=150 AND ast_types.store_id=3
INNER JOIN `catalog_product_index_eav` AS `ast_condom_size` ON e.entity_id=ast_condom_size.entity_id AND ast_condom_size.attribute_id=151 AND ast_condom_size.store_id=3 WHERE (( ast_types.value= 131 AND ast_types.value= 135 ) ) AND (ast_condom_size.`value` IN('141', '140'))`
新修改的查询:
SELECT DISTINCT `e`.*, `price_index`.`price`, `price_index`.`tax_class_id`, `price_index`.`final_price`, IF(`price_index`.`tier_price`, LEAST(`price_index`.`min_price`, `price_index`.`tier_price`), `price_index`.`min_price`) AS `minimal_price`, `price_index`.`min_price`, `price_index`.`max_price`, `price_index`.`tier_price`, `cat_index`.`position` AS `cat_index_position` FROM `catalog_product_entity` AS `e`
INNER JOIN `catalog_product_index_price` AS `price_index` ON price_index.entity_id = e.entity_id AND price_index.website_id = '1' AND price_index.customer_group_id = 0
INNER JOIN `catalog_category_product_index` AS `cat_index` ON cat_index.product_id=e.entity_id AND cat_index.store_id='3' AND cat_index.visibility IN(3, 4) AND cat_index.category_id='2'
INNER JOIN `catalog_product_index_eav` AS `ast_types` ON e.entity_id=ast_types.entity_id AND ast_types.attribute_id=150 AND ast_types.store_id=3
INNER JOIN `catalog_product_index_eav` AS `ast_condom_size` ON e.entity_id=ast_condom_size.entity_id AND ast_condom_size.attribute_id=151 AND ast_condom_size.store_id=3 WHERE (( ast_types.`value`= 135 OR ast_types.`value`= 132 OR ast_types.`value`= 131 ) ) AND (ast_condom_size.`value` IN('141', '140')) GROUP BY sku HAVING COUNT(*)=3
对方法可能出错的任何想法......
答案 0 :(得分:2)
WHERE (( ast_types.value= 131 AND ast_types.value= 135 ) )
您要求的值同时为131和135。这永远不会成立,因此您的结果集将为空。