0
我一直在努力改變getProducts($data = array())
方法中的查詢。OpenCart - 從產品查詢中刪除一個包含子類別的類別
所以..在特定的控制器中,我添加了exclude_category_id => 65
,$data
數組,我將它傳遞給getProducts($data)
。
$data = array(
'sort' => 'p.date_added',
'order' => 'DESC',
'start' => 0,
'limit' => $setting['limit'],
'exclude_category_id' => 65
);
在public function getProducts($data = array())
model/catalog/product.php
我加入這個代碼:
if (!empty($data['filter_category_id'])) {
if (!empty($data['filter_sub_category'])) {
$sql .= " FROM " . DB_PREFIX . "category_path cp LEFT JOIN " . DB_PREFIX . "product_to_category p2c ON (cp.category_id = p2c.category_id)";
} else {
$sql .= " FROM " . DB_PREFIX . "product_to_category p2c";
}
if (!empty($data['filter_filter'])) {
$sql .= " LEFT JOIN " . DB_PREFIX . "product_filter pf ON (p2c.product_id = pf.product_id) LEFT JOIN " . DB_PREFIX . "product p ON (pf.product_id = p.product_id)";
} else {
$sql .= " LEFT JOIN " . DB_PREFIX . "product p ON (p2c.product_id = p.product_id)";
}
} else if(!empty($data['exclude_category_id'])){
// THIS ELSE IF IS ADDED BY ME
$sql .= " FROM " . DB_PREFIX . "product_to_category p2c";
$sql .= " LEFT JOIN " . DB_PREFIX . "product p ON (p2c.product_id = p.product_id)";
}else {
$sql .= " FROM " . DB_PREFIX . "product p";
}
更深這種方法我還補充說:
if(!empty($data['exclude_category_id'])){
$sql .= " AND p2c.category_id != '" . (int)$data['exclude_category_id'] . "'";
}
但是從類別產品ID = 65
仍然可見。任何人有任何想法如何做到這一點?
這適用於主要產品類別,但不適用於產品具有該主要類別的子類別 – rgwsk65 2014-10-30 12:28:03