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

如图所示: 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;
}

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


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

在该行下方增加:


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

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


比如: 

{if $goods.goods_zhekou} {$goods.goods_zhekou} {else} 0 {/if}折

完成,简单吧。








Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.