【问题标题】:How to make carriage on large orders free of charge?大额订单如何免费托运?
【发布时间】: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.carriagesc.quantity 是什么?您正在查看哪个值以查看它是否为> 100?这行得通吗:$total = $query->row()->total; return $total >= 100 ? 0 : $total;?还是您需要检查其他值之一?

标签: php codeigniter activerecord


【解决方案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;
}

【讨论】:

    猜你喜欢
    • 2019-10-30
    • 1970-01-01
    • 2021-05-28
    • 1970-01-01
    • 2017-03-14
    • 2014-12-22
    • 2021-12-13
    • 2018-04-30
    • 2020-05-11
    相关资源
    最近更新 更多