Home > php教程 > php手册 > ecshop首页制作模板时,按要求增加折扣,自己写个php函数调用

ecshop首页制作模板时,按要求增加折扣,自己写个php函数调用

WBOY
Release: 2016-06-06 19:58:12
Original
1033 people have browsed it

如图所示: ecshop本身只有在购物车中涉及到折扣,我们要的不是那种,是单一商品的价比。 如下操作: 在include目录中,找到lib_goods.php,在最后增加如下函数: function get_zhekou($goods_id){$sql = select shop_price,market_price from . $GLOBALS['e

如图所示:


ecshop首页制作模板时,按要求增加折扣,自己写个php函数调用


ecshop本身只有在购物车中涉及到折扣,我们要的不是那种,是单一商品的价格比。


如下操作:


在include目录中,找到lib_goods.php,在最后增加如下函数:


function get_zhekou($goods_id)
{

	$sql = "select shop_price,market_price from " . $GLOBALS['ecs']->table('goods') . "  WHERE goods_id = " . $goods_id . "  " ;

	$res = $GLOBALS['db']->query($sql);

    while ($row = $GLOBALS['db']->fetchRow($res))
    {
        $a         = $row['shop_price'];//商品售价
        $b       = $row['market_price'];//商品市场价
	}


	$c = 10;
	if($b0)
	{
		$c = $a/$b;
	}
	else 
	{
		
	}

	//return number_format($c,2)*10;
	return number_format($c,2)*10;
}
Copy after login

在该文件的327行附近,找到如下内容:


$goods[$idx]['url']          = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']);
Copy after login

在该行下方增加:


$goods[$idx]['goods_zhekou']= get_zhekou($row['goods_id']); 
Copy after login

之后,在前台模板中增加调用的地方即可:


比如: 

{if $goods.goods_zhekou} {$goods.goods_zhekou} {else} 0 {/if}折
Copy after login

完成,简单吧。








source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template