add shipping rules
This commit is contained in:
@@ -3,14 +3,12 @@
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Datatables\Shop\CustomerOrdersDataTable;
|
||||
use App\Models\Shop\Customer;
|
||||
use App\Repositories\Core\File;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
use Laravolt\Avatar\Avatar;
|
||||
|
||||
use App\Repositories\Core\File;
|
||||
use App\Models\Shop\Customer;
|
||||
|
||||
class Customers
|
||||
{
|
||||
public static function count()
|
||||
@@ -32,6 +30,7 @@ class Customers
|
||||
'deliveries' => Deliveries::getAll('sale_channel')->toArray(),
|
||||
'orders' => $orders_datatable->html(),
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
@@ -39,16 +38,17 @@ class Customers
|
||||
{
|
||||
$customer = $id ? self::get($id) : self::getAuth();
|
||||
$file = self::makeAvatarFilename($customer);
|
||||
if (!File::checkFile($file)) {
|
||||
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;
|
||||
$name = $customer->first_name.' '.$customer->last_name;
|
||||
$avatar = new Avatar();
|
||||
$ret = $avatar->create($name)
|
||||
->setBackground('#F2B90F')
|
||||
@@ -58,6 +58,7 @@ class Customers
|
||||
->setDimension(36)
|
||||
->setFontSize(16)
|
||||
->save($filename);
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
@@ -65,19 +66,21 @@ class Customers
|
||||
{
|
||||
$path = storage_path(self::getStorage());
|
||||
if (File::checkDirOrCreate($path)) {
|
||||
$filename = $path . self::getAvatarFilename($customer);
|
||||
$filename = $path.self::getAvatarFilename($customer);
|
||||
}
|
||||
|
||||
return $filename ?? false;
|
||||
}
|
||||
|
||||
public static function getAvatarFilename($customer)
|
||||
{
|
||||
return 'user-' . $customer->uuid . '.png';
|
||||
return 'user-'.$customer->uuid.'.png';
|
||||
}
|
||||
|
||||
public static function getAddresses($id = false)
|
||||
{
|
||||
$customer = self::getWithAddresses($id);
|
||||
|
||||
return $customer ? $customer->addresses : false;
|
||||
}
|
||||
|
||||
@@ -89,7 +92,8 @@ class Customers
|
||||
public static function getName($id = false)
|
||||
{
|
||||
$user = $id ? self::get($id) : self::getAuth();
|
||||
return $user ? $user->first_name . ' ' . $user->last_name : '';
|
||||
|
||||
return $user ? $user->first_name.' '.$user->last_name : '';
|
||||
}
|
||||
|
||||
public static function getAuth()
|
||||
@@ -110,6 +114,7 @@ class Customers
|
||||
public static function get($id = false, $relations = false)
|
||||
{
|
||||
$id = $id ? $id : self::getId();
|
||||
|
||||
return $id ? ($relations ? Customer::with($relations)->findOrFail($id) : Customer::findOrFail($id)) : false;
|
||||
}
|
||||
|
||||
@@ -118,6 +123,7 @@ class Customers
|
||||
$customer = self::get($id, 'addresses');
|
||||
$data = $customer->toArray();
|
||||
$data['deliveries'] = $customer->deliveries->pluck('id')->toArray();
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
@@ -130,6 +136,7 @@ class Customers
|
||||
$customer = self::store($data);
|
||||
self::storeDeliveries($customer, $deliveries);
|
||||
self::storeAddresses($customer, $addresses);
|
||||
|
||||
return $customer->id;
|
||||
}
|
||||
|
||||
@@ -140,7 +147,7 @@ class Customers
|
||||
|
||||
public static function storeDeliveries($customer, $deliveries)
|
||||
{
|
||||
if (!$deliveries) {
|
||||
if (! $deliveries) {
|
||||
return false;
|
||||
}
|
||||
$deliveries = collect($deliveries)->transform(
|
||||
@@ -148,6 +155,7 @@ class Customers
|
||||
return (int) $item;
|
||||
}
|
||||
)->toArray();
|
||||
|
||||
return $customer->deliveries()->sync($deliveries);
|
||||
}
|
||||
|
||||
@@ -176,6 +184,7 @@ class Customers
|
||||
'email' => $data['email'],
|
||||
'password' => bcrypt($data['password']),
|
||||
]);
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
@@ -184,6 +193,7 @@ class Customers
|
||||
$id = $id ? $id : $data['id'];
|
||||
$customer = self::get($id);
|
||||
$customer->update($data);
|
||||
|
||||
return $customer;
|
||||
}
|
||||
|
||||
@@ -195,13 +205,15 @@ class Customers
|
||||
public static function getStorage($filename = false)
|
||||
{
|
||||
$path = '/app/public/Customers/';
|
||||
return $filename ? $path . $filename : $path;
|
||||
|
||||
return $filename ? $path.$filename : $path;
|
||||
}
|
||||
|
||||
public static function getPublic($filename = false)
|
||||
{
|
||||
$path = '/storage/Customers/';
|
||||
return $filename ? $path . $filename : $path;
|
||||
|
||||
return $filename ? $path.$filename : $path;
|
||||
}
|
||||
|
||||
public static function guard()
|
||||
|
||||
Reference in New Issue
Block a user