From db2da3543d3c53cd2f5d185257c1f181f6c25a32 Mon Sep 17 00:00:00 2001 From: Noah Lancien Date: Wed, 29 Oct 2025 12:41:39 +0100 Subject: [PATCH] fix: review feedback --- app/Http/Controllers/Api/v1/BasketController.php | 15 ++++++++------- app/Models/Customers.php | 4 ++-- clients/MesBR_V1.php | 15 +++++++-------- ...id_and_deleted_at_in_printed_coupons_table.php | 6 +++--- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/app/Http/Controllers/Api/v1/BasketController.php b/app/Http/Controllers/Api/v1/BasketController.php index dbd3c74..92a2006 100644 --- a/app/Http/Controllers/Api/v1/BasketController.php +++ b/app/Http/Controllers/Api/v1/BasketController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers\Api\v1; use Illuminate\Http\Request; +use Illuminate\Support\Str; use App\Campagne; use App\Coupon; use App\Enums\LogActions; @@ -35,7 +36,7 @@ class BasketController extends Controller // ---- Contrôle des paramètres $error = false; if ( - (!isset($request->refadherent) || $request->refadherent == "") || + (!isset($request->customer_hashcode) || $request->customer_hashcode == "") || (!isset($request->refcamp) || $request->refcamp == "") || (!isset($request->refsite) || $request->refsite == "") || (!isset($request->panier) || $request->panier == "") @@ -100,8 +101,8 @@ class BasketController extends Controller if ($error) { $this->writeLogErrorWrongRequestParameters( $request->refcamp, - $request->refadherent, - $request->refsite, + $request->customer_hashcode, + $campagne->camp_siteId, $request->panier ); @@ -112,8 +113,8 @@ class BasketController extends Controller ]); } - // ---- Ajout/MAJ du customer - $customer = Customers::where(['hashcode' => $request->refadherent])->first(); + // ---- Récupération du Customer + $customer = Customers::where(['hashcode' => $request->customer_hashcode])->first(); // ---- Ajout/MAJ du panier $panier = Basket::where(['campagne_id' => $refcamp, 'customer_id' => $customer->id])->first(); @@ -136,7 +137,7 @@ class BasketController extends Controller } else { // Ajout du panier et du contenu $panier = new Basket(); - $panier->ref = strtoupper(md5(uniqid(time(), true))); + $panier->ref = Str::uuid(); $panier->campagne()->associate($refcamp); $panier->customer()->associate($customer); $panier->save(); @@ -152,7 +153,7 @@ class BasketController extends Controller $this->writeLogSuccessBasketCreated( $request->refcamp, - $request->refadherent, + $request->customer_hashcode, $request->refsite, $request->panier, $panierCoupons diff --git a/app/Models/Customers.php b/app/Models/Customers.php index 0d42379..55e03ef 100644 --- a/app/Models/Customers.php +++ b/app/Models/Customers.php @@ -82,11 +82,11 @@ class Customers extends Model } /** - * Basket model relation + * Panier model relation * @return HasMany */ public function paniers() { - return $this->hasMany(Panier::class, 'customer_id', 'id'); + return $this->hasMany(Panier::class, 'panier_contactId', 'id'); } } diff --git a/clients/MesBR_V1.php b/clients/MesBR_V1.php index e6c180b..61cd947 100644 --- a/clients/MesBR_V1.php +++ b/clients/MesBR_V1.php @@ -11,10 +11,13 @@ class MesBR private $refCamp; - public function __construct($endpoint, $refCamp) + private $refSite; + + public function __construct($endpoint, $refCamp, $refSite) { $this->endpoint = $endpoint; $this->refCamp = $refCamp; + $this->refSite = $refSite; } public function createCustomer(string $hashcode, string $email, string $country) @@ -90,25 +93,21 @@ class MesBR * Update basket * * @param \LDC\LDCCRM\Models\Customer $crm_customer - * @param string $ref_site * @param string $coupon_id * @param integer $quantity * @return array * 'status' => 'OK', - * 'link' => URL, - * 'verif' => URL, - * 'basketId' => 'ID' + * 'ref' => Basket REF, */ public function updateBasket( Customer $crm_customer, - string $ref_site, string $coupon_id, int $quantity = 1 ): array { $res = $this->callAPI("GET", "/customer/basket/update", [ - 'refsite' => $ref_site, + 'refsite' => $this->refSite, 'refcamp' => $this->refCamp, - 'refadherent' => $crm_customer->hashcode, + 'customer_hashcode' => $crm_customer->hashcode, 'panier' => "({$quantity}){$coupon_id}" ]); diff --git a/database/migrations/2025_07_29_000001_add_id_and_deleted_at_in_printed_coupons_table.php b/database/migrations/2025_07_29_000001_add_id_and_deleted_at_in_printed_coupons_table.php index 6d4b7b0..ad0efb1 100644 --- a/database/migrations/2025_07_29_000001_add_id_and_deleted_at_in_printed_coupons_table.php +++ b/database/migrations/2025_07_29_000001_add_id_and_deleted_at_in_printed_coupons_table.php @@ -26,9 +26,9 @@ return new class extends Migration */ public function down() { - Schema::table('site_user', function (Blueprint $table) { - $table->dropForeign('site_user_site_id_foreign'); - $table->dropForeign('site_user_user_id_foreign'); + Schema::table('printed_coupons', function (Blueprint $table) { + $table->dropColumn('id'); + $table->dropSoftDeletes(); }); } };