fix orders datatables on profile, fix deliveries for profile (public & active)

This commit is contained in:
Ludovic CANDELLIER
2023-08-29 22:15:37 +02:00
parent 7addea00a2
commit 496274b4f4
10 changed files with 60 additions and 91 deletions

View File

@@ -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'),

View File

@@ -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);
}

View File

@@ -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]);
}
}

View File

@@ -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);
}
}

View File

@@ -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();
}
}

View File

@@ -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();
}
}

View File

@@ -5,7 +5,7 @@
@section('content')
@if ($basket)
<div class="row">
<div class="col-8">
<div class="col-lg-8 col-md-12">
<div class="row mb-3">
<div class="col-4">
<h1>Panier</h1>
@@ -27,7 +27,7 @@
</div>
@endforeach
</div>
<div class="col-4">
<div class="col-lg-4 col-md-12">
<x-card class='shadow'>
@include('Shop.Baskets.partials.basketTotal')
<div class="row m-3">
@@ -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));
}

View File

@@ -16,6 +16,7 @@
<span id="basket-total">{{ $basket['total'] ?? 0 }}</span>
</div>
</div>
<!--
<div class="row mb-3">
<div class="col-6">
LIVRAISON
@@ -25,11 +26,12 @@
</div>
</div>
<hr>
-->
<div class="row mb-3 font-weight-bold" style="font-size: 1.6em;">
<div class="col-6">
TOTAL TTC
</div>
<div class="col-6 text-right">
<span id="basket-total-shipped">{{ App\Repositories\Core\User\ShopCart::fixDecimal(($basket['total'] ?? 0) + 5) }}</span>
<span id="basket-total-shipped">{{ App\Repositories\Core\User\ShopCart::fixDecimal(($basket['total'] ?? 0)) }}</span>
</div>
</div>

View File

@@ -5,10 +5,10 @@
</div>
<div class="col-11">
{{ $address['address'] }}<br/>
@if ($address['address2'])
@if ($address['address2'])
{{ $address['address2'] }}<br/>
@endif
{{ $address['zipcode'] }} {{ $address['city'] }}
{{ $address['zipcode'] }} {{ $address['city'] }}
</div>
</div>
@endforeach

View File

@@ -11,7 +11,7 @@
<button class="btn btn-secondary" id="register">Créez mon compte</button>
</p>
<x-layout.collapse id="identification" title="Déjà client" class="d-none identification rounded-lg">
<x-layout.collapse id="identification" title="Déjà client" class="identification rounded-lg" uncollapsed=true>
@include('Shop.auth.partials.login')
</x-layout.collapse>