From 496274b4f4acf1b42df47161bd77d819b01bdee0 Mon Sep 17 00:00:00 2001 From: Ludovic CANDELLIER Date: Tue, 29 Aug 2023 22:15:37 +0200 Subject: [PATCH] fix orders datatables on profile, fix deliveries for profile (public & active) --- .../Shop/CustomerOrdersDataTable.php | 12 +++-- .../Controllers/Shop/BasketController.php | 10 +++-- .../Controllers/Shop/CustomerController.php | 4 ++ app/Models/Shop/Delivery.php | 22 ++++----- app/Repositories/Shop/Customers.php | 45 +++++-------------- app/Repositories/Shop/Deliveries.php | 42 ++++------------- resources/views/Shop/Baskets/basket.blade.php | 6 +-- .../Baskets/partials/basketTotal.blade.php | 4 +- .../Customers/partials/addresses.blade.php | 4 +- resources/views/Shop/Orders/order.blade.php | 2 +- 10 files changed, 60 insertions(+), 91 deletions(-) diff --git a/app/Datatables/Shop/CustomerOrdersDataTable.php b/app/Datatables/Shop/CustomerOrdersDataTable.php index 8655e918..43c8ec17 100644 --- a/app/Datatables/Shop/CustomerOrdersDataTable.php +++ b/app/Datatables/Shop/CustomerOrdersDataTable.php @@ -18,10 +18,16 @@ class CustomerOrdersDataTable extends DataTable public $stateSave = true; + public function __construct() + { + $this->url = route('Shop.Orders.index'); + } + + public function query(Order $model) { - $customer_id = Auth::id(); - $model = $model->byCustomer($customer_id)->with(['delivery']); + $customerId = Auth::id(); + $model = $model->byCustomer($customerId)->with(['delivery']); return $this->buildQuery($model); } @@ -46,8 +52,8 @@ class CustomerOrdersDataTable extends DataTable protected function getColumns() { return [ - Column::make('ref')->title('Ref'), Column::make('status')->title('Statut'), + Column::make('ref')->title('Ref'), Column::make('created_at')->title('Date'), Column::make('payment_type')->title('Règlement'), Column::make('total_shipped')->title('Montant')->class('text-right'), diff --git a/app/Http/Controllers/Shop/BasketController.php b/app/Http/Controllers/Shop/BasketController.php index f7006fc7..67231433 100644 --- a/app/Http/Controllers/Shop/BasketController.php +++ b/app/Http/Controllers/Shop/BasketController.php @@ -31,14 +31,18 @@ class BasketController extends Controller public function modalBasket($offerId, $quantity) { - $data['offer'] = Offers::getFull($offerId)->toArray(); - $data['basket'] = Baskets::addBasket($offerId, $quantity); + $data = [ + 'offer' => Offers::getFull($offerId)->toArray(), + 'basket' => Baskets::addBasket($offerId, $quantity), + ]; return view('Shop.Baskets.partials.modalBasket', $data); } public function basket() { - $data['basket'] = Baskets::getBasket(); + $data = [ + 'basket' => Baskets::getBasket(), + ]; return view('Shop.Baskets.basket', $data); } diff --git a/app/Http/Controllers/Shop/CustomerController.php b/app/Http/Controllers/Shop/CustomerController.php index 329d2766..7f12dae2 100644 --- a/app/Http/Controllers/Shop/CustomerController.php +++ b/app/Http/Controllers/Shop/CustomerController.php @@ -13,12 +13,14 @@ class CustomerController extends Controller public function profile($id = false) { $data = Customers::editProfile($id); + return view('Shop.Customers.profile', $data); } public function modalProfile($id = false) { $data['customer'] = Customers::get($id); + return view('Shop.Customers.partials.registration', $data); } @@ -26,6 +28,7 @@ class CustomerController extends Controller { $id = Auth::id(); $data['customer'] = Customers::get($id, 'addresses')->toArray(); + return view('Shop.Customers.edit', $data); } @@ -33,6 +36,7 @@ class CustomerController extends Controller { $data = $request->all(); $customer = Customers::store($data); + return response()->json(['error' => 0]); } } diff --git a/app/Models/Shop/Delivery.php b/app/Models/Shop/Delivery.php index 8912b100..a9b368f2 100644 --- a/app/Models/Shop/Delivery.php +++ b/app/Models/Shop/Delivery.php @@ -42,9 +42,14 @@ class Delivery extends Model return $this->belongsTo(SaleChannel::class); } - public function scopeActive() + public function scopeActive($query) { - return $this->byActive(1); + return $query->byActive(1); + } + + public function scopeInactive($query) + { + return $query->byActive(0); } public function scopeByActive($query, $active) @@ -62,18 +67,13 @@ class Delivery extends Model return $query->where($this->table.'.at_house', 1); } - public function scopeInactive() + public function scopeManaged($query) { - return $this->byActive(0); + return $query->byPublic(0); } - public function scopeManaged() + public function scopePublic($query) { - return $this->byPublic(0); - } - - public function scopePublic() - { - return $this->byPublic(1); + return $query->byPublic(1); } } diff --git a/app/Repositories/Shop/Customers.php b/app/Repositories/Shop/Customers.php index 2cbdd089..125b8af5 100644 --- a/app/Repositories/Shop/Customers.php +++ b/app/Repositories/Shop/Customers.php @@ -5,16 +5,14 @@ namespace App\Repositories\Shop; use App\Datatables\Shop\CustomerOrdersDataTable; use App\Models\Shop\Customer; use App\Repositories\Core\File; +use App\Traits\Model\Basic; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Str; use Laravolt\Avatar\Avatar; class Customers { - public static function count() - { - return Customer::count(); - } + use Basic; public static function getOptions() { @@ -24,11 +22,11 @@ class Customers public static function editProfile($id = false) { $id = $id ? $id : self::getId(); - $orders_datatable = new CustomerOrdersDataTable(); + $datatableOrders = new CustomerOrdersDataTable(); $data = [ - 'customer' => self::get($id, ['addresses', 'deliveries', 'orders'])->toArray(), - 'deliveries' => Deliveries::getAll('sale_channel')->toArray(), - 'orders' => $orders_datatable->html(), + 'customer' => self::get($id, ['addresses', 'deliveries'])->toArray(), + 'deliveries' => Deliveries::getAllWithSaleChannel()->toArray(), + 'orders' => $datatableOrders->html(), ]; return $data; @@ -111,13 +109,6 @@ class Customers return self::guard()->check(); } - public static function get($id = false, $relations = false) - { - $id = $id ? $id : self::getId(); - - return $id ? ($relations ? Customer::with($relations)->findOrFail($id) : Customer::findOrFail($id)) : false; - } - public static function edit($id) { $customer = self::get($id, 'addresses'); @@ -140,11 +131,6 @@ class Customers return $customer->id; } - public static function store($data) - { - return ($data['id'] ?? false) ? self::update($data) : self::create($data); - } - public static function storeDeliveries($customer, $deliveries) { if (! $deliveries) { @@ -188,20 +174,6 @@ class Customers return $user; } - public static function update($data, $id = false) - { - $id = $id ? $id : $data['id']; - $customer = self::get($id); - $customer->update($data); - - return $customer; - } - - public static function delete($id) - { - return Customer::destroy($id); - } - public static function getStorage($filename = false) { $path = '/app/public/Customers/'; @@ -220,4 +192,9 @@ class Customers { return Auth::guard('customer'); } + + public static function getModel() + { + return Customer::query(); + } } diff --git a/app/Repositories/Shop/Deliveries.php b/app/Repositories/Shop/Deliveries.php index 7e59d8c1..5187edb1 100644 --- a/app/Repositories/Shop/Deliveries.php +++ b/app/Repositories/Shop/Deliveries.php @@ -3,12 +3,15 @@ namespace App\Repositories\Shop; use App\Models\Shop\Delivery; +use App\Traits\Model\Basic; class Deliveries { + use Basic; + public static function getOptions() { - return Delivery::orderBy('name', 'asc')->get()->pluck('name', 'id')->toArray(); + return Delivery::orderBy('name', 'asc')->pluck('name', 'id')->toArray(); } public static function getAll($relations = false) @@ -23,40 +26,13 @@ class Deliveries return Delivery::orderBy('name', 'asc')->active()->public()->with('sale_channel')->get(); } - public static function get($id) - { - return Delivery::find($id); - } - - public static function store($data) - { - $id = $data['id'] ?? false; - $item = $id ? self::update($data, $id) : self::create($data); - - return $item->id; - } - - public static function create($data) - { - return Delivery::create($data); - } - - public static function update($data, $id = false) - { - $id = $id ? $id : $data['id']; - $delivery = self::get($id); - $delivery->update($data); - - return $delivery; - } - - public static function destroy($id) - { - return Delivery::destroy($id); - } - public static function toggle_active($id, $active) { return self::update(['active' => $active], $id); } + + public static function getModel() + { + return Delivery::query(); + } } diff --git a/resources/views/Shop/Baskets/basket.blade.php b/resources/views/Shop/Baskets/basket.blade.php index 77ecfd92..3bda5fe2 100644 --- a/resources/views/Shop/Baskets/basket.blade.php +++ b/resources/views/Shop/Baskets/basket.blade.php @@ -5,7 +5,7 @@ @section('content') @if ($basket)
-
+

Panier

@@ -27,7 +27,7 @@
@endforeach
-
+
@include('Shop.Baskets.partials.basketTotal')
@@ -108,7 +108,7 @@ } function calculateTotalShipped() { - var total_shipped = parseFloat($('#basket-total').html()) + 5; + var total_shipped = parseFloat($('#basket-total').html()); $('#basket-total-shipped').html(fixNumber(total_shipped)); } diff --git a/resources/views/Shop/Baskets/partials/basketTotal.blade.php b/resources/views/Shop/Baskets/partials/basketTotal.blade.php index e2c92f4f..7dfd274a 100644 --- a/resources/views/Shop/Baskets/partials/basketTotal.blade.php +++ b/resources/views/Shop/Baskets/partials/basketTotal.blade.php @@ -16,6 +16,7 @@ {{ $basket['total'] ?? 0 }}
+
TOTAL TTC
- {{ App\Repositories\Core\User\ShopCart::fixDecimal(($basket['total'] ?? 0) + 5) }} € + {{ App\Repositories\Core\User\ShopCart::fixDecimal(($basket['total'] ?? 0)) }}
\ No newline at end of file diff --git a/resources/views/Shop/Customers/partials/addresses.blade.php b/resources/views/Shop/Customers/partials/addresses.blade.php index 8bdbf6a5..b9cfedf0 100644 --- a/resources/views/Shop/Customers/partials/addresses.blade.php +++ b/resources/views/Shop/Customers/partials/addresses.blade.php @@ -5,10 +5,10 @@
{{ $address['address'] }}
- @if ($address['address2']) + @if ($address['address2']) {{ $address['address2'] }}
@endif - {{ $address['zipcode'] }} {{ $address['city'] }} + {{ $address['zipcode'] }} {{ $address['city'] }}
@endforeach diff --git a/resources/views/Shop/Orders/order.blade.php b/resources/views/Shop/Orders/order.blade.php index 2d6a34bb..c0276c0b 100644 --- a/resources/views/Shop/Orders/order.blade.php +++ b/resources/views/Shop/Orders/order.blade.php @@ -11,7 +11,7 @@

- + @include('Shop.auth.partials.login')