// 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;
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;
}
$data[$product]['json'] = json_encode($specification);
}
-
$product = Product::whereIn('id', $ids)
->select('id')
->get()
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");
});
}
}