Commit deae60f0 authored by Artem's avatar Artem

add mail sending for order confirmation

parent 78eea069
......@@ -2,11 +2,13 @@
namespace App\Http\Controllers;
use App\Mail\OrderConfirmation;
use App\Order;
use App\OrderDetail;
use App\Product;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Mail;
use Session;
class OrderController extends Controller
......@@ -25,13 +27,11 @@ class OrderController extends Controller
'total_qty' => $cart->total_qty,
]);
$order_id = $order->id;
foreach ($cart->items as $id => $item) {
$product = Product::where('id', $id)->first();
OrderDetail::create([
'order_id' => $order_id,
'order_id' => $order->id,
'product_id' => $id,
'ordered_reference' => $product->reference,
'ordered_price' => $product->price,
......@@ -42,6 +42,16 @@ class OrderController extends Controller
Session::forget('cart');
return view('cart', compact('order_id'));
//// $order->user->email
//// TODO to ask/check how to pass e-mail as variable to Mail::raw
// Mail::raw('Order placed, hehe123.', function ($message) {
// $message->to('ololo@info.com')
// ->subject('Order subject');
// });
Mail::to($order->user->email)
->send(new OrderConfirmation($order->id));
return redirect('cart')->with('order_id', $order->id);
}
}
......@@ -72,8 +72,8 @@
</table>
@else
@if(isset($order_id))
<div class="alert alert-success">Thank you, order succesfully placed. Your order number is <b>{{ $order_id }}</b>. We will contact you shortly.</div>
@if( session('order_id') )
<div class="alert alert-success">Thank you, order succesfully placed. Your order number is <b>{{ session('order_id') }}</b>. We will contact you shortly.</div>
<a href="{{ route('homepage') }}">You may like our other products</a>
@else
<div>There are no products in the cart. <a href="{{ route('homepage') }}">Check our products</a></div>
......
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<p>Thank you for order. Your order number is {{ $order_id }}. We will contact you shortly.</p>
</body>
</html>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment