服务报价 | 域名主机 | 网络营销 | 软件工具| [加入收藏]
 热线电话: #
当前位置: 主页 > php教程 > zencart教程 >

ZenCart首页指定显示某个分类下面的产品

时间:2016-01-16 17:48来源: 作者: 点击:
ZenCartt默认情况下首页显示的新进产品是随机获取所有最近添加的产品。有时候不想在所有的分类里面获取这些最新产品,而是指定在某些分类下面。分享一下这个修改方法。 首先打开

ZenCartt默认情况下首页显示的新进产品是随机获取所有最近添加的产品。有时候不想在所有的分类里面获取这些最新产品,而是指定在某些分类下面。分享一下这个修改方法。

首先打开includesmodulesnew_products.php 这个模块文件就是首页调用的新进产品模块。要想实现这个功能,只要修改$new_products_query 这个变量,这个是查询最新产品的SQL语句。

看下面这段代码:

 

if ( (($manufacturers_id > 0 && $_GET['filter_id'] == 0) || $_GET['music_genre_id'] > 0 || $_GET['record_company_id'] > 0) || (!isset($new_products_category_id) || $new_products_category_id == ’0′) ) {
$new_products_query = “select distinct p.products_id, p.products_image, p.products_tax_class_id, pd.products_name,
p.products_date_added, p.products_price, p.products_type, p.master_categories_id
from ” . TABLE_PRODUCTS . ” p, ” . TABLE_PRODUCTS_DESCRIPTION . ” pd
where p.products_id = pd.products_id
and pd.language_id = ‘” . (int)$_SESSION['languages_id'] . “‘
and p.products_status = 1 ” . $display_limit;
} else {
// get all products and cPaths in this subcat tree
$productsInCategory = zen_get_categories_products_list( (($manufacturers_id > 0 && $_GET['filter_id'] > 0) ? zen_get_generated_category_path_rev($_GET['filter_id']) : $cPath), false, true, 0, $display_limit);

if (is_array($productsInCategory) && sizeof($productsInCategory) > 0) {
// build products-list string to insert into SQL query
foreach($productsInCategory as $key => $value) {
$list_of_products .= $key . ‘, ‘;
}
$list_of_products = substr($list_of_products, 0, -2); // remove trailing comma

$new_products_query = “select distinct p.products_id, p.products_image, p.products_tax_class_id, pd.products_name,
p.products_date_added, p.products_price, p.products_type, p.master_categories_id
from ” . TABLE_PRODUCTS . ” p, ” . TABLE_PRODUCTS_DESCRIPTION . ” pd
where p.products_id = pd.products_id
and pd.language_id = ‘” . (int)$_SESSION['languages_id'] . “‘
and p.products_status = 1
and p.products_id in (” . $list_of_products . “)”;
}
}

修改成如下:

$filter_cate=”;

$cate_IDS=”22″;///要显示的分类ID,如果有父分类,请输入子分类的ID
if($this_is_home_page){
$filter_cate=” and p.master_categories_id in($cate_IDS) “;
}
if ( (($manufacturers_id > 0 && $_GET['filter_id'] == 0) || $_GET['music_genre_id'] > 0 || $_GET['record_company_id'] > 0) || (!isset($new_products_category_id) || $new_products_category_id == ’0′) ) {
$new_products_query = “select distinct p.products_id, p.products_image, p.products_tax_class_id, pd.products_name,
p.products_date_added, p.products_price, p.products_type, p.master_categories_id
from ” . TABLE_PRODUCTS . ” p, ” . TABLE_PRODUCTS_DESCRIPTION . ” pd
where p.products_id = pd.products_id
and pd.language_id = ‘” . (int)$_SESSION['languages_id'] . “‘
and p.products_status = 1 ” . $display_limit.$filter_cate;///添加到SQL语句后面
} else {
// get all products and cPaths in this subcat tree
$productsInCategory = zen_get_categories_products_list( (($manufacturers_id > 0 && $_GET['filter_id'] > 0) ? zen_get_generated_category_path_rev($_GET['filter_id']) : $cPath), false, true, 0, $display_limit);

if (is_array($productsInCategory) && sizeof($productsInCategory) > 0) {
// build products-list string to insert into SQL query
foreach($productsInCategory as $key => $value) {
$list_of_products .= $key . ‘, ‘;
}
$list_of_products = substr($list_of_products, 0, -2); // remove trailing comma

$new_products_query = “select distinct p.products_id, p.products_image, p.products_tax_class_id, pd.products_name,
p.products_date_added, p.products_price, p.products_type, p.master_categories_id
from ” . TABLE_PRODUCTS . ” p, ” . TABLE_PRODUCTS_DESCRIPTION . ” pd
where p.products_id = pd.products_id
and pd.language_id = ‘” . (int)$_SESSION['languages_id'] . “‘
and p.products_status = 1
and p.products_id in (” . $list_of_products . “)”.$filter_cate;///添加到SQL语句后面
}
}

(责任编辑:最模板)
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
栏目列表
热点内容