如何免费提供大额订单?

时间:2013-10-08 16:35:00

标签: php codeigniter activerecord

以下是在结账时获取运费的功能。它根据一些东西/获取功能返回运费;如果购物车的价值是> =£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');
     }

1 个答案:

答案 0 :(得分:1)

如果我理解正确,您只需检查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');

    $total = $query->row()->total;
    return $total >= 100 ? 0 : $total;
}