change homepages to contents, add new methods to deliveries and sale_channels by customer

This commit is contained in:
ludo
2023-12-09 23:55:50 +01:00
parent 2a429e4163
commit 25b78f3380
28 changed files with 185 additions and 153 deletions

View File

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

View File

@@ -111,7 +111,6 @@ class Baskets
'latin' => $offer->article->product->specie->latin ?? false,
];
}
$data['sale_channel'] = Customers::getSaleChannel();
return $data ?? false;
}

View File

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

View File

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

View File

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