fix editing orders
This commit is contained in:
@@ -458,17 +458,17 @@ class Articles
|
||||
$images = count($article->images) ? $article->images : collect([]);
|
||||
switch ($article->product_type) {
|
||||
case 'App\Models\Botanic\Variety':
|
||||
$variety = $article->product;
|
||||
$specie = $variety->specie;
|
||||
$variety = $article->product ?? false;
|
||||
$specie = $variety->specie ?? false;
|
||||
$images = $variety ? (count($variety->images) ? $images->merge($variety->images) : $images) : $images;
|
||||
$images = $specie ? (count($specie->images) ? $images->merge($specie->images) : $images) : $images;
|
||||
break;
|
||||
case 'App\Models\Botanic\Specie':
|
||||
$specie = $article->product;
|
||||
$images = count($specie->images) ? $specie->images : $images;
|
||||
$specie = $article->product ?? false;
|
||||
$images = count($specie->images ?? []) ? $specie->images : $images;
|
||||
break;
|
||||
case 'App\Models\Shop\Merchandise':
|
||||
$merchandise = $article->product;
|
||||
$merchandise = $article->product ?? false;
|
||||
$images = count($merchandise->images) ? $merchandise->images : $images;
|
||||
break;
|
||||
}
|
||||
@@ -488,20 +488,13 @@ class Articles
|
||||
}
|
||||
switch ($article->product_type) {
|
||||
case 'App\Models\Botanic\Variety':
|
||||
$variety = $article->product;
|
||||
$image = $variety->image ?? false;
|
||||
if (!$image) {
|
||||
$specie = $variety->specie;
|
||||
$image = $specie->image ?? false;
|
||||
}
|
||||
$image = $article->product->image ?? ($article->product->specie->image ?? false);
|
||||
break;
|
||||
case 'App\Models\Botanic\Specie':
|
||||
$specie = $article->product;
|
||||
$image = $specie->image ?? false;
|
||||
$image = $article->product->image ?? false;
|
||||
break;
|
||||
case 'App\Models\Shop\Merchandise':
|
||||
$merchandise = $article->product;
|
||||
$image = $merchandise->image ?? false;
|
||||
$image = $article->product->image ?? false;
|
||||
break;
|
||||
}
|
||||
return $image;
|
||||
@@ -509,16 +502,16 @@ class Articles
|
||||
|
||||
public static function storeFull($data)
|
||||
{
|
||||
$images = isset($data['images']) ? $data['images'] : false;
|
||||
$images = $data['images'] ?? false;
|
||||
unset($data['images']);
|
||||
|
||||
$categories = isset($data['categories']) ? $data['categories'] : false;
|
||||
$categories = $data['categories'] ?? false;
|
||||
unset($data['categories']);
|
||||
|
||||
$tags = isset($data['tags']) ? $data['tags'] : false;
|
||||
$tags = $data['tags'] ?? false;
|
||||
unset($data['tags']);
|
||||
|
||||
$prices = isset($data['prices']) ? $data['prices'] : false;
|
||||
$prices = $data['prices'] ?? false;
|
||||
unset($data['prices']);
|
||||
|
||||
$article = self::store($data);
|
||||
|
||||
@@ -15,14 +15,11 @@ class Customers
|
||||
public static function editProfile($id = false)
|
||||
{
|
||||
$id = $id ? $id : self::getId();
|
||||
dump($id);
|
||||
exit;
|
||||
$data = [
|
||||
'customer' => self::get($id, ['addresses', 'deliveries', 'orders']),
|
||||
'customer' => self::get($id, ['addresses', 'deliveries', 'orders'])->toArray(),
|
||||
'deliveries' => Deliveries::getAll('sale_channel')->toArray(),
|
||||
];
|
||||
dump($data);
|
||||
exit;
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
18
app/Repositories/Shop/Dashboards.php
Normal file
18
app/Repositories/Shop/Dashboards.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\Homepage;
|
||||
|
||||
class Dashboards
|
||||
{
|
||||
|
||||
public static function getStats()
|
||||
{
|
||||
return [
|
||||
'orders_count' => Orders::countByMonth(),
|
||||
'orders_sum' => Orders::sumByMonth(),
|
||||
'orders_avg' => Orders::avgByMonth(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use App\Models\Shop\Invoice;
|
||||
|
||||
class Invoices
|
||||
@@ -19,6 +19,17 @@ class Invoices
|
||||
return $relations ? Invoice::with($relations)->findOrFail($id) : Invoice::findOrFail($id);
|
||||
}
|
||||
|
||||
public static function count()
|
||||
{
|
||||
return Invoice::count();
|
||||
}
|
||||
|
||||
public static function countByMonth()
|
||||
{
|
||||
$start = Carbon::now()->beginOfMonth();
|
||||
return Invoice::where('created_at', '>', $start);
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
return ($data['id'] ?? false) ? self::update($data) : self::create($data);
|
||||
@@ -53,4 +64,9 @@ class Invoices
|
||||
$last_ref = Invoice::orderBy('ref', 'desc')->where('ref', '>', $ref)->first();
|
||||
return $last_ref ? $last_ref->ref + 1 : $ref + 1;
|
||||
}
|
||||
|
||||
public static function statuses()
|
||||
{
|
||||
return ['En attente', 'Non soldée', 'Soldée'];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use App\Models\Shop\Order;
|
||||
|
||||
class Orders
|
||||
@@ -24,9 +25,36 @@ class Orders
|
||||
return ($order && $detail) ? Invoices::saveInvoice($order->id, $data) : false;
|
||||
}
|
||||
|
||||
public static function count()
|
||||
{
|
||||
return Order::count();
|
||||
}
|
||||
|
||||
public static function countByMonth()
|
||||
{
|
||||
$start = Carbon::now()->startOfMonth();
|
||||
return Order::where('created_at', '>', $start)->count();
|
||||
}
|
||||
|
||||
public static function sumByMonth()
|
||||
{
|
||||
$start = Carbon::now()->startOfMonth();
|
||||
return Order::where('created_at', '>', $start)->sum('total_shipped');
|
||||
}
|
||||
|
||||
public static function avgByMonth()
|
||||
{
|
||||
return self::countByMonth() ? round(self::sumByMonth() / self::countByMonth(), 2) : 0;
|
||||
}
|
||||
|
||||
public static function edit($id)
|
||||
{
|
||||
return Orders::get($id, ['customer', 'address', 'delivery', 'detail']);
|
||||
return [
|
||||
'order' => self::get($id, ['customer', 'address', 'detail']),
|
||||
'statuses' => self::statuses(),
|
||||
'payment_types' => self::payment_types(),
|
||||
'sale_channels' => SaleChannels::getOptions(),
|
||||
];
|
||||
}
|
||||
|
||||
public static function get($id, $relations = false)
|
||||
@@ -65,10 +93,16 @@ class Orders
|
||||
|
||||
public static function statuses()
|
||||
{
|
||||
return [
|
||||
'En attente',
|
||||
'Expédié',
|
||||
'Livré',
|
||||
];
|
||||
return ['En attente', 'Expédié', 'Livré'];
|
||||
}
|
||||
|
||||
public static function getPaymentType($id)
|
||||
{
|
||||
return self::payment_types()[$id] ?? false;
|
||||
}
|
||||
|
||||
public static function payment_types()
|
||||
{
|
||||
return ['', 'CARTE BANCAIRE', 'CHEQUE', 'VIREMENT BANCAIRE'];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user