欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

关于ecshop的smarty有关问题

程序员文章站 2022-06-16 18:57:25
...
关于ecshop的smarty问题
本帖最后由 u011850217 于 2014-07-19 13:01:06 编辑 这是ecshop手机端的index模板的一段代码
关于ecshop的smarty有关问题

define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');
$type = !empty($_GET['type']) ? $_GET['type'] : 'best';
if ($type != 'best' && $type != 'promote' && $type != 'hot' && $type != 'new')
{
$type = 'best';
}
$smarty->assign('type', $type);

if (empty($_GET['order_price']))
{
$order_rule = 'ORDER BY shop_price ASC, g.last_update DESC';
}
else
{
$order_rule = 'ORDER BY shop_price DESC, g.last_update DESC';
}

if ($type == 'promote')
{
$goods = wap_get_promote_goods($order_rule);
}
else
{
$goods = wap_get_recommend_goods($type, $order_rule);
}

$num = count($goods);
if ($num > 0)
{
foreach ($goods as $key => $data)
{
$sort_array[$data['id']] = $key;
}
$page_num = '10';
$page = !empty($_GET['page']) ? intval($_GET['page']) : 1;
$pages = ceil($num / $page_num);
if ($page {
$page = 1;
}
if ($pages == 0)
{
$pages = 1;
}
if ($page > $pages)
{
$page = $pages;
}
$i = 1;
foreach ($sort_array as $goods_key)
{
if (($i > ($page_num * ($page - 1 ))) && ($i {
$price = empty($goods[$goods_key]['promote_price_org']) ? $goods[$goods_key]['shop_price'] : $goods[$goods_key]['promote_price'];
//$wml_data .= "".encode_output($goods[$goods_key]['name'])."[".encode_output($price)."]
";
$goods_data[] = array('i' => $i , 'price' => encode_output($price) , 'id' => $goods[$goods_key]['id'] , 'name' => encode_output($goods[$goods_key]['name']), 'thumb' => $goods[$goods_key]['thumb']);//16:43 2013-07-16
}
$i++;
}
$smarty->assign('goods_data', $goods_data);
$pagebar = get_wap_pager($num, $page_num, $page, 'goods_list.php?type='.$type.'&order_price='.(empty($order_price)?0:$order_price), 'page');
$smarty->assign('pagebar' , $pagebar);
}

$smarty->assign('footer', get_footer());
$smarty->display('goods_list.html');




function wap_get_recommend_goods($type = '', $order_rule = '')
{
if (!in_array($type, array('best', 'new', 'hot')))
{
return array();
}

//取不同推荐对应的商品
static $type_goods = array();
if (empty($type_goods[$type]))
{
//初始化数据
$type_goods['best'] = array();
$type_goods['new'] = array();
$type_goods['hot'] = array();
$data = read_static_cache('recommend_goods');
if ($data === false)
{
$sql = 'SELECT g.goods_id, g.is_best, g.is_new, g.is_hot, g.is_promote, b.brand_name,g.sort_order ' .
' FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' .
' LEFT JOIN ' . $GLOBALS['ecs']->table('brand') . ' AS b ON b.brand_id = g.brand_id ' .
' WHERE g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 AND (g.is_best = 1 OR g.is_new =1 OR g.is_hot = 1)'.
' ORDER BY g.sort_order, g.last_update DESC';
$goods_res = $GLOBALS['db']->getAll($sql);
//定义推荐,最新,热门,促销商品
$goods_data['best'] = array();
$goods_data['new'] = array();
$goods_data['hot'] = array();
$goods_data['brand'] = array();
if (!empty($goods_res))
{
foreach($goods_res as $data)
{
if ($data['is_best'] == 1)
{
$goods_data['best'][] = array('goods_id' => $data['goods_id'], 'sort_order' => $data['sort_order']);
}
if ($data['is_new'] == 1)
{
$goods_data['new'][] = array('goods_id' => $data['goods_id'], 'sort_order' => $data['sort_order']);
}
if ($data['is_hot'] == 1)
{
$goods_data['hot'][] = array('goods_id' => $data['goods_id'], 'sort_order' => $data['sort_order']);
}
if ($data['brand_name'] != '')
{
$goods_data['brand'][$data['goods_id']] = $data['brand_name'];
}
}
}
write_static_cache('recommend_goods', $goods_data);
关于ecshop的smarty有关问题

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

相关文章

相关视频


    网友评论

    文明上网理性发言,请遵守 新闻评论服务协议

    我要评论
  • 关于ecshop的smarty有关问题
  • 专题推荐