randomize picture filenames to prevent cache on update

This commit is contained in:
Olivier Legat 2021-04-16 09:00:36 +02:00
parent 1b64c6ba1a
commit 9c770f3f3a
4 changed files with 57 additions and 46 deletions

View file

@ -27,17 +27,20 @@ class OrdersController extends Controller
/**
* index of orders (Bo)
*/
public function index() {
public function index()
{
$orders = Order::orderBy('date', 'DESC')->get();
return view('bo.orders.index', compact('orders'));
}
/**
* action de changement de statut vers l'avant
* @todo : envoyer les mails transactionnels
* envoi de mails transctionnels
* @param String $reference reference de la commande
*/
public function changeStatus($reference) {
$order = Order::where('reference', $reference)->first();
public function changeStatus($reference)
{
$order = Order::where('reference', $reference)->first();
$order->status_id = $order->status_id + 1;
$order->save();
@ -51,8 +54,9 @@ class OrdersController extends Controller
/**
* mise au statut annulé d'une commande
*/
public function cancelOrder($reference) {
$order = Order::where('reference', $reference)->first();
public function cancelOrder($reference)
{
$order = Order::where('reference', $reference)->first();
$order->status_id = 7;
$order->save();
@ -65,15 +69,16 @@ class OrdersController extends Controller
* ajout de produits à la commande
* @todo : supprimer cette méthode qui repose sur un modèle de donnée osolète
*/
public function addProduct($orderReference, $productId, $quantity) {
public function addProduct($orderReference, $productId, $quantity)
{
$product = Product::findOrFail($productId);
$order = Order::where('reference', $orderReference)->first();
$order = Order::where('reference', $orderReference)->first();
$order->total = $order->total + (($product->price - $product->price_buy) * $quantity);
$orderProduct = new OrdersProducts();
$order->total = $order->total + (($product->price - $product->price_buy) * $quantity);
$orderProduct = new OrdersProducts();
$orderProduct->product_id = $product->id;
$orderProduct->order_id = $order->id;
$orderProduct->quantity = $quantity;
$orderProduct->order_id = $order->id;
$orderProduct->quantity = $quantity;
$orderProduct->save();
@ -124,10 +129,10 @@ class OrdersController extends Controller
$cart = Cart::content();
foreach ($cart as $cartItem) {
$order_line = new OrderLine();
$order_line->order_id = $order->id;
$order_line = new OrderLine();
$order_line->order_id = $order->id;
$order_line->product_id = $cartItem->model->id;
$order_line->quantity = $cartItem->qty;
$order_line->quantity = $cartItem->qty;
//gross unit price
$order_line->unit_price = $cartItem->model->priceHt;
//discount per unit
@ -164,44 +169,44 @@ class OrdersController extends Controller
//settings à stocker
//get available timeslots
//days 0 = sunday => 6 = saturday
$plage = array(
$plage = array(
0 => array(),
1 => array(
'start' =>'09:00',
'start' => '09:00',
'end' => '16:50',
),
2 => array(
'start' =>'09:00',
'start' => '09:00',
'end' => '17:00',
),
3 => array(
'start' =>'09:00',
'start' => '09:00',
'end' => '17:00',
),
4 => array(
'start' =>'09:00',
'start' => '09:00',
'end' => '17:00',
),
5 => array(
'start' =>'09:00',
'start' => '09:00',
'end' => '17:00',
),
6 => array(
'start' =>'10:00',
'start' => '10:00',
'end' => '12:00',
),
);
$plage_interval = "0:15";
$plage_days = 14;
$plage_days = 14;
//génération des plages
//start today
$today = CarbonImmutable::now()->startOfDay();
$now = CarbonImmutable::now();
$now = CarbonImmutable::now();
$availCreneaux = array();
$interval = CarbonInterval::createFromFormat('h:i',$plage_interval);
$interval = CarbonInterval::createFromFormat('h:i', $plage_interval);
for ($i = 0; $i < $plage_days; $i++) {
/** @var Carbon */
@ -209,11 +214,11 @@ class OrdersController extends Controller
$weekDay = $current->weekday();
if (isset($plage[$weekDay]['start'])) {
$currentTime = Carbon::createFromTimeString($plage[$weekDay]['start']);
$endTime = Carbon::createFromTimeString($plage[$weekDay]['end']);
$endTime = Carbon::createFromTimeString($plage[$weekDay]['end']);
do {
$creneau = $currentTime->format('H:i');
//attention si la date est passée (today mai avant maintenant) : pas de créneau
if($current > $today || $currentTime >= $now) {
if ($current > $today || $currentTime >= $now) {
$availCreneaux[$current->format('d/m/Y')][] = $creneau;
}
$currentTime->add($interval);
@ -232,22 +237,22 @@ class OrdersController extends Controller
public function setTimeSlot(Request $request)
{
$time_slot = Carbon::createFromFormat('d/m/Y-H:i', $request->selectedcreneau);
$tsday = explode('-',$request->selectedcreneau)[0];
$tstime = explode('-',$request->selectedcreneau)[1];
$tsday = explode('-', $request->selectedcreneau)[0];
$tstime = explode('-', $request->selectedcreneau)[1];
$reference = $request->order_ref;
$order = Order::where('reference', '=', $reference)->firstOrFail();
$order = Order::where('reference', '=', $reference)->firstOrFail();
if($order->status_id == 1) {
if ($order->status_id == 1) {
// on ne traite l'enregistrement que pour les commandes en attente venant de l'étape de récap
//save timeslot
$timeslot = Timeslot::firstOrNew(['order_id' => $order->id]);
$timeslot = Timeslot::firstOrNew(['order_id' => $order->id]);
$timeslot->order_id = $order->id;
$timeslot->day = $tsday;
$timeslot->time = $tstime;
$timeslot->day = $tsday;
$timeslot->time = $tstime;
$timeslot->save();
//save order status
$order->status_id = 3;
$order->status_id = 3;
$order->save();
//send confirm mail
@ -267,7 +272,7 @@ class OrdersController extends Controller
$activestep = 4;
$idcommande = Session::get('idcommande');
$order = Order::where('reference', '=', $reference)->firstOrFail();
$order = Order::where('reference', '=', $reference)->firstOrFail();
return view('sales.confirm', compact('activestep', 'order'));
}
@ -277,7 +282,8 @@ class OrdersController extends Controller
* ajx : affichage d'infos sur un client
* @todo : déplacer dans le controller idoine
*/
public function getCustomerInfo($id) {
public function getCustomerInfo($id)
{
$cust = Customers::findOrFail($id);
return view('bo.customer.info-popup', compact('cust'));
}
@ -285,7 +291,8 @@ class OrdersController extends Controller
/**
* bo : page détatil commande
*/
public function orderDetail($reference) {
public function orderDetail($reference)
{
$order = Order::where('reference', '=', $reference)->firstOrFail();
return view('bo.orders.detail', compact('order'));
}

View file

@ -102,8 +102,10 @@ class ProductsController extends Controller
$oldSlug->save();
}
$str_random = Str::random(5);
if ($picture !== null) {
$imageName = $product->id . '.' . $picture->extension();
$imageName = $product->id . '_' . $str_random . '.' . $picture->extension();
$picture->move(public_path('images/produits'), $imageName);
$product->picture = $imageName;
}
@ -114,7 +116,7 @@ class ProductsController extends Controller
config('theme.product_image_large_maxwidth') . ',max_height=' .
config('theme.product_image_large_maxheight')
]);
$imageName = $product->id . '_large.' . $picture->extension();
$imageName = $product->id . '_' . $str_random . '_large.' . $picture->extension();
$picture_large->move(public_path('images/produits'), $imageName);
$product->picture_large = $imageName;
$product->save();
@ -215,11 +217,13 @@ class ProductsController extends Controller
"\" éxiste déjà. Veuillez changer le nom du produit.");
}
$str_random = Str::random(5);
if ($picture !== null) {
if ($product->picture !== null && file_exists(public_path('images/produits/') . $product->picture)) {
unlink(public_path('images/produits/') . $product->picture);
}
$imageName = $product->id . '.' . $picture->extension();
$imageName = $product->id . '_' . $str_random . '.' . $picture->extension();
$picture->move(public_path('images/produits'), $imageName);
$product->picture = $imageName;
}
@ -228,7 +232,7 @@ class ProductsController extends Controller
if ($product->picture_large !== null && file_exists(public_path('images/produits/') . $product->picture_large)) {
unlink(public_path('images/produits/') . $product->picture_large);
}
$imageName = $product->id . '_large.' . $picture_large->extension();
$imageName = $product->id . '_' . $str_random . '_large.' . $picture_large->extension();
$picture_large->move(public_path('images/produits'), $imageName);
$product->picture_large = $imageName;
}

View file

@ -44,7 +44,7 @@ class RangesController extends Controller
$range->save();
if ($picture !== null) {
$imageName = $range->id . '.' . $picture->extension();
$imageName = $range->id . '_' . $slug . '_' . Str::random(5) . '.' . $picture->extension();
$picture->move(public_path('images/gammes'), $imageName);
$range->picture = $imageName;
$range->save();
@ -78,7 +78,7 @@ class RangesController extends Controller
if ($picture !== null) {
if ($range->picture !== null && file_exists(public_path('images/gammes/') . $range->picture))
unlink(public_path('images/gammes/') . $range->picture);
$imageName = $range->id . '.' . $picture->extension();
$imageName = $range->id . '_' . $slug . '_' . Str::random(5) . '.' . $picture->extension();
$picture->move(public_path('images/gammes'), $imageName);
}

View file

@ -93,7 +93,7 @@ class SlidesController extends Controller
$slide->save();
if ($picture !== null) {
$imageName = $slide->id . '.' . $picture->extension();
$imageName = $slide->id . '_' . Str::random(5) . '.' . $picture->extension();
$picture->move(public_path('images/slides'), $imageName);
$slide->picture = $imageName;
$slide->save();
@ -187,7 +187,7 @@ class SlidesController extends Controller
if ($picture !== null) {
if(file_exists(public_path() . 'images/slides/' . $slide->picture))
unlink(public_path() . 'images/slides/' . $slide->picture);
$imageName = $slide->id . '.' . $picture->extension();
$imageName = $slide->id . '_' . Str::random(5) . '.' . $picture->extension();
$picture->move(public_path('images/slides'), $imageName);
$slide->picture = $imageName;
$slide->save();