]> _ Git - fluidbook-toolbox.git/commitdiff
wait #7513 @1.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 7 May 2025 16:30:01 +0000 (18:30 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 7 May 2025 16:30:01 +0000 (18:30 +0200)
app/Http/Controllers/Admin/Operations/FluidbookPublication/Services/PumaOperation.php

index 0874df4985da2cfefeb0a4e07ac692c883f4b8f9..dda9e90152824f29cdbeeb807a4cf5047ebc193d 100644 (file)
@@ -32,6 +32,9 @@ trait PumaOperation
             $cl->execute();
             return response()->download($tmp, $filename . '.pdf')->deleteFileAfterSend(true);
         }
+
+        $bottomStrings = ['shorts', 'pants'];
+
         $references = explode(',', $references);
         /** @var FluidbookPublication $book */
         $book = FluidbookPublication::withoutGlobalScopes()->where('id', $id)->where('cid', $cid)->firstOrFail();
@@ -42,14 +45,23 @@ trait PumaOperation
             if (!in_array($reference, $references)) {
                 continue;
             }
+
             $r[$reference] = $data;
             $title = trim(trim($data['Catégorie'] ?? '') . ' ' . trim($data['RBU'] ?? ''));
             $subtitle = trim(trim($data['Age Group'] ?? '') . ' - ' . $data['Gender'] . ' - ' . trim($data['Product Line'] ?? ''), '- ');
             $key = md5($title . $subtitle);
             if (!isset($planches[$key])) {
-                $planches[$key] = ['class' => $data['Catégorie'], 'title' => $title, 'subtitle' => $subtitle, 'products' => []];
+                $planches[$key] = ['class' => $data['Catégorie'], 'title' => $title, 'subtitle' => $subtitle, 'groups' => ['top' => [], 'bottom' => []]];
             }
-            $planches[$key]['products'][$reference] = $data;
+            $group = 'top';
+            foreach ($bottomStrings as $str) {
+                if (stristr($data['Article Type'], $str)) {
+                    $group = 'bottom';
+                    break;
+                }
+            }
+
+            $planches[$key]['groups'][$group][$reference] = $data;
         }
 
         $html = '<html>';
@@ -61,37 +73,52 @@ trait PumaOperation
         $html .= '</head>';
         $html .= '<body>';
         foreach ($planches as $data) {
-            $max = $data['class'] === 'Footwear' ? 20 : 18;
+            $cols = $data['class'] === 'Footwear' ? 5 : 6;
+            $rows = $data['class'] === 'Footwear' ? 4 : 3;
 
-            $subs = array_chunk($data['products'], $max, true);
+            $lines = [];
+            foreach ($data['groups'] as $group => $products) {
+                if (!count($products)) {
+                    continue;
+                }
+                $lines= array_merge($lines, array_chunk($products, $cols, true));;;
+            }
+
+            $subs = array_chunk($lines, $rows, true);
             $csubs = count($subs);
 
-            foreach ($subs as $i => $sub) {
+            foreach ($subs as $i => $lines) {
                 $pos = $csubs == 1 ? '' : ' (' . ($i + 1) . '/' . $csubs . ')';
                 $html .= '<section class="' . $data['class'] . '">';
                 $html .= '<h1>' . $data['title'] . '</h1>';
                 $html .= '<h2>' . $data['subtitle'] . $pos . '</h2>';
                 $html .= '<div class="products">';
-                foreach ($sub as $reference => $product) {
-                    if (isset($product['zoom_image'])) {
-                        $f = protected_path('fluidbookpublication/cache/zoomarea/zoomarea/books/' . $id . '/' . $product['zoom_image']);
-                        $img = Files::asDataURI($f);
-                        $img_attr = '';
-                    } else {
-                        $img = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+P+/HgAFhAJ/wlseKgAAAABJRU5ErkJggg==';
-                        $img_attr = ' width="40" height="40"';
-                    }
+                foreach ($lines as $line) {
+                    foreach ($line as $reference => $product) {
+                        if (isset($product['zoom_image'])) {
+                            $f = protected_path('fluidbookpublication/cache/zoomarea/zoomarea/books/' . $id . '/' . $product['zoom_image']);
+                            $img = Files::asDataURI($f);
+                            $img_attr = '';
+                        } else {
+                            $img = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+P+/HgAFhAJ/wlseKgAAAABJRU5ErkJggg==';
+                            $img_attr = ' width="40" height="40"';
+                        }
 
-                    $html .= '<article>';
-                    $html .= '<img ' . $img_attr . ' src="' . $img . '">';
-                    $html .= '<div class="infos">';
-                    $html .= '<h3>' . $reference . '</h3>';
-                    $html .= '<div>' . $product['Désignation'] ?? '' . '</div>';
-                    $html .= '<div>' . $product['Color Name'] ?? '' . '</div>';
-                    $html .= '<div>PA : ' . number_format(floatval($product['Tarif'] ?? 0), 2, ',', ' ') . ' € / PVP : ' . number_format(floatval($product['PVC'] ?? 0), 2, ',', ' ') . ' €</div>';
-                    $html .= '</div>';
-                    $html .= '</article>';
+                        $html .= '<article>';
+                        $html .= '<img ' . $img_attr . ' src="' . $img . '">';
+                        $html .= '<div class="infos">';
+                        $html .= '<h3>' . $reference . '</h3>';
+                        $html .= '<div>' . $product['Désignation'] ?? '' . '</div>';
+                        $html .= '<div>' . $product['Color Name'] ?? '' . '</div>';
+                        $html .= '<div>PA : ' . number_format(floatval($product['Tarif'] ?? 0), 2, ',', ' ') . ' € / PVP : ' . number_format(floatval($product['PVC'] ?? 0), 2, ',', ' ') . ' €</div>';
+                        $html .= '</div>';
+                        $html .= '</article>';
+                    }
+                    for ($i = count($line); $i < $cols; $i++) {
+                        $html .= '<article></article>';
+                    }
                 }
+
                 $html .= '</div>';
                 $html .= '</section>';
             }