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();
|
||||
|
||||
Reference in New Issue
Block a user