On the smarty related issues of Ecshop

Source: Internet
Author: User
On the smarty problem of Ecshop
This post was last edited by u011850217 on 2014-07-19 13:01:06

This is a piece of code for the index template on the Ecshop phone.


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 '))
{
er _rule = ' ORDER by Shop_price ASC, G.last_update DESC ';
}
Else
{
er _rule = ' ORDER by shop_price Desc, g.last_update desc ';
}

if ($type = = ' promote ')
{
$goods = Wap_get_promote_goods (er _rule);
}
Else
{
$goods = Wap_get_recommend_goods ($type, er _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 <= 0)
{
$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 <= ($page _num * $page)))
{
$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 ' =& Gt 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 (er _price)? 0: er _price), ' page ');
$smarty->assign (' Pagebar ', $pagebar);
}

$smarty->assign (' Footer ', Get_footer ());
$smarty->display (' goods_list.html ');




function Wap_get_recommend_goods ($type = ", er _rule =")
{
if (!in_array ($type, Array (' Best ', ' new ', ' hot '))
{
return Array ();
}

Pick a different recommended product
static $type _goods = Array ();
if (Empty ($type _goods[$type]))
{
Initializing data
$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);
Definition of recommended, latest, popular, promotional items
$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);
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.