显示每个类别的特殊产品,仅显示与该类别相关的产品
是否可以在每个类别中显示特殊产品,仅显示与该类别相关的产品?例如,如果类别是“诺基亚”,则显示仅限诺基亚使用的特价商品,并且不显示其他特价商品。显示每个类别的特殊产品,仅显示与该类别相关的产品
也适用于特色产品。
可能吗?如果可能的话,你能解释一下如何做到让初学者能理解它吗?我正在使用OpenCart 1.5.3.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 - - - -
Thankyou B-and-P,你给出了一个很棒的代码yar thankyou谢谢你这么多 – user2365268 2013-05-09 10:31:12
Thankyou B-and-P,它的工作很棒,并且可以在特色产品中将上面的内容分开。请告诉我,我是opencart的初学者。感谢您的帮助 – user2365268 2013-05-09 10:33:55
如果我解决了您的问题,请点击左边的复选标记接受我的答案。不要为你做所有的工作,我建议你自己尝试并使用我的示例到特色模块。这是学习的唯一途径。如果您遇到麻烦,请回到这里并发布您的代码。 – 2013-05-09 10:51:41
只是这需要我,这里是我的解决方案,需要修改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);
当然有可能。虽然我不确定这是一个初学者,但任务。在'catalog/controller/module/special.php'中,你需要检查当前页面是否是一个类别页面,然后得到它的类别id,然后运行一个循环来检查和过滤相关产品的产品。 – 2013-05-09 08:11:07