[WIP] Finish the order process
This commit is contained in:
@@ -283,36 +283,7 @@ class Articles
|
||||
public static function getInherited($id)
|
||||
{
|
||||
$article = Article::with('product.tags.tag_group')->findOrFail($id);
|
||||
$product_type = $article->product_type;
|
||||
switch ($product_type) {
|
||||
case 'App\Models\Botanic\Variety':
|
||||
$data[] = [
|
||||
'name' => 'Espèces',
|
||||
'description' => Species::getDescription($article->product->specie_id),
|
||||
'tags' => Species::getTags($article->product->specie_id),
|
||||
];
|
||||
$data[] = [
|
||||
'name' => 'Variétés',
|
||||
'description' => $article->product->description,
|
||||
'tags' => $article->product->tags->toArray()
|
||||
];
|
||||
break;
|
||||
case 'App\Models\Botanic\Specie':
|
||||
$data[] = [
|
||||
'name' => 'Espèces',
|
||||
'description' => $article->product->description,
|
||||
'tags' => $article->product->tags->toArray()
|
||||
];
|
||||
break;
|
||||
case 'App\Models\Shop\Merchandise':
|
||||
$data[] = [
|
||||
'name' => 'Marchandise',
|
||||
'description' => $article->product->description,
|
||||
'tags' => $article->product->tags->toArray(),
|
||||
];
|
||||
break;
|
||||
}
|
||||
return $data ?? [];
|
||||
return self::getInheritedByProduct($article->product_id, $article->product_type);
|
||||
}
|
||||
|
||||
public static function getInheritedByProduct($product_id, $product_type)
|
||||
|
||||
@@ -29,10 +29,11 @@ class Customers
|
||||
$name = $customer->first_name . ' ' . $customer->last_name;
|
||||
$avatar = new Avatar();
|
||||
$ret = $avatar->create($name)
|
||||
->setBackground($bgColor)
|
||||
->setBorder(1, '#29292e')
|
||||
->setBackground('#F2B90F')
|
||||
->setForeground('#335012')
|
||||
->setBorder(1, '#28a745')
|
||||
->setFontFamily('Roboto Condensed')
|
||||
->setDimension(40)
|
||||
->setDimension(36)
|
||||
->setFontSize(16)
|
||||
->save($filename);
|
||||
return $ret;
|
||||
@@ -42,7 +43,7 @@ class Customers
|
||||
{
|
||||
$path = storage_path(self::getStorage());
|
||||
if (File::checkDirOrCreate($path)) {
|
||||
$filename = $path . 'user-' . $customer->uuid . '.png';
|
||||
$filename = $path . self::getAvatarFilename($customer);
|
||||
}
|
||||
return $filename ?? false;
|
||||
}
|
||||
@@ -55,58 +56,44 @@ class Customers
|
||||
public static function getAddresses($id = false)
|
||||
{
|
||||
$customer = self::getWithAddresses($id);
|
||||
return $customer ? $customer->addresses : false;
|
||||
}
|
||||
|
||||
public static function getWithAddresses($id = false)
|
||||
{
|
||||
$id = $id ? $id : self::getId();
|
||||
return Customer::with('addresses')->find($id);
|
||||
return self::get($id, 'addresses');
|
||||
}
|
||||
|
||||
public static function getName()
|
||||
public static function getName($id = false)
|
||||
{
|
||||
$user = self::getAuth();
|
||||
return $user ? $user->first_name : '';
|
||||
$user = $id ? self::get($id) : self::getAuth();
|
||||
return $user ? $user->first_name . ' ' . $user->last_name : '';
|
||||
}
|
||||
|
||||
public static function getAuth()
|
||||
{
|
||||
return Auth::guard('customer')->user();
|
||||
return self::guard()->user();
|
||||
}
|
||||
|
||||
public static function getId()
|
||||
{
|
||||
return Auth::guard('customer')->id();
|
||||
return self::guard()->id();
|
||||
}
|
||||
|
||||
public static function isConnected()
|
||||
{
|
||||
return Auth::guard('customer')->check();
|
||||
return self::guard()->check();
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
public static function get($id = false, $relations = false)
|
||||
{
|
||||
return Customer::orderBy('value', 'asc')->get()->pluck('value', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getOptionsByPackage($package_id)
|
||||
{
|
||||
return Customer::byPackage($package_id)->orderBy('value', 'asc')->get()->pluck('value', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return Customer::orderBy('value', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Customer::find($id);
|
||||
$id = $id ? $id : self::getId();
|
||||
return $id ? ($relations ? Customer::with($relations)->findOrFail($id) : Customer::findOrFail($id)) : false;
|
||||
}
|
||||
|
||||
public static function edit($id)
|
||||
{
|
||||
$customer = Customer::with(['addresses'])->find($id);
|
||||
$customer = self::get($id, 'addresses');
|
||||
$data = $customer->toArray();
|
||||
$data['deliveries'] = $customer->deliveries->pluck('id')->toArray();
|
||||
return $data;
|
||||
@@ -126,9 +113,7 @@ class Customers
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = $data['id'] ?? false;
|
||||
$item = $id ? self::update($data, $id) : self::create($data);
|
||||
return $item;
|
||||
return ($data['id'] ?? false) ? self::update($data) : self::create($data);
|
||||
}
|
||||
|
||||
public static function storeDeliveries($customer, $deliveries)
|
||||
@@ -166,7 +151,7 @@ class Customers
|
||||
return $customer;
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
public static function delete($id)
|
||||
{
|
||||
return Customer::destroy($id);
|
||||
}
|
||||
@@ -182,4 +167,9 @@ class Customers
|
||||
$path = '/storage/Customers/';
|
||||
return $filename ? $path . $filename : $path;
|
||||
}
|
||||
|
||||
public static function guard()
|
||||
{
|
||||
return Auth::guard('customer');
|
||||
}
|
||||
}
|
||||
|
||||
46
app/Repositories/Shop/OrderDetails.php
Normal file
46
app/Repositories/Shop/OrderDetails.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\OrderDetail;
|
||||
|
||||
class OrderDetails
|
||||
{
|
||||
|
||||
public static function saveBasket($order_id, $data)
|
||||
{
|
||||
foreach ($data as $item) {
|
||||
$item['order_id'] = $order_id;
|
||||
$detail = self::store($item);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function get($id, $relations = false)
|
||||
{
|
||||
return $relations ? OrderDetail::with($relations)->findOrFail($id) : OrderDetail::findOrFail($id);
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
return ($data['id'] ?? false) ? self::update($data) : self::create($data);
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return OrderDetail::create($data);
|
||||
}
|
||||
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
$id = $id ? $id : $data['id'];
|
||||
$item = self::get($id);
|
||||
$item->update($data);
|
||||
return $item;
|
||||
}
|
||||
|
||||
public static function delete($id)
|
||||
{
|
||||
return OrderDetail::destroy($id);
|
||||
}
|
||||
}
|
||||
@@ -6,31 +6,23 @@ use App\Models\Shop\Order;
|
||||
|
||||
class Orders
|
||||
{
|
||||
public static function getOptions()
|
||||
|
||||
public static function saveOrder($data)
|
||||
{
|
||||
return Order::orderBy('value', 'asc')->get()->pluck('value', 'id')->toArray();
|
||||
$basket = $data['basket'];
|
||||
unset($data['basket']);
|
||||
$order = self::store($data);
|
||||
return $order ? OrderDetails::saveBasket($order->id, $basket) : false;
|
||||
}
|
||||
|
||||
public static function getOptionsByPackage($package_id)
|
||||
public static function get($id, $relations = false)
|
||||
{
|
||||
return Order::byPackage($package_id)->orderBy('value', 'asc')->get()->pluck('value', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return Order::orderBy('value', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Order::findOrFail($id);
|
||||
return $relations ? Order::with($relations)->findOrFail($id) : Order::findOrFail($id);
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$item = $id ? self::update($data, $id) : self::create($data);
|
||||
return $item->id;
|
||||
return ($data['id'] ?? false) ? self::update($data) : self::create($data);
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
@@ -46,7 +38,7 @@ class Orders
|
||||
return $item;
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
public static function delete($id)
|
||||
{
|
||||
return Order::destroy($id);
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ class TagGroups
|
||||
$data[$tag['tag_group_id']]['name'] = $tag_groups[$tag['tag_group_id']];
|
||||
if (!$tag['articles_count']) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$data[$tag['tag_group_id']]['tags'][] = [
|
||||
'id' => $tag['id'],
|
||||
'name' => $tag['name'],
|
||||
@@ -72,8 +72,7 @@ class TagGroups
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$item = $id ? self::update($data) : self::create($data);
|
||||
$item = ($data['id'] ?? false) ? self::update($data) : self::create($data);
|
||||
return $item->id;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user