fixes
This commit is contained in:
@@ -5,11 +5,9 @@ namespace App\Repositories\Shop;
|
||||
use App\Datatables\Shop\CustomerInvoicesDataTable;
|
||||
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
|
||||
{
|
||||
@@ -32,20 +30,24 @@ class Customers
|
||||
public static function getSaleChannels($customerId = false)
|
||||
{
|
||||
$customer = $customerId ? self::get($customerId) : self::getAuth();
|
||||
$saleChannels = $customer ? $customer->sale_channels : false;
|
||||
|
||||
return $customer ? $customer->sale_channels : SaleChannels::getDefault();
|
||||
return $saleChannels ? $saleChannels : SaleChannels::getDefault();
|
||||
}
|
||||
|
||||
public static function getSaleChannel()
|
||||
public static function getSaleChannel($customerId = false)
|
||||
{
|
||||
return SaleChannels::getDefault();
|
||||
$saleChannels = self::getSaleChannels($customerId);
|
||||
|
||||
return $saleChannels->first();
|
||||
}
|
||||
|
||||
public static function getDeliveries()
|
||||
{
|
||||
$customer = self::getAuth();
|
||||
$deliveries = $customer ? $customer->deliveries : false;
|
||||
|
||||
return $customer ? $customer->deliveries : Deliveries::getDefault();
|
||||
return $deliveries ? $deliveries : [Deliveries::getDefault()];
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
@@ -63,48 +65,6 @@ class Customers
|
||||
] : abort('403');
|
||||
}
|
||||
|
||||
public static function getAvatar($id = false)
|
||||
{
|
||||
$customer = $id ? self::get($id) : self::getAuth();
|
||||
$file = self::makeAvatarFilename($customer);
|
||||
if (!File::checkFile($file)) {
|
||||
self::createAvatar($customer);
|
||||
}
|
||||
|
||||
return self::getPublic(self::getAvatarFilename($customer));
|
||||
}
|
||||
|
||||
public static function createAvatar($customer)
|
||||
{
|
||||
$filename = self::makeAvatarFilename($customer);
|
||||
$name = $customer->first_name . ' ' . $customer->last_name;
|
||||
$avatar = new Avatar();
|
||||
|
||||
return $avatar->create($name)
|
||||
->setBackground('#F2B90F')
|
||||
->setForeground('#335012')
|
||||
->setBorder(1, '#28a745')
|
||||
->setFontFamily('Roboto Condensed')
|
||||
->setDimension(36)
|
||||
->setFontSize(16)
|
||||
->save($filename);
|
||||
}
|
||||
|
||||
public static function makeAvatarFilename($customer)
|
||||
{
|
||||
$path = storage_path(self::getStorage());
|
||||
if (File::checkDirOrCreate($path)) {
|
||||
$filename = $path . self::getAvatarFilename($customer);
|
||||
}
|
||||
|
||||
return $filename ?? false;
|
||||
}
|
||||
|
||||
public static function getAvatarFilename($customer)
|
||||
{
|
||||
return 'user-' . $customer->uuid . '.png';
|
||||
}
|
||||
|
||||
public static function getAddresses($id = false)
|
||||
{
|
||||
$customer = self::getWithAddresses($id);
|
||||
@@ -126,26 +86,6 @@ class Customers
|
||||
return $user ? $user->name : '';
|
||||
}
|
||||
|
||||
public static function getAuth()
|
||||
{
|
||||
return self::guard()->user();
|
||||
}
|
||||
|
||||
public static function getId()
|
||||
{
|
||||
return self::guard()->id();
|
||||
}
|
||||
|
||||
public static function isNotConnected()
|
||||
{
|
||||
return !self::isConnected();
|
||||
}
|
||||
|
||||
public static function isConnected()
|
||||
{
|
||||
return self::guard()->check();
|
||||
}
|
||||
|
||||
public static function edit($id)
|
||||
{
|
||||
if (!$id) {
|
||||
@@ -178,14 +118,9 @@ class Customers
|
||||
return $customer->id;
|
||||
}
|
||||
|
||||
public static function storeDeliveries($customer, $deliveries)
|
||||
public static function storeDeliveries($customerId, $deliveries)
|
||||
{
|
||||
if (!$deliveries) {
|
||||
return false;
|
||||
}
|
||||
$deliveries = collect($deliveries)->transform(function ($item) {
|
||||
return (int) $item;
|
||||
})->toArray();
|
||||
$customer = self::get($customerId);
|
||||
|
||||
return $customer->deliveries()->sync($deliveries);
|
||||
}
|
||||
@@ -200,18 +135,9 @@ class Customers
|
||||
|
||||
public static function storeSaleChannels($customerId, $saleChannels)
|
||||
{
|
||||
$oldSaleChannels = self::getSaleChannelIds($customerId);
|
||||
$deleteSaleChannels = array_diff($oldSaleChannels, $saleChannels);
|
||||
$newSaleChannels = array_diff($saleChannels, $oldSaleChannels);
|
||||
$customer = self::get($customerId);
|
||||
|
||||
$data = ['customer_id' => $customerId];
|
||||
foreach ($newSaleChannels as $saleChannelId) {
|
||||
$data['sale_channel_id'] = $saleChannelId;
|
||||
CustomerSaleChannels::store($data);
|
||||
}
|
||||
foreach ($deleteSaleChannels as $saleChannelId) {
|
||||
CustomerSaleChannels::destroyByCustomerAndSaleChannel($customerId, $saleChannelId);
|
||||
}
|
||||
return $customer->sale_channels()->sync($saleChannels);
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
@@ -223,18 +149,24 @@ class Customers
|
||||
return Customer::create($data);
|
||||
}
|
||||
|
||||
public static function getStorage($filename = false)
|
||||
public static function getAuth()
|
||||
{
|
||||
$path = '/app/public/Customers/';
|
||||
|
||||
return $filename ? $path . $filename : $path;
|
||||
return self::guard()->user();
|
||||
}
|
||||
|
||||
public static function getPublic($filename = false)
|
||||
public static function getId()
|
||||
{
|
||||
$path = '/storage/Customers/';
|
||||
return self::guard()->id();
|
||||
}
|
||||
|
||||
return $filename ? $path . $filename : $path;
|
||||
public static function isNotConnected()
|
||||
{
|
||||
return !self::isConnected();
|
||||
}
|
||||
|
||||
public static function isConnected()
|
||||
{
|
||||
return self::guard()->check();
|
||||
}
|
||||
|
||||
public static function guard()
|
||||
|
||||
Reference in New Issue
Block a user