Commit 3b9aced4 by Angel MAS

notification order

parent f68b67a4
......@@ -18,6 +18,7 @@ use Onestartup\Shop\Payment\MP;
use Onestartup\Shop\Notifications\PaymentClient;
use Onestartup\Shop\Notifications\PaymentAcordarClient;
use Onestartup\Shop\Notifications\PaymentClientCard;
use Onestartup\Shop\Notifications\ResumenOrder;
use PayPal\Rest\ApiContext;
use PayPal\Auth\OAuthTokenCredential;
......@@ -261,6 +262,7 @@ public function shipping()
$client = $sale->client;
$items = $sale->items;
$addres = $client->shipping;
$products = $sale->products;
$detail = '';
$status = '';
$user = \App\User::first();
......@@ -299,7 +301,8 @@ public function shipping()
\Session::forget('cart');
\Session::forget('sale');
$user->notify(new PaymentClientCard($client, $request->paymentMethodId, $status));
$user->notify(new ResumenOrder($sale, $products, $client, $addres));
$client->notify(new ResumenOrder($sale, $products, $client, $addres));
return redirect()
->route('main.shop')
......@@ -316,7 +319,9 @@ public function shipping()
\Session::forget('cart');
\Session::forget('sale');
$user->notify(new PaymentClientCard($client, $request->paymentMethodId, $status));
//$user->notify(new PaymentClientCard($client, $request->paymentMethodId, $status));
$user->notify(new ResumenOrder($sale, $products, $client, $addres));
$client->notify(new ResumenOrder($sale, $products, $client, $addres));
return redirect()
->route('main.shop')
......@@ -358,6 +363,7 @@ public function shipping()
$client = $sale->client;
$items = $sale->items;
$addres = $client->shipping;
$products = $sale->products;
$detail = '';
foreach ($sale->items as $item) {
......@@ -396,7 +402,8 @@ public function shipping()
\Session::forget('sale');
$user = \App\User::first();
$user->notify(new PaymentClient($request->payment_id, $client));
$user->notify(new ResumenOrder($sale, $products, $client, $addres));
$client->notify(new ResumenOrder($sale, $products, $client, $addres));
return redirect()
......@@ -461,13 +468,15 @@ public function shipping()
$client = $sale->client;
$items = $sale->items;
$addres = $client->shipping;
$products = $sale->products;
$sale->status = 2;
$sale->payment_type = 'Pay Pal';
$sale->save();
$user = \App\User::first();
$user->notify(new PaymentClientCard($client, 'Paypal', 'Pagado'));
$user->notify(new ResumenOrder($sale, $products, $client, $addres));
$client->notify(new ResumenOrder($sale, $products, $client, $addres));
\Session::forget('client');
\Session::forget('cart');
......@@ -511,6 +520,7 @@ public function shipping()
$sale = Sale::find(\Session::get('sale')->id);
$client = $sale->client;
$items = $sale->items;
$products = $sale->products;
$addres = $client->shipping;
$detail = '';
......@@ -619,6 +629,7 @@ public function shipping()
$sale = Sale::find(\Session::get('sale')->id);
$client = $sale->client;
$products = $sale->products;
$items = $sale->items;
$addres = $client->shipping;
$detail = '';
......@@ -633,14 +644,32 @@ public function shipping()
\Session::forget('sale');
$user = \App\User::first();
$user->notify(new PaymentAcordarClient('Acordar con el vendedor', $client));
//$user->notify(new PaymentAcordarClient('Acordar con el vendedor', $client));
$user->notify(new ResumenOrder($sale, $products, $client, $addres));
$client->notify(new ResumenOrder($sale, $products, $client, $addres));
return redirect()
->route('main.shop')
->with('acordar', 'acordar');
}
public function testmail()
{
/*$user = \App\User::first();
$orden = Sale::find(27);
$products = $orden->products;
$client = $orden->client;
$shipping = $client->shipping;
//return $products;
//return $shipping->shipping_price->name;
$user->notify(new ResumenOrder($orden, $products, $client, $shipping));*/
return "Liston";
}
}
......@@ -3,9 +3,12 @@
namespace Onestartup\Shop\Model;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;
class ClientShop extends Model
{
use Notifiable;
protected $table = 'client_shops';
protected $fillable = [
'name',
......
......@@ -24,4 +24,14 @@ class SaleShop extends Model
{
return $this->hasMany('Onestartup\Shop\Model\OrderTracking', 'sale_id');
}
public function products()
{
return $this->belongsToMany(
'Onestartup\Shop\Model\ProductShop',
'detail_shops',
'sale_id',
'product_id')
->withPivot('quantity');
}
}
<?php
namespace Onestartup\Shop\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Onestartup\Shop\Model\SaleShop as Order;
use Onestartup\Shop\Model\ClientShop as Client;
use Onestartup\Shop\Model\ShippingAddres as Shipping;
class ResumenOrder extends Notification
{
use Queueable;
protected $order;
protected $products;
protected $client;
protected $shipping;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct(Order $order, $products, Client $client, Shipping $shipping)
{
$this->order = $order;
$this->products = $products;
$this->shipping = $shipping;
$this->client = $client;
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['mail'];
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
return (new MailMessage)
->subject('Resumen de compra')
->markdown('shop::mail.resumen.order', [
'order'=>$this->order,
'products'=>$this->products,
'client'=>$this->client,
'shipping'=>$this->shipping
]);
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
//
];
}
}
......@@ -100,4 +100,6 @@ Route::group(['middleware' => ['web']], function(){
Route::post('cart/paymentPaypal', 'Onestartup\Shop\Controller\CartController@paymentPaypal')->name('cart.paymentPaypal');
Route::get('cart/successPaypal', 'Onestartup\Shop\Controller\CartController@successPaypal')->name('cart.successPaypal');
Route::get('cart/cancelPaypal', 'Onestartup\Shop\Controller\CartController@cancelPaypal')->name('cart.cancelPaypal');
Route::get('cart/testmail', 'Onestartup\Shop\Controller\CartController@testmail')->name('cart.testmail');
});
@php
setlocale(LC_MONETARY, 'en_US');
@endphp
@component('mail::message')
# Resumen de la compra
@component('mail::panel')
- Numero de orden: # {{$order->id}}
- Fecha: {{$order->created_at->format('d/m/Y')}}
- Forma de pago: {{$order->payment_type}}
@endcomponent
@component('mail::table')
| Cantidad | Producto | Precio | Subtotal |
| :-------------: |:-------------:| :--------:| :-------:|
@foreach($products as $p)
| {{$p->pivot->quantity}} | {{$p->name}} | {{money_format('%(#10n', $p->infoSale->sale_price)}} | {{money_format('%(#10n', $p->infoSale->sale_price * $p->pivot->quantity)}} |
@endforeach
| 1 | {{$shipping->shipping_price->name}} | {{money_format('%(#10n',$shipping->shipping_price->cost)}} | {{money_format('%(#10n',$shipping->shipping_price->cost)}} |
| - | - | Total: | {{money_format('%(#10n',$order->total)}}|
@endcomponent
@component('mail::panel')
Datos del comprador:
- Nombre: *** {{$client->name}} {{$client->lastname}} ***
- Teléfono: *** {{$client->phone}} ***
- Correo: *** {{$client->email}} ***
@endcomponent
@component('mail::panel')
Datos de envio:
- Calle: *** {{$shipping->calle}} Nro. {{$shipping->numero}}, col. {{$shipping->colonia}} ***
- *** {{$shipping->ciudad}}, {{$shipping->estado}}, C.P. {{$shipping->cp}}***
- Referencias: *** {{$shipping->referencias}} ***
@endcomponent
Gracias por tu compra,<br>
{{ config('app.name') }}
@endcomponent
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