From f721422abc447d638752cfb377603167d38f2f21 Mon Sep 17 00:00:00 2001 From: Ludovic CANDELLIER Date: Mon, 28 Aug 2023 21:48:04 +0200 Subject: [PATCH] fixes --- .../Admin/Shop/OrderController.php | 15 ++++++++-- app/Http/Controllers/Shop/OrderController.php | 2 ++ app/Http/Middleware/Authenticate.php | 2 +- app/Models/Shop/Invoice.php | 7 ++++- app/Models/Shop/Order.php | 5 ---- app/Repositories/Shop/Invoices.php | 29 +++---------------- app/Repositories/Shop/Orders.php | 4 +-- .../views/Admin/Shop/Orders/edit.blade.php | 11 +++---- .../Shop/Orders/partials/addresses.blade.php | 2 +- .../Shop/Orders/partials/payments.blade.php | 14 ++++----- routes/web.php | 1 - 11 files changed, 42 insertions(+), 50 deletions(-) diff --git a/app/Http/Controllers/Admin/Shop/OrderController.php b/app/Http/Controllers/Admin/Shop/OrderController.php index c18b896e..47662cd3 100644 --- a/app/Http/Controllers/Admin/Shop/OrderController.php +++ b/app/Http/Controllers/Admin/Shop/OrderController.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers\Admin\Shop; use App\Datatables\Shop\OrdersDataTable; use App\Http\Controllers\Controller; use App\Repositories\Shop\Orders; +use App\Repositories\Shop\OrderMails; use Illuminate\Http\Request; class OrderController extends Controller @@ -29,20 +30,30 @@ class OrderController extends Controller public function edit($id) { $data = Orders::edit($id); + // dump($data); + // exit; return view('Admin.Shop.Orders.edit', $data); } public function store(Request $request) { - $ret = Orders::store($request->all()); + $order = Orders::store($request->all()); + switch ($order->status) { + case 1: + OrderMails::sendPreparation($order->id); + break; + case 2: + OrderMails::sendShipping($order->id); + break; + } return redirect()->route('Admin.Shop.Orders.index'); } public function delete($id) { - return Orders::delete($id); + return Orders::destroy($id); } public function download($id) diff --git a/app/Http/Controllers/Shop/OrderController.php b/app/Http/Controllers/Shop/OrderController.php index 5b048db5..d60ee651 100644 --- a/app/Http/Controllers/Shop/OrderController.php +++ b/app/Http/Controllers/Shop/OrderController.php @@ -9,6 +9,7 @@ use App\Repositories\Core\User\ShopCart; use App\Repositories\Shop\Customers; use App\Repositories\Shop\Deliveries; use App\Repositories\Shop\Orders; +use App\Repositories\Shop\OrderMails; use App\Repositories\Shop\Paybox; use App\Repositories\Shop\Baskets; use App\Repositories\Shop\SaleChannels; @@ -62,6 +63,7 @@ class OrderController extends Controller } else { return redirect()->route('Shop.Orders.confirmed'); } + OrderMails::sendOrderConfirmed($order->id); } else { return view('Shop.Orders.order'); } diff --git a/app/Http/Middleware/Authenticate.php b/app/Http/Middleware/Authenticate.php index 704089a7..e6fa3f2b 100644 --- a/app/Http/Middleware/Authenticate.php +++ b/app/Http/Middleware/Authenticate.php @@ -15,7 +15,7 @@ class Authenticate extends Middleware protected function redirectTo($request) { if (! $request->expectsJson()) { - return route('login'); + return route('boilerplate.login'); } } } diff --git a/app/Models/Shop/Invoice.php b/app/Models/Shop/Invoice.php index 23318479..868dd838 100644 --- a/app/Models/Shop/Invoice.php +++ b/app/Models/Shop/Invoice.php @@ -31,7 +31,12 @@ class Invoice extends Model public function customer() { - return $this->belongsToThrough(Customer::class, Order::class, null, '', [Customer::class => 'customer_id', Order::class => 'order_id']); + return $this->belongsTo(Customer::class, 'customer_id'); + } + + public function address() + { + return $this->belongsTo(CustomerAddress::class, 'invoice_address_id'); } public function scopeByUUID($query, $uuid) diff --git a/app/Models/Shop/Order.php b/app/Models/Shop/Order.php index fa3bb9ed..7dc08239 100644 --- a/app/Models/Shop/Order.php +++ b/app/Models/Shop/Order.php @@ -23,11 +23,6 @@ class Order extends Model return $this->belongsTo(Customer::class); } - public function address() - { - return $this->belongsTo(CustomerAddress::class, 'customer_address_id'); - } - public function delivery_address() { return $this->belongsTo(CustomerAddress::class, 'customer_delivery_id'); diff --git a/app/Repositories/Shop/Invoices.php b/app/Repositories/Shop/Invoices.php index bfd1ac26..572c257d 100644 --- a/app/Repositories/Shop/Invoices.php +++ b/app/Repositories/Shop/Invoices.php @@ -3,11 +3,14 @@ namespace App\Repositories\Shop; use App\Models\Shop\Invoice; +use App\Traits\Model\Basic; use Carbon\Carbon; use Illuminate\Support\Str; class Invoices { + use Basic; + public static function getInvoiceHtml($id) { $invoice = self::get($id, ['order.customer', 'order.address', 'order.detail']); @@ -35,16 +38,6 @@ class Invoices return self::store($data); } - public static function get($id, $relations = false) - { - return $relations ? Invoice::with($relations)->findOrFail($id) : Invoice::findOrFail($id); - } - - public static function count() - { - return Invoice::count(); - } - public static function countByMonth() { $start = Carbon::now()->beginOfMonth(); @@ -52,11 +45,6 @@ class Invoices return Invoice::where('created_at', '>', $start); } - public static function store($data) - { - return ($data['id'] ?? false) ? self::update($data) : self::create($data); - } - public static function create($data) { InvoiceStats::increase($data['total_taxed']); @@ -66,15 +54,6 @@ class Invoices return Invoice::create($data); } - public static function update($data, $id = false) - { - $id = $id ? $id : $data['id']; - $item = self::get($id); - $item->update($data); - - return $item; - } - public static function delete($id) { $invoice = self::get($id); @@ -85,7 +64,7 @@ class Invoices public static function getNewRef() { - $ref = date('ym').'00000'; + $ref = date('ymd').'00000'; $lastRef = Invoice::orderBy('id', 'desc')->first(); return $lastRef ? $lastRef->ref + 1 : $ref + 1; diff --git a/app/Repositories/Shop/Orders.php b/app/Repositories/Shop/Orders.php index 8e2f6363..8d630c38 100644 --- a/app/Repositories/Shop/Orders.php +++ b/app/Repositories/Shop/Orders.php @@ -37,7 +37,7 @@ class Orders public static function edit($id) { return [ - 'order' => self::get($id, ['customer', 'address', 'delivery_address', 'detail']), + 'order' => self::get($id, ['customer', 'invoice.address', 'delivery', 'delivery_address', 'detail'])->toArray(), 'statuses' => self::statuses(), 'delivery_types' => DeliveryTypes::getOptions(), 'payment_types' => self::paymentTypes(), @@ -89,7 +89,7 @@ class Orders public static function getNewRef() { - $ref = date('ym').'00000'; + $ref = date('ymd').'00000'; $lastRef = Order::orderBy('id', 'desc')->first(); return $lastRef ? $lastRef->ref + 1 : $ref + 1; diff --git a/resources/views/Admin/Shop/Orders/edit.blade.php b/resources/views/Admin/Shop/Orders/edit.blade.php index edf7fc48..6d116c0b 100644 --- a/resources/views/Admin/Shop/Orders/edit.blade.php +++ b/resources/views/Admin/Shop/Orders/edit.blade.php @@ -25,12 +25,13 @@
- @if ($order['address']) - {{ $order['address']['address'] }}
- @isset ($order['address']['address2']) - {{ $order['address']['address2'] }}
+ @if ($order['invoice']['address']) + {{ $order['invoice']['address']['address'] }}
+ @isset ($order['invoice']['address']['address2']) + {{ $order['invoice']['address']['address2'] }}
@endisset - {{ $order['address']['zipcode'] }} {{ $order['address']['city'] }}
+ {{ $order['invoice']['address']['zipcode'] }} + {{ $order['invoice']['address']['city'] }}
@endif
diff --git a/resources/views/Shop/Orders/partials/addresses.blade.php b/resources/views/Shop/Orders/partials/addresses.blade.php index 23335fc0..278f3b19 100644 --- a/resources/views/Shop/Orders/partials/addresses.blade.php +++ b/resources/views/Shop/Orders/partials/addresses.blade.php @@ -1,6 +1,6 @@ @if ($addresses) @foreach ($addresses ?? [] as $address) -
+
diff --git a/resources/views/Shop/Orders/partials/payments.blade.php b/resources/views/Shop/Orders/partials/payments.blade.php index 3c232001..b1ec68d5 100644 --- a/resources/views/Shop/Orders/partials/payments.blade.php +++ b/resources/views/Shop/Orders/partials/payments.blade.php @@ -1,26 +1,26 @@ -
+
-
+
PAIEMENT PAR CARTE BANCAIRE
-
+
-
+
PAIEMENT PAR CHEQUE
-
+
-
+
PAIEMENT PAR VIREMENT BANCAIRE
@@ -29,7 +29,7 @@
-
+
J'ai lu les conditions générales de vente et j'y adhère sans réserve
diff --git a/routes/web.php b/routes/web.php index 4d150d66..2b462597 100644 --- a/routes/web.php +++ b/routes/web.php @@ -13,7 +13,6 @@ // Auth::routes(); -Route::get('login2', 'Shop\Auth\LoginController@showLoginForm')->name('login'); Route::get('', 'Shop\HomeController@index')->name('welcome'); Route::get('home', 'Shop\HomeController@index')->name('home');