From: soufiane Date: Wed, 12 Jul 2023 16:21:36 +0000 (+0200) Subject: wip #6129 @5:00 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=090d4c8dd2341f7dfba02029f57c3157563f0ad7;p=pmi.git wip #6129 @5:00 --- diff --git a/app/Http/Controllers/Admin/ProductBaseController.php b/app/Http/Controllers/Admin/ProductBaseController.php index 5820f8a..f933d61 100644 --- a/app/Http/Controllers/Admin/ProductBaseController.php +++ b/app/Http/Controllers/Admin/ProductBaseController.php @@ -60,19 +60,24 @@ class ProductBaseController extends CubistMagicController { if($excels) { $sizeFiles = sizeof($excels); - $sizeSheets = sizeof(call_user_func_array('array_merge', $excels)); + $sizeSheets = sizeof(call_user_func_array('array_merge',array_merge(...$excels))); // Parse product files + foreach ($excels as $key => $excel) { $filename = key($excel); // Parse product sheets + $ids = []; foreach ($excel[$filename] as $sheet => $rows) { - try { + if(!empty($rows[1][1])) { $id = $rows[1][1]; - } catch(\Exception $e) { + $ids[$sheet] = $id; + }else { $errorsMessage[] = "L'Identifiant pour la fiche $sheet est manquant."; - $contentMail["details"][$filename][$sheet] = "Identifiant manquant"; + $contentMail["details"][$filename][$sheet] = "[ERREUR] Identifiant manquant"; + continue; } + try { // Parse rows of sheet foreach ($rows as $row => $columns) { @@ -118,7 +123,7 @@ class ProductBaseController extends CubistMagicController { } } catch(\Exception $e) { $errorsMessage[] = "La feuille : $sheet, contient des erreurs"; - $contentMail["details"][$filename][$sheet] = "Format invalide"; + $contentMail["details"][$filename][$sheet] = "[ERREUR] Format invalide"; } $optionId = -1; } @@ -126,31 +131,37 @@ class ProductBaseController extends CubistMagicController { foreach ($specifications as $product => $specification) { $data[$product]['json'] = json_encode($specification); } - - $product = Product::find($id); - if($product) { - $changes = $this->storeAndReturnChanges($data); - // Remove empty array from the changes - $changes = array_filter($changes); - // Total changes - $sizeChanges = sizeof($changes); + foreach ($ids as $sheet => $id) { + $product = Product::find($id); + if ($product) { + $changes = $this->storeAndReturnChanges($data); - $contentMail["details"][$filename][$sheet] = "OK"; - if(!$changes) { - $contentMail["details"][$filename][$sheet] .= " (aucune modification)"; - } - }else { - if($id) { + // Remove empty array from the changes + $changes = array_filter($changes); + + // Total changes + $sizeChanges = sizeof($changes); + + $contentMail["details"][$filename][$sheet] = "[OK]"; + + if (!$changes) { + $contentMail["details"][$filename][$sheet] .= " (aucune modification)"; + } + } else { $errorsMessage[] = "Aucun ID correspond pour le produit: $sheet"; - $contentMail["details"][$filename][$sheet] = "Identifiant inconnu"; + if ($id) { + $contentMail["details"][$filename][$sheet] = "[ERREUR] Identifiant inconnu"; + } else { + $contentMail["details"][$filename][$sheet] = "[ERREUR] Identifiant manquant"; + } } } } }else{ $errorsMessage[] = "Erreur lors du téléchargement du fichier."; - $contentMail["details"] = "Fichier incorrect"; + $contentMail["details"] = "[ERREUR] Fichier incorrect"; } $successMessage = "$sizeFiles fichier(s) chargé(s)"; @@ -187,10 +198,11 @@ class ProductBaseController extends CubistMagicController { $changes = []; foreach ($datas as $id => $data) { $product = Product::find($id); - if($product) + if ($product) { $product->update($data); $product->save(); $changes[$id] = $product->wasChanged(); + } } return $changes; } @@ -220,7 +232,7 @@ class ProductBaseController extends CubistMagicController { $message->sender(config('mail.from.address'), config('mail.from.name')); $message->to("soufiane@cubedesigners.com"); $message->bcc('test+pmi@cubedesigners.com'); - $message->subject("Mise à jour"); + $message->subject("[PM-Instrumentation] Mise à jour"); }); } } diff --git a/app/Http/Controllers/AjaxController.php b/app/Http/Controllers/AjaxController.php index 6c1c7e7..70c0165 100644 --- a/app/Http/Controllers/AjaxController.php +++ b/app/Http/Controllers/AjaxController.php @@ -647,7 +647,7 @@ class AjaxController extends CubistFrontController $cart['products'] = json_decode($cart['products'], true); $clientId = Client::getClientConnected()->id; - $currentCartRef = Cart::getRefs(json_decode($cart['products'],true)); + $currentCartRef = Cart::getRefs($cart['products']); $data = Cart::updateCartData($currentCartRef,$cart,$productsInfosBase); if($clientIdInRequest === $clientId) { diff --git a/app/Http/Controllers/Client/ClientController.php b/app/Http/Controllers/Client/ClientController.php index fadd14f..547a970 100644 --- a/app/Http/Controllers/Client/ClientController.php +++ b/app/Http/Controllers/Client/ClientController.php @@ -1,14 +1,10 @@