Skip to content

Commit

Permalink
Add Phone to Order (fixes #2), Added E-Mail function.
Browse files Browse the repository at this point in the history
  • Loading branch information
Grisu118 committed Apr 25, 2016
1 parent d420000 commit f9e3d4d
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .env.example
Expand Up @@ -25,6 +25,8 @@ MAIL_ADDRESS=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

MAIL_SUBJECT=Ihre Bestellung

SHOP_BRAND="Grisu119 Foto"
SHOP_NAME="Foto-Shop"
SHOP_HOMEPAGEURL=http://test.ch
Expand Down
28 changes: 24 additions & 4 deletions app/Http/Controllers/PublicController.php
Expand Up @@ -57,10 +57,10 @@ public function show($id)
], 200);
}

public function order(Request $request)
public function order(Request $request) //TODO Add Phone Number
{
if (!$request->firstname or !$request->lastname or !$request->address or !$request->zip
or !$request->city or !$request->finish or !$request->price or !$request->album
or !$request->city or !$request->email or !$request->phone or !$request->finish or !$request->price or !$request->album
or !$request->photos or !$request->agb
) {
return \Response::json([
Expand All @@ -77,6 +77,7 @@ public function order(Request $request)
'zip' => $request->zip,
'city' => $request->city,
'email' => $request->email,
'phone' => $request->phone,
'finish' => $request->finish,
'price' => $request->price,
'remark' => $request->remark,
Expand Down Expand Up @@ -121,14 +122,33 @@ public function order(Request $request)
], 422);
}

//TODO SendMail

return \Response::json([
'data' => 'created'
], 201);
}

public function mail()
{
//Function called by Cronjob of Webserver!

$orders = Order::with('Photo')->with('Album')->where('deleted', '=', false)->where('mailSend', '=', false)->get();

foreach ($orders as $order) {
foreach ($order->photo as $photo) {
$path = explode('/', $photo->path);
$photo->name = end($path);
}

\Mail::send('emails.customer', ['order' => $order], function ($message) use ($order) {
$message->from(env('MAIL_ADDRESS'), $name = null);
$message->to($order->email, $name = null);
$message->cc(env('MAIL_ADDRESS'), $name = null);
$message->subject('#' . $order->id . ':' . $order->album->name . ' - ' . env('MAIL_SUBJECT'));
});
$order->mailSend = true;
$order->save();
}
}

private function transformAlbums($albums)
{
Expand Down
2 changes: 1 addition & 1 deletion app/Order.php
Expand Up @@ -6,7 +6,7 @@

class Order extends Model
{
protected $fillable = ['album_id', 'firstname', 'lastname', 'street', 'zip', 'city', 'email', 'price', 'finish', 'remark'];
protected $fillable = ['album_id', 'firstname', 'lastname', 'street', 'zip', 'city', 'email', 'phone', 'price', 'finish', 'remark'];

public function album() {
return $this->belongsTo('App\Album');
Expand Down
2 changes: 2 additions & 0 deletions database/migrations/2016_03_07_091944_create_orders_table.php
Expand Up @@ -22,9 +22,11 @@ public function up()
$table->string('zip');
$table->string('city');
$table->string('email');
$table->string('phone');
$table->text('remark')->nullable();
$table->decimal('price');
$table->string('finish');
$table->boolean('mailSend')->default(false);
$table->boolean('deleted');
$table->timestamps();
});
Expand Down
1 change: 1 addition & 0 deletions public/lang/de_CH.json
Expand Up @@ -25,6 +25,7 @@
"FORM_ZIP": "Postleitzahl",
"FORM_CITY": "Ort",
"FORM_EMAIL": "E-Mail",
"FORM_PHONE": "Telefon",
"FORM_REMARKS": "Anmerkungen",
"FORM_PAYTYPE": "Zahlungsart",
"FORM_PAY_BILL": "Rechnung",
Expand Down
6 changes: 6 additions & 0 deletions public/views/public/order/orderDialog.html
Expand Up @@ -36,6 +36,12 @@ <h4 translate="ORDER_FORM_HEADER"></h4>
<input type="text" class="form-control" id="inputCity" name="inputCity" ng-model="ctrl.person.city" ng-required="true">
</div>
</div>
<div class="form-group" ng-class="{ 'has-error': orderForm.inputPhone.$invalid }">
<label for="inputPhone" class="col-sm-2 control-label"><span translate="FORM_PHONE"></span></label>
<div class="col-sm-10">
<input type="text" class="form-control" id="inputPhone" name="inputPhone" ng-model="ctrl.person.phone" ng-required="true">
</div>
</div>
<div class="form-group" ng-class="{ 'has-error': orderForm.inputEmail.$invalid }">
<label for="inputEmail" class="col-sm-2 control-label"><span translate="FORM_EMAIL"></span></label>
<div class="col-sm-10">
Expand Down
30 changes: 24 additions & 6 deletions resources/views/emails/customer.blade.php
Expand Up @@ -3,18 +3,36 @@

</head>
<body>
Sehr geehrte(r) Herr/Frau {{$firstname}} {{$lastname}}

Sehr geehrte(r) Herr/Frau {{$order->firstname}} {{$order->lastname}}
<br>
Besten Dank für Ihre Bestellung, wir werden Sie so schnell als möglich abarbeiten.

<h3>Zusammenfassung</h3>
Album: {{$album['name']}}
<b>Kundendaten:</b><br>
{{$order->firstname}} {{$order->lastname}}<br>
{{$order->street}}<br>
{{$order->zip}} {{$order->city}}<br>
{{$order->phone}}<br>
{{$order->email}}
<br><br>
<b>Bemerkungen</b><br>
<span style="white-space: pre-line"><i>{{$order->remark or '-'}}</i></span>
<br><br>
<b>Album</b><br>
#{{$order->album->id}}: {{$order->album->name}}
<br><br>
<b>Bilder</b><br>
Papierqualität: @if ($order->finish == 'DULL')
matt
@else
glänzend
@endif
<ul>
@foreach ($photos as $photo)
<li>Datei: {{$photo['name']}}, Format: {{$photo['size']}}, {{$photo['count']}} Stk. für {{$photo['price']}}</li>
@foreach ($order->photo as $photo)
<li>Datei: {{$photo->name}}, Format: {{$photo->size}}, {{$photo->count}} Stk. für {{$photo->price}} CHF</li>
@endforeach
</ul>
<b>Total: {{$price}}</b>
<b>Total: {{$order->price}} CHF</b>
<hr>
<i>Dies ist eine automatisch generierte E-Mail</i>
</body>
Expand Down

0 comments on commit f9e3d4d

Please sign in to comment.