如何实现ecshop中商品分类页分类搜索的功能
1个回答
展开全部
需要修改的文件category.php
goods_list.lbi common.js
1、读出当前分类的所有下级分类
$chlidren_category =
$GLOBALS['db']->getALl('SELECT cat_id,cat_name FROM
' . $GLOBALS['ecs']->table('category') ." WHERE
parent_id = '$cat_id' and is_show=1");
$category_id_all =
array('all'=>array('cat_id'
=> $cat_id,
'cat_name'
=> 'all category',
'show'
=>1
)
);
foreach($chlidren_category as $key=>$value)
{
if($value['cat_id']==$cat_id)
{
$chlidren_category[$key]['show']=1;$category_id_all['show']=0;continue;
}
else $chlidren_category[$key]['show']=0;
}
$category_list = array_merge($category_id_all,
$chlidren_category);
$smarty->assign('category_list_all',
$category_list);
2、修改goods_list.lbi文件, <form
method="GET" name="listform">下面加入循环出分类的模板代码
<!--{foreach from=$category_list_all
item=cat_list}-->
<a href="javascript:;"
onClick="javascript:category_change({$cat_list.cat_id})">{$cat_list.cat_name}</a
<!--{/foreach}-->
3、common.js中加入js脚本
function category_change(cat_id)
{
document.getElementByIdx_x('category_id').value = cat_id;
setTimeout(doSubmit, 0);
function
doSubmit() {document.forms['listform'].submit();}
}
goods_list.lbi common.js
1、读出当前分类的所有下级分类
$chlidren_category =
$GLOBALS['db']->getALl('SELECT cat_id,cat_name FROM
' . $GLOBALS['ecs']->table('category') ." WHERE
parent_id = '$cat_id' and is_show=1");
$category_id_all =
array('all'=>array('cat_id'
=> $cat_id,
'cat_name'
=> 'all category',
'show'
=>1
)
);
foreach($chlidren_category as $key=>$value)
{
if($value['cat_id']==$cat_id)
{
$chlidren_category[$key]['show']=1;$category_id_all['show']=0;continue;
}
else $chlidren_category[$key]['show']=0;
}
$category_list = array_merge($category_id_all,
$chlidren_category);
$smarty->assign('category_list_all',
$category_list);
2、修改goods_list.lbi文件, <form
method="GET" name="listform">下面加入循环出分类的模板代码
<!--{foreach from=$category_list_all
item=cat_list}-->
<a href="javascript:;"
onClick="javascript:category_change({$cat_list.cat_id})">{$cat_list.cat_name}</a
<!--{/foreach}-->
3、common.js中加入js脚本
function category_change(cat_id)
{
document.getElementByIdx_x('category_id').value = cat_id;
setTimeout(doSubmit, 0);
function
doSubmit() {document.forms['listform'].submit();}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询