2013-10-08 35 views
-2

以下是在結帳時獲得運輸費用的功能。它基於幾件事/返回函數返回運輸成本;如果車的值是> =£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'); 
    } 
+0

好地方在拋出if語句 – Ibu

+2

你剛纔的意思是,如果$查詢 - >行(「總」)大於100或者sc.quantity大於100? –

+0

我們應該如何知道?表結構? '$ this'中的對象屬性?沒有足夠的信息 – SmokeyPHP

回答

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; 
} 
相關問題