比如:
当订单金额超过时,优惠
当订单金额超过$99时,优惠$10

当订单金额超过$149时,优惠$15
等等
首先看下实现效果:
在产品详情页面显示优惠方案解释
加入购物车处理折扣并显示
下面是实现这一功能的几片改动:
在 includes/functions/functions_prices.php 文件末端新增一个折扣打算函数:
//折扣打算function shiro_order_discount($total){ global $currencies; if($total >= $currencies->value(149)){ return $total - $currencies->value(15); }elseif($total >= $currencies->value(99)){ return $total - $currencies->value(10); }elseif($total >= $currencies->value(59)){ return $total - $currencies->value(3); } }
对购物车类 添加一个成员属性来保存原价:
includes/classes/shopping_cart.php 24行后面添加
var $ototal;
912行后面 添加调用打折:
// discount$this->ototal = $this->total;$this->total = shiro_order_discount($this->ototal);
添加代码后效果
折扣打算已经完成,还须要在购物车页面显示打折的信息,打开 includes/modules/pages/shopping_cart/header_php.php 在159行后面添加代码:
$cartShowTotal = $currencies->format($_SESSION['cart']->show_total());$cartOtotal = $currencies->format($_SESSION['cart']->show_ototal());$discountTotal = $currencies->format($_SESSION['cart']->show_ototal() - $_SESSION['cart']->show_total());
添加代码后效果
然后回到购物车显示的模板文件 includes/templates/[你的模板]/templates/tpl_shopping_cart_default.php 在134行的位置把原来的 cartSubTotal 层更换成:
<div id="cartSubTotal"> Order Total: <span class="price"><?=$cartOtotal?></span><br> Discount: <span class="price">-<?=$discountTotal?></span><br> <?php echo SUB_TITLE_SUB_TOTAL; ?> <span class="price"><?=$cartShowTotal?></span></div>
末了更换的效果
以上改动只为对全体购物车订单总额进行满多少减多少的折扣。如需不同的折扣条件可在 函数 shiro_order_discount 中 自行定义修正。