commit 2bdbfaec541c3d51489f32e0fa6f7523ca4e4f6f
Author: Olivier Legat <olivier.legat@ldc.fr>
Date: Thu Apr 8 15:48:13 2021 +0200
arrondis de taxe dans le panier
commit ce748bcac15a0b633cacc06b8232cbb92a8e455c
Author: Olivier Legat <olivier.legat@ldc.fr>
Date: Thu Apr 8 11:53:54 2021 +0200
Prix calcules - affichés
commit cc79e7c633d81290371eceabe9864d4d0ee9e4a5
Author: Olivier Legat <olivier.legat@ldc.fr>
Date: Wed Apr 7 18:09:12 2021 +0200
Affichage des promowork in progress => prix remisés
commit 8545d1079da2456f090557eeef005e4d37154a1e
Author: Olivier Legat <olivier.legat@ldc.fr>
Date: Wed Apr 7 13:04:28 2021 +0200
resource BO Promotions
commit d7145835de675da32e57bec3f0b8f06e1e447b27
Author: Olivier Legat <olivier.legat@ldc.fr>
Date: Tue Apr 6 18:23:36 2021 +0200
structure DB, debut BO
136 lines
3.7 KiB
PHP
136 lines
3.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Bo;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\DiscountType;
|
|
use App\Models\Promotion;
|
|
use Illuminate\Http\Request;
|
|
|
|
class PromotionsController extends Controller
|
|
{
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function index()
|
|
{
|
|
$promotions = Promotion::all();
|
|
return view('bo.promotions.index', compact('promotions'));
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function create()
|
|
{
|
|
$discTypes = DiscountType::all();
|
|
return view('bo.promotions.create', compact('discTypes'));
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
$productIds = explode(",", $request->product_id);
|
|
$discType = $request->discount_type_id;
|
|
$value = $request->discount_value;
|
|
$date_start = $request->date_start_date . " " . $request->date_start_time;
|
|
$date_end = $request->date_end_date . " " . $request->date_end_time;
|
|
|
|
$request->validate([]);
|
|
|
|
$promotion = new Promotion();
|
|
$promotion->discount_type_id = $discType;
|
|
$promotion->discount_value = $value;
|
|
$promotion->date_start = $date_start;
|
|
$promotion->date_end = $date_end;
|
|
$promotion->save();
|
|
|
|
//prise en charge de la liaison avec les produits
|
|
$promotion->products()->sync($productIds);
|
|
|
|
return redirect()->route('bo.promotions.index');
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function show($id)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function edit($id)
|
|
{
|
|
$promotion = Promotion::findOrFail($id);
|
|
$discTypes = DiscountType::all();
|
|
return view('bo.promotions.edit', compact('promotion', 'discTypes'));
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function update(Request $request, $id)
|
|
{
|
|
$promotion = Promotion::findOrFail($id);
|
|
|
|
$productIds = explode(",", $request->product_id);
|
|
$discType = $request->discount_type_id;
|
|
$value = $request->discount_value;
|
|
$date_start = $request->date_start_date . " " . $request->date_start_time;
|
|
$date_end = $request->date_end_date . " " . $request->date_end_time;
|
|
|
|
$request->validate([]);
|
|
|
|
$promotion->discount_type_id = $discType;
|
|
$promotion->discount_value = $value;
|
|
$promotion->date_start = $date_start;
|
|
$promotion->date_end = $date_end;
|
|
$promotion->save();
|
|
|
|
//prise en charge de la liaison avec les produits
|
|
$promotion->products()->sync($productIds);
|
|
|
|
return redirect()->route('bo.promotions.edit', $promotion->id)->with('success', 'Modifications enregistrés !');
|
|
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function destroy($id)
|
|
{
|
|
$p = Promotion::findOrFail($id);
|
|
|
|
//prise en charge de la liaison avec les produits
|
|
$p->products()->detach();
|
|
|
|
$p->delete();
|
|
|
|
return redirect()->route('bo.promotions.index');
|
|
}
|
|
}
|