]> _ Git - pmi.git/commitdiff
wait #6172 @0:10
authorsoufiane <soufiane@cubedesigners.com>
Wed, 26 Jul 2023 11:15:07 +0000 (13:15 +0200)
committersoufiane <soufiane@cubedesigners.com>
Wed, 26 Jul 2023 11:15:07 +0000 (13:15 +0200)
app/Http/Controllers/Admin/ProductBaseController.php
resources/views/components/item-cart.blade.php

index e9ff728b5b0d93078c238e1d9f46f8c3ba721ebf..6babbfdcb0907a336dbfa8a3ae005af83fd3ba3c 100644 (file)
@@ -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");
         });
     }
 }
index baec87505333b896aa4bcce331a9b6c6537fe2f1..96f3369866d92fa5249d4a6233f9063e8fde8682 100644 (file)
@@ -43,7 +43,7 @@
                                 @php($price = $product['price'] - (($product['price'] * $product['discount']) / 100))
                                 <p class="no-m">
                                     <span class="sm:inline hidden">{{ __('Total HT : ') }}</span>
-                                    {{ number_format($price * $product['quantity'], 2) }}€ HT
+                                    {{ $price * $product['quantity'] }}€ HT
                                 </p>
                             @else
                                 <p class="text-navy">
@@ -63,7 +63,7 @@
                 @if($item['total'])
                     <div class="text-right pb-6">
                         <p class="no-m">{{ __('Montant Total') }}</p>
-                        <p class="no-m">{{ $item['total'] }}€ TTC</p>
+                        <p class="no-m">{{ $price * $product['quantity'] }}€ HT</p>
                     </div>
                 @endif
             </div>