From d53bb7cb5d2f8820a2a0ee0cb7d08d70d49ee762 Mon Sep 17 00:00:00 2001 From: soufiane Date: Wed, 26 Jul 2023 13:15:07 +0200 Subject: [PATCH] wait #6172 @0:10 --- .../Admin/ProductBaseController.php | 97 +++++++++---------- .../views/components/item-cart.blade.php | 4 +- 2 files changed, 47 insertions(+), 54 deletions(-) diff --git a/app/Http/Controllers/Admin/ProductBaseController.php b/app/Http/Controllers/Admin/ProductBaseController.php index e9ff728..6babbfd 100644 --- a/app/Http/Controllers/Admin/ProductBaseController.php +++ b/app/Http/Controllers/Admin/ProductBaseController.php @@ -69,6 +69,13 @@ class ProductBaseController extends CubistMagicController { // Parse product sheets $ids = []; foreach ($excel[$filename] as $sheet => $rows) { + $options = array_splice($rows, 9); + $emptyRef = array_filter($options, function($n) { return empty($n[6]); }); + if($emptyRef) { + $contentMail["details"][$filename][$sheet] = "[ERREUR] Référence option manquante"; + continue; + } + if(!empty($rows[1][1])) { $id = $rows[1][1]; $ids[$sheet] = $id; @@ -78,61 +85,48 @@ class ProductBaseController extends CubistMagicController { continue; } - try { - // Parse rows of sheet - foreach ($rows as $row => $columns) { - if ($row < 8) { - foreach ($fields as $key => $field) { - // Ignore first and second row (SKU, ID) - // Begin at third - $c = ($key + 2); - $value = $rows[$c][$index]; - - if (in_array($field, ["basic_selling_price", "basic_purschase_price", "conversion"])) { - $value = floatval($value); - } elseif ($field === "discount") { - $value = floatval(str_replace("%", "", $value)); - } - - if (in_array($field, ["category", "currency"])) { - $value = trim($value); - } - $data[$id][$field] = $value; - } - } elseif ($row >= 9) { - try { - if(empty($colmns[6])) { - throw new Exception('Empty ref'); - } - } catch (Exception $e) { - $contentMail["details"][$filename][$sheet] = "[ERREUR] Référence manquante"; - continue; - } - if ($columns[0] && $columns[0] !== " ") { - $optionId++; - $specifications[$id][$optionId] = [ - "name_fr" => trim($columns[0]), - "name_en" => trim($columns[1] ?: $columns[0]), - "name_de" => trim($columns[2] ?: $columns[0]) - ]; + // Parse rows of sheet + + foreach ($rows as $row => $columns) { + if ($row < 8) { + foreach ($fields as $key => $field) { + // Ignore first and second row (SKU, ID) + // Begin at third + $c = ($key + 2); + $value = $rows[$c][$index]; + + if (in_array($field, ["basic_selling_price", "basic_purschase_price", "conversion"])) { + $value = floatval($value); + } elseif ($field === "discount") { + $value = floatval(str_replace("%", "", $value)); } - if ($specifications) { - $specifications[$id][$optionId]["options"][] = [ - "name_fr" => trim($columns[3]), - "name_en" => trim($columns[4] ?: $columns[3]), - "name_de" => trim($columns[5] ?: $columns[3]), - "ref" => trim($columns[6]), - "purchase_price" => floatval($columns[7]), - "sale_price" => floatval($columns[8]) - ]; + if (in_array($field, ["category", "currency"])) { + $value = trim($value); } + $data[$id][$field] = $value; + } + } elseif ($row >= 9) { + if ($columns[0] && $columns[0] !== " ") { + $optionId++; + $specifications[$id][$optionId] = [ + "name_fr" => trim($columns[0]), + "name_en" => trim($columns[1] ?: $columns[0]), + "name_de" => trim($columns[2] ?: $columns[0]) + ]; + } + if ($specifications) { + $specifications[$id][$optionId]["options"][] = [ + "name_fr" => trim($columns[3]), + "name_en" => trim($columns[4] ?: $columns[3]), + "name_de" => trim($columns[5] ?: $columns[3]), + "ref" => trim($columns[6]), + "purchase_price" => floatval($columns[7]), + "sale_price" => floatval($columns[8]) + ]; } } - } catch(\Exception $e) { - $errorsMessage[] = "La feuille : $sheet, contient des erreurs"; - $contentMail["details"][$filename][$sheet] = "[ERREUR] Format invalide"; } $optionId = -1; } @@ -141,7 +135,6 @@ class ProductBaseController extends CubistMagicController { $data[$product]['json'] = json_encode($specification); } - $product = Product::whereIn('id', $ids) ->select('id') ->get() @@ -244,9 +237,9 @@ class ProductBaseController extends CubistMagicController { Mail::raw($contents, function ($message) { $message->from(config('mail.from.address'), config('mail.from.name')); $message->sender(config('mail.from.address'), config('mail.from.name')); - $message->to("soufiane@cubedesigners.com"); + $message->to(env('MAIL_TO_ADDRESS')); $message->bcc('test+pmi@cubedesigners.com'); - $message->subject("[Importation de fiche produit] Cubedesigners"); + $message->subject("[PMI] Import des fiches produits"); }); } } diff --git a/resources/views/components/item-cart.blade.php b/resources/views/components/item-cart.blade.php index baec875..96f3369 100644 --- a/resources/views/components/item-cart.blade.php +++ b/resources/views/components/item-cart.blade.php @@ -43,7 +43,7 @@ @php($price = $product['price'] - (($product['price'] * $product['discount']) / 100))

- {{ number_format($price * $product['quantity'], 2) }}€ HT + {{ $price * $product['quantity'] }}€ HT

@else

@@ -63,7 +63,7 @@ @if($item['total'])

{{ __('Montant Total') }}

-

{{ $item['total'] }}€ TTC

+

{{ $price * $product['quantity'] }}€ HT

@endif -- 2.39.5