How to count the total price of order?

前端 未结 3 929
梦如初夏
梦如初夏 2021-01-28 02:25

I have these tables:

Orders: 
id - status -user_id - address_id 
1     await    1          1 

products:
id -  name -   price  - quantity
1     test1    100$             


        
3条回答
  •  忘掉有多难
    2021-01-28 03:03

    • If you don't use any model then use this raw query

    $orderitem = DB::table('order_product')->where('order_id', 'your order id')->get();

        // Now create a foreach loop for get total price 
    
        $total = 0;
    
        foreach($orderitem as $order){
            $porduct = DB::table('products')->where('id', $order->product_id)->first();
            $total += $porduct->price * $order->quantity;
        }
        // now you got sub total
        $shipping = DB::table('cities')->where('id', 'Orders table address column')->first();
        $subtotal = $tatal + $shipping->shipping_charges;
    

提交回复
热议问题