php - OpenCart - remove one category with subcategories from product query -
i've been working alter query in getproducts($data = array())
method.
so.. in specific controller added exclude_category_id => 65
in $data
array, pass getproducts($data)
.
$data = array( 'sort' => 'p.date_added', 'order' => 'desc', 'start' => 0, 'limit' => $setting['limit'], 'exclude_category_id' => 65 );
in model/catalog/product.php
in public function getproducts($data = array())
added code:
if (!empty($data['filter_category_id'])) { if (!empty($data['filter_sub_category'])) { $sql .= " " . db_prefix . "category_path cp left bring together " . db_prefix . "product_to_category p2c on (cp.category_id = p2c.category_id)"; } else { $sql .= " " . db_prefix . "product_to_category p2c"; } if (!empty($data['filter_filter'])) { $sql .= " left bring together " . db_prefix . "product_filter pf on (p2c.product_id = pf.product_id) left bring together " . db_prefix . "product p on (pf.product_id = p.product_id)"; } else { $sql .= " left bring together " . db_prefix . "product p on (p2c.product_id = p.product_id)"; } } else if(!empty($data['exclude_category_id'])){ // else if added me $sql .= " " . db_prefix . "product_to_category p2c"; $sql .= " left bring together " . db_prefix . "product p on (p2c.product_id = p.product_id)"; }else { $sql .= " " . db_prefix . "product p"; }
deeper in method added also:
if(!empty($data['exclude_category_id'])){ $sql .= " , p2c.category_id != '" . (int)$data['exclude_category_id'] . "'"; }
but products category id = 65
still visible. have thought how that?
i solved problem.
i added @ origin of method in model/catalog/product.php
:
public function getproducts($data = array()) { $exclude_ids; if(!empty($data['exclude_category_id'])){ $exclude_ids = array($data['exclude_category_id']); $this->load->model('catalog/category'); $results = $this->model_catalog_category->getcategories($data['exclude_category_id']); if($results){ foreach($results $result){ $exclude_ids[] = $result['category_id']; } } } if(!empty($exclude_ids)){ $t = $exclude_ids; $exclude_ids = ""; foreach($t $id){ $exclude_ids .= $id.', '; } $exclude_ids = substr($exclude_ids, 0, -2); }
and deeper in function:
if (!empty($data['filter_category_id'])) { if (!empty($data['filter_sub_category'])) { $sql .= " " . db_prefix . "category_path cp left bring together " . db_prefix . "product_to_category p2c on (cp.category_id = p2c.category_id)"; } else { $sql .= " " . db_prefix . "product_to_category p2c"; } if (!empty($data['filter_filter'])) { $sql .= " left bring together " . db_prefix . "product_filter pf on (p2c.product_id = pf.product_id) left bring together " . db_prefix . "product p on (pf.product_id = p.product_id)"; } else { $sql .= " left bring together " . db_prefix . "product p on (p2c.product_id = p.product_id)"; } } else if(!empty($data['exclude_category_id'])){ /*********** added else if *********/ $sql .= " " . db_prefix . "product_to_category p2c"; $sql .= " left bring together " . db_prefix . "product p on (p2c.product_id = p.product_id)"; }else { $sql .= " " . db_prefix . "product p"; }
and little deeper:
if(!empty($data['exclude_category_id'])){ $sql .= " , p2c.category_id not in (".$exclude_ids.")"; }
sorry chaotic solution, time key in project.
php mysql opencart
No comments:
Post a Comment