【发布时间】:2013-10-08 16:34:59
【问题描述】:
以下是在结帐时获取运输费用的功能。但是,它会根据一些事情/获取功能返回运输成本;如果购物车的价值 >=100 英镑(“p.price”),那么我需要返回“0.00 英镑”的价值,否则正常使用该功能,即 $query->row('total') 我认为:/
function get_cart_total($cartID) {
$this->db->select('SUM((COALESCE(NULLIF(sc.override_price_from_auction, 0), p.price))*sc.quantity) AS total',FALSE);
$this->db->join('products AS p', 'sc.product_id = p.product_id');
$this->db->where('sc.cart_id',$cartID);
$query = $this->db->get('shopping_cart AS sc');
return $query->row('total');
function total_with_VAT($cartID, $taxAmount) {
$total = $this->get_cart_total($cartID);
$tax_inclusive_total = $total;
return $tax_inclusive_total;
}
function carriage_cost($cartID) {
$this->db->select('SUM(p.carriage*sc.quantity) AS total',FALSE);
$this->db->join('products AS p', 'sc.product_id = p.product_id');
$this->db->where('sc.cart_id',$cartID);
$query = $this->db->get('shopping_cart AS sc');
$query->row('total');
//echo $this->db->last_query();
return $query->row('total');
}
【问题讨论】:
-
插入 if 语句的好地方
-
你的意思是 $query->row('total') 大于 100 还是 sc.quantity 大于 100?
-
我们应该怎么知道?表结构?
$this中的对象属性?没有足够的信息 -
@SmokeyPHP:我假设
$this是 CodeIgniter。这看起来像 CodeIgniter 活动记录代码。 -
p.carriage和sc.quantity是什么?您正在查看哪个值以查看它是否为> 100?这行得通吗:$total = $query->row()->total; return $total >= 100 ? 0 : $total;?还是您需要检查其他值之一?
标签: php codeigniter activerecord