是否可以在每个类别中显示特殊产品,仅显示与该类别相关的产品?例如,如果类别为“诺基亚”,则显示仅在诺基亚下的特价,并且不显示其他特价。
同样适用于特色产品。
有可能吗?如果可能的话,请您解释一下如何做到这一点,以便初学者能够理解它?我正在使用OpenCart 1.5.3.1。
答案 0 :(得分:1)
好的,这是让你入门的东西。我正在使用Opencart 1.5.5.1。
在catalog/controller/module/special.php
中找到这一行到最后:
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/special.tpl')) {
之前,添加此代码(我希望我的评论足够清楚):
// filter specials by current category code - - - - - - -
/* check wether current page is a category page (i.e. has 'path' var) */
if (isset($this->request->get['path'])) {
/* get category ID from path (last number) */
$parts = explode('_', (string)$this->request->get['path']);
$category_id = (int)array_pop($parts);
/* loop through products */
foreach ($this->data['products'] as $k => $item){
/* check whether this product is assigned to current category */
$sql = "SELECT * FROM " . DB_PREFIX ."product_to_category WHERE product_id = ". $item['product_id']. " AND category_id = ".$category_id;
$query = $this->db->query($sql);
/* if no match found, remove this item */
if (count($query->rows) == 0){
unset ($this->data['products'][$k]);
}
}
}
// end of filter specials by current category code - - - -
答案 1 :(得分:0)
我自己需要这个,这是我的解决方案,您需要修改catalog/model/catalog/product.php
和catalog/controller/module/special.php
。我建议VQMod这样做:
在product.php
替换
$sql = "SELECT DISTINCT ps.product_id, (SELECT AVG(rating) FROM " . DB_PREFIX . "review r1 WHERE r1.product_id = ps.product_id AND r1.status = '1' GROUP BY r1.product_id) AS rating FROM " . DB_PREFIX . "product_special ps LEFT JOIN " . DB_PREFIX . "product p ON (ps.product_id = p.product_id) LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ps.customer_group_id = '" . (int)$customer_group_id . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) GROUP BY ps.product_id";
使用:
$sql = "SELECT DISTINCT ps.product_id, (SELECT AVG(rating) FROM " . DB_PREFIX . "review r1 WHERE r1.product_id = ps.product_id AND r1.status = '1' GROUP BY r1.product_id) AS rating".(isset($data['category_id']) ? ", (SELECT category_id FROM oc_product_to_category WHERE product_id = ps.product_id AND category_id = '".$data['category_id']."' GROUP BY category_id) as category" : "")." FROM " . DB_PREFIX . "product_special ps LEFT JOIN " . DB_PREFIX . "product p ON (ps.product_id = p.product_id) LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ps.customer_group_id = '" . (int)$customer_group_id . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) GROUP BY ps.product_id".(isset($data['category_id']) ? ",category HAVING category='".$data['category_id']."'" : "");
并在special.php:
添加
if (isset($this->request->get['path'])) {
$parts = explode('_', (string)$this->request->get['path']);
$data['category_id'] = (int)array_pop($parts);
}
前
$results = $this->model_catalog_product->getProductSpecials($data);