Files
opensem/app/Repositories/Shop/Deliveries.php
2024-01-07 20:42:37 +01:00

57 lines
1.4 KiB
PHP

<?php
namespace App\Repositories\Shop;
use App\Models\Shop\Delivery;
use App\Traits\Model\Basic;
class Deliveries
{
use Basic;
public static function init()
{
return [
'sale_channels' => SaleChannels::getOptions(),
];
}
public static function getByCustomer($customerId = false)
{
$customer = $customerId ? Customers::get($customerId) : Customers::getAuth();
$saleChannels = $customer ? $customer->sale_channels->pluck('id')->toArray() : false;
return $saleChannels ? self::getBySaleChannels($saleChannels) : false;
}
public static function getBySaleChannels($saleChannels)
{
return Delivery::bySaleChannels($saleChannels)->with('sale_channel')->get();
}
public static function getSaleChannelId($deliveryId)
{
return $deliveryId ? Deliveries::getField($deliveryId, 'sale_channel_id') : SaleChannels::getDefaultID();
}
public static function getDefault()
{
return Delivery::active()->atHouse()->first();
}
public static function getAllWithSaleChannel()
{
return Delivery::orderBy('name', 'asc')->active()->public()->with('sale_channel')->get();
}
public static function toggleActive($id, $active)
{
return self::update(['active' => $active], $id);
}
public static function getModel()
{
return Delivery::query();
}
}