ecshop ecs_template 解释 作用,数据字段
作用: 用于某个模板的个性化设置,例如首页分类显示 哪几个分类
搜索
结果
使用方法
assign_dynamic('index');
$smarty->assign('cat_goods',$smarty->_var['cat_goods_1']);
$smarty->assign('goods_cat',$smarty->_var['goods_cat_1']);
echo $smarty->fetch('library/cat_goods.lbi');
$smarty->assign('cat_goods',$smarty->_var['cat_goods_2']);
$smarty->assign('goods_cat',$smarty->_var['goods_cat_2']);
echo $smarty->fetch('library/cat_goods.lbi');
$smarty->assign('cat_goods',$smarty->_var['cat_goods_3']);
$smarty->assign('goods_cat',$smarty->_var['goods_cat_3']);
echo $smarty->fetch('library/cat_goods.lbi');
相关函数
/**
* 获得指定页面的动态内容
*
* @access public
* @param string $tmp 模板名称
* @return void
*/
function assign_dynamic($tmp)
{
$sql = 'SELECT id, number, type FROM ' . $GLOBALS['ecs']->table('template') .
" WHERE filename = '$tmp' AND type > 0 AND remarks ='' AND theme='" . $GLOBALS['_CFG']['template'] . "'";
$res = $GLOBALS['db']->getAll($sql);
foreach ($res AS $row)
{
switch ($row['type'])
{
case 1:
/* 分类下的商品 */
$GLOBALS['smarty']->assign('goods_cat_' . $row['id'], assign_cat_goods($row['id'], $row['number']));
break;
case 2:
/* 品牌的商品 */
$brand_goods = assign_brand_goods($row['id'], $row['number']);
$GLOBALS['smarty']->assign('brand_goods_' . $row['id'], $brand_goods['goods']);
$GLOBALS['smarty']->assign('goods_brand_' . $row['id'], $brand_goods['brand']);
break;
case 3:
/* 文章列表 */
$cat_articles = assign_articles($row['id'], $row['number']);
$GLOBALS['smarty']->assign('articles_cat_' . $row['id'], $cat_articles['cat']);
$GLOBALS['smarty']->assign('articles_' . $row['id'], $cat_articles['arr']);
break;
}
}
}
/**
* 取得某模板某库设置的数量
* @param string $template 模板名,如index
* @param string $library 库名,如recommend_best
* @param int $def_num 默认数量:如果没有设置模板,显示的数量
* @return int 数量
*/
function get_library_number($library, $template = null)
{
global $page_libs;
if (empty($template))
{
$template = basename(PHP_SELF);
$template = substr($template, 0, strrpos($template, '.'));
}
$template = addslashes($template);
static $lib_list = array();
/* 如果没有该模板的信息,取得该模板的信息 */
if (!isset($lib_list[$template]))
{
$lib_list[$template] = array();
$sql = "SELECT library, number FROM " . $GLOBALS['ecs']->table('template') .
" WHERE theme = '" . $GLOBALS['_CFG']['template'] . "'" .
" AND filename = '$template' AND remarks='' ";
$res = $GLOBALS['db']->query($sql);
while ($row = $GLOBALS['db']->fetchRow($res))
{
$lib = basename(strtolower(substr($row['library'], 0, strpos($row['library'], '.'))));
$lib_list[$template][$lib] = $row['number'];
}
}
$num = 0;
if (isset($lib_list[$template][$library]))
{
$num = intval($lib_list[$template][$library]);
}
else
{
/* 模板设置文件查找默认值 */
include_once(ROOT_PATH . ADMIN_PATH . '/includes/lib_template.php');
static $static_page_libs = null;
if ($static_page_libs == null)
{
$static_page_libs = $page_libs;
}
$lib = '/library/' . $library . '.lbi';
$num = isset($static_page_libs[$template][$lib]) ? $static_page_libs[$template][$lib] : 3;
}
return $num;
}
/**
* 获得指定分类下的商品
*
* @access public
* @param integer $cat_id 分类ID
* @param integer $num 数量
* @param string $from 来自web/wap的调用
* @param string $order_rule 指定商品排序规则
* @return array
*/
function assign_cat_goods($cat_id, $num = 0, $from = 'web', $order_rule = '')
{
$sql = 'SELECT sort_order FROM ' . $GLOBALS['ecs']->table('template') .
" WHERE filename = 'index' AND type = 1 AND remarks ='' AND id = $cat_id ";
$sort_order = $GLOBALS['db']->getOne($sql);
$cat['sort_order'] = $sort_order;
$children = get_children($cat_id);
$sql = 'SELECT g.goods_id, g.goods_name, g.market_price, g.shop_price AS org_price, ' .
"IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, ".
'g.promote_price, promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb, g.goods_img ' .
"FROM " . $GLOBALS['ecs']->table('goods') . ' AS g '.
"LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp ".
"ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' ".
'WHERE g.is_on_sale = 1 AND g.is_alone_sale = 1 AND '.
'g.is_delete = 0 AND (' . $children . 'OR ' . get_extension_goods($children) . ') ';
$order_rule = empty($order_rule) ? 'ORDER BY g.sort_order, g.goods_id DESC' : $order_rule;
$sql .= $order_rule;
if ($num > 0)
{
$sql .= ' LIMIT ' . $num;
}
$res = $GLOBALS['db']->getAll($sql);
$goods = array();
foreach ($res AS $idx => $row)
{
if ($row['promote_price'] > 0)
{
$promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']);
$goods[$idx]['promote_price'] = $promote_price > 0 ? price_format($promote_price) : '';
}
else
{
$goods[$idx]['promote_price'] = '';
}
$goods[$idx]['id'] = $row['goods_id'];
$goods[$idx]['name'] = $row['goods_name'];
$goods[$idx]['brief'] = $row['goods_brief'];
$goods[$idx]['market_price'] = price_format($row['market_price']);
$goods[$idx]['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ?
sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];
$goods[$idx]['shop_price'] = price_format($row['shop_price']);
$goods[$idx]['thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true);
$goods[$idx]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']);
$goods[$idx]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']);
/* 会员等级价格 add by yanggg */
$sql = "SELECT rank_id, IFNULL(mp.user_price, r.discount * $row[shop_price] / 100) AS price, r.rank_name, r.discount " . 'FROM '
. $GLOBALS['ecs']->table('user_rank') . ' AS r ' . 'LEFT JOIN ' . $GLOBALS['ecs']->table('member_price') . " AS mp "
. "ON mp.goods_id = '$row[goods_id]' AND mp.user_rank = r.rank_id "
. "WHERE r.show_price = 1 OR r.rank_id = '$_SESSION[user_rank]'";
$res_up = $GLOBALS['db']->query($sql);
while ($row_up = $GLOBALS['db']->fetchRow($res_up)) {
$goods[$idx]['user_price'][$row_up['rank_id']] =
array(
'rank_name' => htmlspecialchars($row_up['rank_name']),
'price' => price_format($row_up['price']),
'rank_id' =>$row_up['rank_id'],
'min_account'=>$row_up['min_account'],
);
}
}
if ($from == 'web')
{
$GLOBALS['smarty']->assign('cat_goods_' . $cat_id, $goods);
}
elseif ($from == 'wap')
{
$cat['goods'] = $goods;
}
/* 分类信息 */
$sql = 'SELECT cat_name FROM ' . $GLOBALS['ecs']->table('category') . " WHERE cat_id = $cat_id";
$cat['name'] = $GLOBALS['db']->getOne($sql);
$cat['url'] = build_uri('category', array('cid' => $cat_id), $cat['name']);
$cat['id'] = $cat_id;
$cat['cat_clild'] = get_clild_list($cat_id);
//获取二级分类下的商品
$cat_list_arr = cat_list($cat_id, 0 , false);
foreach($cat_list_arr as $key=>$value)
{
if($value['level'] == 1)
{
$sql = 'SELECT g.goods_id,g.cat_id, g.goods_name, g.market_price, g.shop_price AS org_price, ' .
"IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, ".
'g.promote_price, promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb, g.goods_img '.
'FROM '.$GLOBALS['ecs']->table('goods') .' AS g '.
'LEFT JOIN ' . $GLOBALS['ecs']->table('member_price') . ' AS mp '.
"ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' ".
'WHERE g.is_on_sale = 1 AND g.is_alone_sale = 1 AND is_delete = 0 AND ' . get_children($value['cat_id']) . ' ORDER BY g.sort_order, g.goods_id DESC';
if ($num > 0)
{
$sql .= ' LIMIT ' . $num;
}
$goods_res = $GLOBALS['db']->getAll($sql);
foreach($goods_res as $idx=>$row)
{
if ($row['promote_price'] > 0)
{
$promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']);
$goods_res[$idx]['promote_price'] = $promote_price > 0 ? price_format($promote_price) : '';
}
else
{
$goods_res[$idx]['promote_price'] = '';
}
$goods_res[$idx]['market_price'] = price_format($row['market_price']);
$goods_res[$idx]['shop_price'] = price_format($row['shop_price']);
$goods_res[$idx]['promote_price'] = $promote_price > 0 ? price_format($promote_price) : '';
$goods_res[$idx]['shop_price'] = price_format($row['shop_price']);
$goods_res[$idx]['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];
$goods_res[$idx]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']);
}
$cat_list_arr[$key]['goods'] = $goods_res;
}
else
{
unset($cat_list_arr[$key]);
}
}
$cat['goods_level2'] = $cat_list_arr;
// 获取分类下品牌
$sql = "SELECT b.brand_id, b.brand_name, brand_logo , COUNT(*) AS goods_num ".
"FROM " . $GLOBALS['ecs']->table('brand') . "AS b, ".
$GLOBALS['ecs']->table('goods') . " AS g LEFT JOIN ". $GLOBALS['ecs']->table('goods_cat') . " AS gc ON g.goods_id = gc.goods_id " .
"WHERE g.brand_id = b.brand_id AND ($children OR " . 'gc.cat_id ' . db_create_in(array_unique(array_merge(array($cat_id), array_keys(cat_list($cat_id, 0, false))))) . ") AND b.is_show = 1 " .
" AND g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 ".
"GROUP BY b.brand_id HAVING goods_num > 0 ORDER BY b.sort_order, b.brand_id ASC LIMIT 3";
$brands = $GLOBALS['db']->getAll($sql);
foreach ($brands AS $key => $val)
{
$brands[$key]['brand_name'] = $val['brand_name'];
$brands[$key]['url'] = build_uri('brand', array('bid' => $val['brand_id']), $val['brand_name']);
$brands[$key]['logo'] = 'data/brandlogo/'.$val['brand_logo'];
}
$cat['brands'] = $brands;
return $cat;
}
E_D("replace into `ecs_template` values('index','分类-商品','/library/cat_goods.lbi','1','2','5','1','meilele','');");
E_D("replace into `ecs_template` values('index','分类-商品','/library/cat_goods.lbi','2','3','5','1','meilele','');");
E_D("replace into `ecs_template` values('index','','/library/brands.lbi','0','0','3','0','meilele','');");
E_D("replace into `ecs_template` values('index','分类-商品','/library/cat_goods.lbi','0','1','5','1','meilele','');");
E_D("replace into `ecs_template` values('index','','/library/auction.lbi','0','0','3','0','meilele','');");
E_D("replace into `ecs_template` values('index','','/library/group_buy.lbi','0','0','1','0','meilele','');");
E_D("replace into `ecs_template` values('index','','/library/recommend_promotion.lbi','0','0','4','0','meilele','');");
E_D("replace into `ecs_template` values('index','','/library/recommend_hot.lbi','0','0','3','0','meilele','');");
E_D("replace into `ecs_template` values('index','','/library/recommend_new.lbi','0','0','3','0','meilele','');");
E_D("replace into `ecs_template` values('index','','/library/recommend_best.lbi','0','0','3','0','meilele','');");
E_D("replace into `ecs_template` values('index','文章-网站公告','/library/cat_articles.lbi','0','9','3','3','meilele','');");