diff --git a/app/Http/Controllers/Shop/CategoryController.php b/app/Http/Controllers/Shop/CategoryController.php
index cb755cef..3a36845c 100644
--- a/app/Http/Controllers/Shop/CategoryController.php
+++ b/app/Http/Controllers/Shop/CategoryController.php
@@ -26,11 +26,21 @@ class CategoryController extends Controller
dump($product_type);
exit;
} else {
- // $product_type = Articles::getProductTypeByCategory($category_id);
- // dump($product_type);
$article_nature = $request->input('article_nature');
- // dump($article_nature);
- // exit;
+ if (!$article_nature) {
+ $article_natures = Articles::getArticleNaturesWithOffers([
+ 'category_id' => $category_id,
+ ]);
+ if (count($article_natures) === 1) {
+ $article_nature = $article_natures[0];
+ }
+ $product_types = Articles::getProductTypesWithOffers([
+ 'category_id' => $category_id,
+ ]);
+ if (count($product_types) === 1) {
+ $product_type = $product_types[0];
+ }
+ }
switch ($article_nature) {
case 'semences':
@@ -46,14 +56,17 @@ class CategoryController extends Controller
$article_nature_id = 3;
break;
default:
- $product_type = 'botanic';
- $article_nature_id = 1;
- $article_nature = 'semences';
+ if (!($product_type ?? false)) {
+ $product_type = 'botanic';
+ $article_nature_id = 1;
+ $article_nature = 'semences';
+ }
break;
}
// $product_type = ArticleNatures::getProductType($article_nature_id);
// dump($product_type);
// dump($article_nature_id);
+ // exit;
}
// exit;
$data = [
@@ -62,12 +75,8 @@ class CategoryController extends Controller
'display_by_rows' => $request->input('display_by_rows') ?? false,
'product_type' => $product_type,
'article_nature' => $article_nature,
- 'article_natures' => Articles::getArticleNaturesWithOffers([
- 'category_id' => $category_id,
- ]),
- 'product_types' => Articles::getProductTypesWithOffers([
- 'category_id' => $category_id,
- ]),
+ 'article_natures' => $article_natures,
+ 'product_types' => $product_types,
'tags_selected' => $request->input('tags') ?? [],
'articles' => Articles::getArticlesToSell([
'category_id' => $category_id,
@@ -77,6 +86,8 @@ class CategoryController extends Controller
]),
'tags' => TagGroups::getWithTagsAndCountOffers($category_id),
];
+ // dump($data);
+ // exit;
return view('Shop.Shelves.shelve', $data);
}
diff --git a/app/Mail/Acheminement.php b/app/Mail/Acheminement.php
index 482b18da..d8881a3b 100644
--- a/app/Mail/Acheminement.php
+++ b/app/Mail/Acheminement.php
@@ -3,6 +3,7 @@
namespace App\Mail;
use App\Models\Core\Mail\MailTemplate;
+use App\Repositories\Shop\Invoices;
use App\Repositories\Shop\Traits\MailCustomers;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
@@ -14,18 +15,42 @@ class Acheminement extends TemplateMailable
protected static $templateModelClass = MailTemplate::class;
- public $user;
+ public $email;
- public $male;
+ public $nom;
+
+ public $prenom;
+
+ public $societe;
public $subject;
- public $url;
+ public $numero_suivi;
- public function __construct($user, $subject = '')
+ public $numero_commande;
+
+ public $adresse;
+
+ public $cp;
+
+ public $ville;
+
+ public $date_expedition;
+
+ public $facture;
+
+ public function __construct($order)
{
- $this->user = $user;
- $this->male = $user->gender == 1;
- $this->subject = $subject;
+ $this->prenom = $order->customer->first_name;
+ $this->nom = $order->customer->last_name;
+ $this->adresse = $order->address->address;
+ $this->cp = $order->address->zipcode;
+ $this->ville = $order->address->city;
+ $this->societe = $order->customer->company;
+ $this->email = $order->customer->email;
+ $this->numero_suivi = $order->delivery_ref;
+ $this->numero_commande = $order->ref;
+ $this->date_expedition = $order->updated_at;
+ $this->facture = Invoices::getInvoiceHtml($order->invoice->id);
}
}
diff --git a/app/Mail/Preparation.php b/app/Mail/Preparation.php
index 4f142d72..9eeb672e 100644
--- a/app/Mail/Preparation.php
+++ b/app/Mail/Preparation.php
@@ -24,12 +24,12 @@ class Preparation extends TemplateMailable
public $subject;
- public function __construct($user, $subject = '')
+ public function __construct($order)
{
- $this->prenom = $user->first_name;
- $this->nom = $user->last_name;
- $this->societe = $user->society;
- $this->email = $user->email;
+ $this->prenom = $order->customer->first_name;
+ $this->nom = $order->customer->last_name;
+ $this->societe = $order->customer->company;
+ $this->email = $order->customer->email;
$this->subject = $subject;
}
}
diff --git a/app/Repositories/Shop/Customers.php b/app/Repositories/Shop/Customers.php
index 04d2d941..343b817e 100644
--- a/app/Repositories/Shop/Customers.php
+++ b/app/Repositories/Shop/Customers.php
@@ -26,7 +26,7 @@ class Customers
public static function editProfile($id = false)
{
$id = $id ? $id : self::getId();
- $orders_datatable = new CustomerOrdersDataTable;
+ $orders_datatable = new CustomerOrdersDataTable();
$data = [
'customer' => self::get($id, ['addresses', 'deliveries', 'orders'])->toArray(),
'deliveries' => Deliveries::getAll('sale_channel')->toArray(),
@@ -144,7 +144,7 @@ class Customers
return false;
}
$deliveries = collect($deliveries)->transform(
- function ($item, $key) {
+ function ($item) {
return (int) $item;
}
)->toArray();
diff --git a/app/Repositories/Shop/Invoices.php b/app/Repositories/Shop/Invoices.php
index d374b99c..78988561 100644
--- a/app/Repositories/Shop/Invoices.php
+++ b/app/Repositories/Shop/Invoices.php
@@ -8,6 +8,20 @@ use App\Models\Shop\Invoice;
class Invoices
{
+ public static function getInvoiceHtml($id)
+ {
+ $invoice = self::get($id, ['order.customer', 'order.address', 'order.detail']);
+ $order = $invoice->order;
+ $customer = $order->customer;
+ unset($invoice->order, $order->customer);
+ $data = [
+ 'invoice' => $invoice->toArray(),
+ 'order' => $order->toArray(),
+ 'customer' => $customer->toArray(),
+ ];
+ return view('Shop.Invoices.mail', $data)->render();
+ }
+
public static function getByUUID($uuid)
{
return Invoice::byUUID($uuid)->first();
diff --git a/app/Repositories/Shop/Orders.php b/app/Repositories/Shop/Orders.php
index c54885a9..b60a5b08 100644
--- a/app/Repositories/Shop/Orders.php
+++ b/app/Repositories/Shop/Orders.php
@@ -3,10 +3,13 @@
namespace App\Repositories\Shop;
use Carbon\Carbon;
+use App\Mail\Acheminement;
+use App\Mail\Preparation;
use App\Models\Shop\Order;
use App\Repositories\Core\DateStats;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
+use Illuminate\Support\Facades\Mail;
class Orders
{
@@ -34,6 +37,35 @@ class Orders
return ($order && $detail) ? Invoices::saveInvoice($order->id, $data) : false;
}
+ public static function testSend($id)
+ {
+ $order = self::get($id, ['customer', 'address']);
+ dump($order->toArray());
+ exit;
+ self::sendPreparation($order);
+ }
+
+ public static function sendOrderConfirmed($order_id)
+ {
+ $order = self::get($order_id, ['customer']);
+ $mail = new Acheminement($order);
+ return Mail::to($order->email)->send($mail);
+ }
+
+ public static function sendShipping($order_id)
+ {
+ $order = self::get($order_id, ['customer']);
+ $mail = new Acheminement($order);
+ return Mail::to($order->email)->send($mail);
+ }
+
+ public static function sendPreparation($order_id)
+ {
+ $order = self::get($order_id, ['customer']);
+ $mail = new Preparation($order);
+ return Mail::to($order->email)->send($mail);
+ }
+
public static function count()
{
return Order::count();
diff --git a/app/Repositories/Shop/Traits/MailCustomers.php b/app/Repositories/Shop/Traits/MailCustomers.php
index 884be200..3ae2a99b 100644
--- a/app/Repositories/Shop/Traits/MailCustomers.php
+++ b/app/Repositories/Shop/Traits/MailCustomers.php
@@ -9,28 +9,6 @@ use Illuminate\Mail\Mailables\Envelope;
trait MailCustomers
{
- public static function getContext()
- {
- return Customers::getOptions();
- }
-
- public static function getData($id)
- {
- $user = self::getUser($id);
-
- return $user ? [
- 'prenom' => $user->first_name,
- 'nom' => $user->last_name,
- 'societe' => $user->society,
- 'email' => $user->email,
- ] : false;
- }
-
- public static function getUser($id)
- {
- return Customers::get($id);
- }
-
public function envelope()
{
return new Envelope(
diff --git a/resources/views/Shop/Invoices/mail.blade.php b/resources/views/Shop/Invoices/mail.blade.php
new file mode 100644
index 00000000..5b5b2437
--- /dev/null
+++ b/resources/views/Shop/Invoices/mail.blade.php
@@ -0,0 +1,165 @@
+
+
+
+
+
+
+
+
+
+ |
+
+
+ |
+
+
+
+
+
+
+
+
+
+
+ Livré à:
+
+
+ {{ $order['address']['name'] }}
+ {{ $order['address']['address'] }}
+ {{ $order['address']['zipcode'] }} {{ $order['address']['city'] }}
+ FR
+
+
+ |
+
+
+ Facturé à:
+
+ {{ $customer['first_name'] }} {{ $customer['last_name'] }}
+ {{ $customer['address'] }}
+ {{ $customer['zipcode'] }} {{ $customer['city'] }}
+ FR
+
+
+ |
+
+
+ Jardin'enVie Artisan Semencier SCIC SA
+ 429 route des chaux
+ 26500 Bourge les Valence
+
+ |
+
+
+
+
+
+
+
+ |
+
+ N° Facture
+ {{ $invoice['ref'] }}
+
+ |
+
+
+ Date D'émission
+ {{ $invoice['created_at'] }}
+
+ |
+
+
+ TVA N°
+ FR21 818 557 589
+
+ |
+
+
+ |
+
+ Numéro de commande
+ {{ $order['ref'] }}
+
+ |
+
+
+ N° Client
+ {{ $customer['id'] }}
+
+ |
+
+ |
+
+
+
+
+
+
+
+ |
+ Désignation
+ |
+
+ Quantité
+ |
+
+ TOTAL HT
+ |
+
+ Total TVA
+ |
+
+ Total
+ |
+
+ TAUX
+ |
+
+
+ |
+ Livraison
+ |
+ |
+ {{ $invoice['shipping'] }} |
+ |
+
+
+ |
+
+ @foreach ($order['detail'] as $detail)
+
+ | {{ $detail['name'] }} |
+ {{ $detail['quantity'] }} |
+ {{ $detail['total'] }} |
+ {{ $detail['total_tax'] }} |
+ {{ $detail['total_taxed'] }} |
+ |
+
+ @endforeach
+
+ |
+ |
+ TOTAL HT |
+ TOTAL TVA |
+ TOTAL |
+ |
+
+
+ |
+ |
+ {{ $invoice['total'] }} |
+ {{ $invoice['taxes'] }} |
+ {{ $invoice['total_taxed'] }} |
+ EUR |
+
+
+
+ |
+
+
+