change homepages to contents, add new methods to deliveries and sale_channels by customer
This commit is contained in:
@@ -3,14 +3,14 @@
|
||||
namespace App\Datatables\Admin\Shop;
|
||||
|
||||
use App\Datatables\ParentDataTable as DataTable;
|
||||
use App\Models\Shop\Homepage;
|
||||
use App\Models\Shop\Content;
|
||||
use Yajra\DataTables\Html\Column;
|
||||
|
||||
class HomepagesDataTable extends DataTable
|
||||
class ContentsDataTable extends DataTable
|
||||
{
|
||||
public $model_name = 'homepages';
|
||||
public $model_name = 'contents';
|
||||
|
||||
public function query(Homepage $model)
|
||||
public function query(Content $model)
|
||||
{
|
||||
return $this->buildQuery($model);
|
||||
}
|
||||
44
app/Http/Controllers/Admin/Shop/ContentController.php
Normal file
44
app/Http/Controllers/Admin/Shop/ContentController.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin\Shop;
|
||||
|
||||
use App\Datatables\Admin\Shop\ContentsDataTable;
|
||||
use App\Repositories\Shop\Contents;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ContentController extends Controller
|
||||
{
|
||||
public function index(ContentsDataTable $dataTable)
|
||||
{
|
||||
return $dataTable->render('Admin.Shop.Contents.list', $data ?? []);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
return view('Admin.Shop.Contents.create', $data ?? []);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$ret = Contents::store($request->all());
|
||||
|
||||
return redirect()->route('Admin.Shop.Contents.index');
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
return view('Admin.Shop.Contents.view', $data ?? []);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$data['homepage'] = Contents::get($id);
|
||||
|
||||
return view('Admin.Shop.Contents.edit', $data);
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
return Contents::destroy($id);
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin\Shop;
|
||||
|
||||
use App\Datatables\Admin\Shop\HomepagesDataTable;
|
||||
use App\Repositories\Shop\Homepages;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class HomepageController extends Controller
|
||||
{
|
||||
public function index(HomepagesDataTable $dataTable)
|
||||
{
|
||||
return $dataTable->render('Admin.Shop.Homepages.list', $data ?? []);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
return view('Admin.Shop.Homepages.create', $data ?? []);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$ret = Homepages::store($request->all());
|
||||
|
||||
return redirect()->route('Admin.Shop.Homepages.index');
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
return view('Admin.Shop.Homepages.view', $data ?? []);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$data['homepage'] = Homepages::get($id);
|
||||
|
||||
return view('Admin.Shop.Homepages.edit', $data);
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
return Homepages::destroy($id);
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,8 @@ namespace App\Http\Controllers\Shop;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Repositories\Core\User\ShopCart;
|
||||
use App\Repositories\Shop\Baskets;
|
||||
use App\Repositories\Shop\Contents;
|
||||
use App\Repositories\Shop\Customers;
|
||||
use App\Repositories\Shop\Offers;
|
||||
use App\Repositories\Shop\Orders;
|
||||
use App\Repositories\Users;
|
||||
@@ -45,6 +47,8 @@ class BasketController extends Controller
|
||||
{
|
||||
$data = [
|
||||
'basket' => Baskets::getBasket(),
|
||||
'sale_channel' => Customers::getSaleChannel(),
|
||||
'header' => Contents::getBasketContent(),
|
||||
];
|
||||
|
||||
return view('Shop.Baskets.basket', $data);
|
||||
|
||||
@@ -13,8 +13,8 @@ class Contents
|
||||
->order(6);
|
||||
|
||||
$menu->addTo('contents', 'Contenus', [
|
||||
'route' => 'Admin.Shop.Homepages.index',
|
||||
])->activeIfRoute(['Admin.Shop.Homepages.*'])->order(1);
|
||||
'route' => 'Admin.Shop.Contents.index',
|
||||
])->activeIfRoute(['Admin.Shop.Contents.*'])->order(1);
|
||||
|
||||
$menu->addTo('contents', 'Template de Mails', [
|
||||
'route' => 'Admin.Core.Mail.MailTemplate.index',
|
||||
|
||||
@@ -18,7 +18,6 @@ use Kirschbaum\PowerJoins\PowerJoins;
|
||||
use Rinvex\Categories\Traits\Categorizable;
|
||||
use Rinvex\Tags\Traits\Taggable;
|
||||
use Spatie\MediaLibrary\HasMedia;
|
||||
use Staudenmeir\EloquentHasManyDeep\HasManyDeep;
|
||||
use Staudenmeir\EloquentHasManyDeep\HasRelationships;
|
||||
use Venturecraft\Revisionable\RevisionableTrait;
|
||||
use Wildside\Userstamps\Userstamps;
|
||||
|
||||
@@ -4,9 +4,9 @@ namespace App\Models\Shop;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Homepage extends Model
|
||||
class Content extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
|
||||
protected $table = 'shop_homepages';
|
||||
protected $table = 'shop_contents';
|
||||
}
|
||||
@@ -7,11 +7,13 @@ use App\Notifications\VerifyEmail;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Venturecraft\Revisionable\RevisionableTrait;
|
||||
use Staudenmeir\EloquentHasManyDeep\HasRelationships;
|
||||
use Yadahan\AuthenticationLog\AuthenticationLogable;
|
||||
|
||||
class Customer extends Authenticatable
|
||||
{
|
||||
use AuthenticationLogable, Notifiable, SoftDeletes;
|
||||
use AuthenticationLogable, HasRelationships, Notifiable, RevisionableTrait, SoftDeletes;
|
||||
|
||||
protected $guarded = ['id'];
|
||||
|
||||
@@ -48,7 +50,10 @@ class Customer extends Authenticatable
|
||||
|
||||
public function deliveries()
|
||||
{
|
||||
return $this->belongsToMany(Delivery::class, CustomerDelivery::class);
|
||||
return $this->hasManyDeepFromRelations(
|
||||
$this->sale_channels(),
|
||||
(new SaleChannel())->deliveries())
|
||||
->whereNull('shop_customer_sale_channels.deleted_at');
|
||||
}
|
||||
|
||||
public function sale_channels()
|
||||
@@ -66,6 +71,11 @@ class Customer extends Authenticatable
|
||||
return $this->hasMany(Order::class);
|
||||
}
|
||||
|
||||
public function scopeById($query, $id)
|
||||
{
|
||||
return $query->where($this->table.'.id', $id);
|
||||
}
|
||||
|
||||
public function scopeBySaleChannel($query, $saleChannelId)
|
||||
{
|
||||
return $query->whereHas('sale_channels', function ($query) use ($saleChannelId) {
|
||||
|
||||
@@ -4,12 +4,13 @@ namespace App\Models\Shop;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Staudenmeir\EloquentHasManyDeep\HasRelationships;
|
||||
use Venturecraft\Revisionable\RevisionableTrait;
|
||||
use Wildside\Userstamps\Userstamps;
|
||||
|
||||
class Delivery extends Model
|
||||
{
|
||||
use RevisionableTrait, SoftDeletes, Userstamps;
|
||||
use HasRelationships, RevisionableTrait, SoftDeletes, Userstamps;
|
||||
|
||||
protected $guarded = ['id'];
|
||||
|
||||
@@ -34,7 +35,7 @@ class Delivery extends Model
|
||||
|
||||
public function customers()
|
||||
{
|
||||
return $this->hasMany(Customer::class);
|
||||
return $this->hasManyThrough(Customer::class, CustomerSaleChannel::class);
|
||||
}
|
||||
|
||||
public function sale_channel()
|
||||
@@ -67,6 +68,11 @@ class Delivery extends Model
|
||||
return $query->where($this->table.'.at_house', 1);
|
||||
}
|
||||
|
||||
public function scopeBySaleChannels($query, $ids)
|
||||
{
|
||||
return $query->whereIn($this->table.'.sale_channel_id', $ids);
|
||||
}
|
||||
|
||||
public function scopeBySaleChannel($query)
|
||||
{
|
||||
return $query->where($this->table.'.sale_channel_id', 1);
|
||||
@@ -81,4 +87,11 @@ class Delivery extends Model
|
||||
{
|
||||
return $query->byPublic(1);
|
||||
}
|
||||
|
||||
public function scopeByCustomer($query, $customerId)
|
||||
{
|
||||
return $query->whereHas('customers', function($query) use ($customerId) {
|
||||
return $query->byId($customerId);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,12 +3,9 @@
|
||||
namespace App\Models\Shop;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Staudenmeir\EloquentHasManyDeep\HasRelationships;
|
||||
|
||||
class Price extends Model
|
||||
{
|
||||
use HasRelationships;
|
||||
|
||||
protected $guarded = ['id'];
|
||||
|
||||
protected $table = 'shop_prices';
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Repositories\Shop\Categories;
|
||||
use App\Repositories\Shop\Homepages;
|
||||
use App\Repositories\Shop\Contents;
|
||||
|
||||
class Config
|
||||
{
|
||||
@@ -12,8 +12,8 @@ class Config
|
||||
return [
|
||||
'auth' => Users::getUser() ? Users::getInfo() : false,
|
||||
'categories' => Categories::getTreeVisibles(),
|
||||
'footer' => Homepages::getFooter(),
|
||||
'extra_footer' => Homepages::getExtraFooter(),
|
||||
'footer' => Contents::getFooter(),
|
||||
'extra_footer' => Contents::getExtraFooter(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,7 +111,6 @@ class Baskets
|
||||
'latin' => $offer->article->product->specie->latin ?? false,
|
||||
];
|
||||
}
|
||||
$data['sale_channel'] = Customers::getSaleChannel();
|
||||
|
||||
return $data ?? false;
|
||||
}
|
||||
|
||||
@@ -2,21 +2,21 @@
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\Homepage;
|
||||
use App\Models\Shop\Content;
|
||||
use App\Traits\Model\Basic;
|
||||
|
||||
class Homepages
|
||||
class Contents
|
||||
{
|
||||
use Basic;
|
||||
|
||||
public static function getLast()
|
||||
{
|
||||
$model = Homepage::latest('id')->first();
|
||||
$model = Content::latest('id')->first();
|
||||
|
||||
return $model ? $model->text : '';
|
||||
}
|
||||
|
||||
public static function getHomepage()
|
||||
public static function getContent()
|
||||
{
|
||||
return self::get(1)->text ?? '';
|
||||
}
|
||||
@@ -31,8 +31,13 @@ class Homepages
|
||||
return self::get(3)->text ?? '';
|
||||
}
|
||||
|
||||
public static function getBasketContent()
|
||||
{
|
||||
return self::get(4)->text ?? '';
|
||||
}
|
||||
|
||||
public static function getModel()
|
||||
{
|
||||
return Homepage::query();
|
||||
return Content::query();
|
||||
}
|
||||
}
|
||||
@@ -153,6 +153,7 @@ class Customers
|
||||
$customer = self::get($id, ['delivery_addresses', 'invoice_addresses', 'sale_channels']);
|
||||
$data = $customer->toArray();
|
||||
$data['sale_channels'] = $customer->sale_channels->pluck('id')->toArray();
|
||||
$data['deliveries'] = Deliveries::getBySaleChannels($data['sale_channels'])->toArray();
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\Delivery;
|
||||
use App\Repositories\Shop\Customers;
|
||||
use App\Traits\Model\Basic;
|
||||
|
||||
class Deliveries
|
||||
@@ -16,6 +17,19 @@ class Deliveries
|
||||
];
|
||||
}
|
||||
|
||||
public static function getByCustomer($customerId = false)
|
||||
{
|
||||
$customer = Customers::get($customerId);
|
||||
$saleChannels = $customer->sale_channels->pluck('id')->toArray();
|
||||
|
||||
return self::getBySaleChannels($saleChannels);
|
||||
}
|
||||
|
||||
public static function getBySaleChannels($saleChannels)
|
||||
{
|
||||
return Delivery::bySaleChannels($saleChannels)->get();
|
||||
}
|
||||
|
||||
public static function getSaleChannelId($deliveryId)
|
||||
{
|
||||
return $deliveryId ? Deliveries::getField($deliveryId, 'sale_channel_id') : SaleChannels::getDefaultID();
|
||||
@@ -26,18 +40,6 @@ class Deliveries
|
||||
return Delivery::active()->atHouse()->first();
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return Delivery::orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getAll($relations = false)
|
||||
{
|
||||
$model = $relations ? Delivery::with($relations) : Delivery::query();
|
||||
|
||||
return $model->orderBy('name', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function getAllWithSaleChannel()
|
||||
{
|
||||
return Delivery::orderBy('name', 'asc')->active()->public()->with('sale_channel')->get();
|
||||
|
||||
14
resources/views/Admin/Shop/Contents/create.blade.php
Normal file
14
resources/views/Admin/Shop/Contents/create.blade.php
Normal file
@@ -0,0 +1,14 @@
|
||||
@extends('layout.index', [
|
||||
'title' => __('Contenus'),
|
||||
'subtitle' => __('Ajouter un contenu'),
|
||||
])
|
||||
|
||||
@section('content')
|
||||
{{ Form::open([
|
||||
'route' => 'Admin.Shop.Contents.store',
|
||||
'id' => 'homepage-form',
|
||||
'autocomplete' => 'off',
|
||||
]) }}
|
||||
@include('Admin.Shop.Contents.form')
|
||||
</form>
|
||||
@endsection
|
||||
11
resources/views/Admin/Shop/Contents/edit.blade.php
Normal file
11
resources/views/Admin/Shop/Contents/edit.blade.php
Normal file
@@ -0,0 +1,11 @@
|
||||
@extends('layout.index', [
|
||||
'title' => __('Contenus'),
|
||||
'subtitle' => __('Editer un contenu'),
|
||||
])
|
||||
|
||||
@section('content')
|
||||
{{ Form::open(['route' => 'Admin.Shop.Contents.store', 'id' => 'content-form', 'autocomplete' => 'off']) }}
|
||||
<input type="hidden" name="id" value="{{ $content['id'] }}">
|
||||
@include('Admin.Shop.Contents.form')
|
||||
</form>
|
||||
@endsection
|
||||
23
resources/views/Admin/Shop/Contents/form.blade.php
Normal file
23
resources/views/Admin/Shop/Contents/form.blade.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
@include('components.form.editor', [
|
||||
'name' => 'text',
|
||||
'value' => $content['text'] ?? '',
|
||||
'rows' => 10,
|
||||
])
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<x-save />
|
||||
|
||||
@include('load.form.save')
|
||||
@include('load.form.editor')
|
||||
|
||||
@push('js')
|
||||
<script>
|
||||
$(function() {
|
||||
initEditor();
|
||||
initSaveForm('#homepage-form');
|
||||
});
|
||||
</script>
|
||||
@endpush
|
||||
13
resources/views/Admin/Shop/Contents/list.blade.php
Normal file
13
resources/views/Admin/Shop/Contents/list.blade.php
Normal file
@@ -0,0 +1,13 @@
|
||||
@extends('layout.index', [
|
||||
'title' => __('Contenus'),
|
||||
'subtitle' => __('Liste des contenus'),
|
||||
])
|
||||
|
||||
@section('content')
|
||||
<x-card>
|
||||
@include('components.datatable', [
|
||||
'route' => route('Admin.Shop.Contents.index'),
|
||||
'model' => 'contents',
|
||||
])
|
||||
</x-card>
|
||||
@endsection
|
||||
@@ -1,10 +0,0 @@
|
||||
@extends('layout.index', [
|
||||
'title' => __('Contenus'),
|
||||
'subtitle' => __('Ajouter un contenu'),
|
||||
])
|
||||
|
||||
@section('content')
|
||||
{{ Form::open(['route' => 'Admin.Shop.Homepages.store', 'id' => 'homepage-form', 'autocomplete' => 'off']) }}
|
||||
@include('Admin.Shop.Homepages.form')
|
||||
</form>
|
||||
@endsection
|
||||
@@ -1,13 +0,0 @@
|
||||
@extends('layout.index', [
|
||||
'title' => __('Contenus'),
|
||||
'subtitle' => __('Editer un contenu'),
|
||||
])
|
||||
|
||||
@section('content')
|
||||
|
||||
{{ Form::open(['route' => 'Admin.Shop.Homepages.store', 'id' => 'homepage-form', 'autocomplete' => 'off']) }}
|
||||
<input type="hidden" name="id" value="{{ $homepage['id'] }}">
|
||||
@include('Admin.Shop.Homepages.form')
|
||||
</form>
|
||||
|
||||
@endsection
|
||||
@@ -1,23 +0,0 @@
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
@include('components.form.editor', [
|
||||
'name' => 'text',
|
||||
'value' => $homepage['text'] ?? '',
|
||||
'rows' => 10,
|
||||
])
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@include('components.save')
|
||||
|
||||
@include('load.form.save')
|
||||
@include('load.form.editor')
|
||||
|
||||
@push('js')
|
||||
<script>
|
||||
$(function() {
|
||||
initEditor();
|
||||
initSaveForm('#homepage-form');
|
||||
});
|
||||
</script>
|
||||
@endpush
|
||||
@@ -1,10 +0,0 @@
|
||||
@extends('layout.index', [
|
||||
'title' => __('Contenus'),
|
||||
'subtitle' => __('Liste des contenus'),
|
||||
])
|
||||
|
||||
@section('content')
|
||||
@component('components.card')
|
||||
@include('components.datatable', ['route' => route('Admin.Shop.Homepages.index'), 'model' => 'homepages'])
|
||||
@endcomponent
|
||||
@endsection
|
||||
@@ -11,10 +11,7 @@
|
||||
<h1>Panier</h1>
|
||||
</div>
|
||||
<div class="col-8">
|
||||
Livraison à domicile ...<br>
|
||||
Commande en ligne et livraison par voie postale. Attention certains produits ne sont pas disponibles
|
||||
en livraison.
|
||||
Les sachets disponibles en lignes sont disponibles à la livraison et uniquement quelques plants.
|
||||
{!! $header ?? '' !!}
|
||||
</div>
|
||||
</div>
|
||||
@foreach ($basket as $nature => $items)
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
</div>
|
||||
<div class="col-6 text-right font-weight-bold">
|
||||
<span id="basket_sale_channel">
|
||||
{{ $basket['sale_channel']['name'] ?? null }}
|
||||
{{ $sale_channel['name'] ?? null }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
10
routes/Admin/Shop/Contents.php
Normal file
10
routes/Admin/Shop/Contents.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
Route::prefix('Contents')->name('Contents.')->group(function () {
|
||||
Route::get('', 'ContentController@index')->name('index');
|
||||
Route::get('create', 'ContentController@create')->name('create');
|
||||
Route::delete('destroy/{id?}', 'ContentController@destroy')->name('destroy');
|
||||
Route::post('update', 'ContentController@update')->name('update');
|
||||
Route::post('store', 'ContentController@store')->name('store');
|
||||
Route::get('edit/{id}', 'ContentController@edit')->name('edit');
|
||||
});
|
||||
@@ -1,10 +0,0 @@
|
||||
<?php
|
||||
|
||||
Route::prefix('Homepages')->name('Homepages.')->group(function () {
|
||||
Route::get('', 'HomepageController@index')->name('index');
|
||||
Route::get('create', 'HomepageController@create')->name('create');
|
||||
Route::delete('destroy/{id?}', 'HomepageController@destroy')->name('destroy');
|
||||
Route::post('update', 'HomepageController@update')->name('update');
|
||||
Route::post('store', 'HomepageController@store')->name('store');
|
||||
Route::get('edit/{id}', 'HomepageController@edit')->name('edit');
|
||||
});
|
||||
@@ -5,13 +5,13 @@ Route::middleware('auth')->prefix('Shop')->namespace('Shop')->name('Shop.')->gro
|
||||
include_once __DIR__.'/ArticleNatures.php';
|
||||
include_once __DIR__.'/Articles.php';
|
||||
include_once __DIR__.'/Categories.php';
|
||||
include_once __DIR__.'/Contents.php';
|
||||
include_once __DIR__.'/Customers.php';
|
||||
include_once __DIR__.'/CustomerAddresses.php';
|
||||
include_once __DIR__.'/Deliveries.php';
|
||||
include_once __DIR__.'/DeliveryPackages.php';
|
||||
include_once __DIR__.'/DeliveryTypes.php';
|
||||
include_once __DIR__.'/DeliveryTypeCalculations.php';
|
||||
include_once __DIR__.'/Homepages.php';
|
||||
include_once __DIR__.'/InvoiceItems.php';
|
||||
include_once __DIR__.'/InvoicePayments.php';
|
||||
include_once __DIR__.'/Invoices.php';
|
||||
|
||||
Reference in New Issue
Block a user