From: Vincent Vanwaelscappel Date: Tue, 7 Oct 2025 17:13:02 +0000 (+0200) Subject: wip #7776 @12 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=91c367eaec2cb12862a4c9e423311f797b6356d3;p=fluidbook-toolbox.git wip #7776 @12 --- diff --git a/app/Http/Controllers/Admin/Operations/FluidbookPublication/Services/PumaOperation.php b/app/Http/Controllers/Admin/Operations/FluidbookPublication/Services/PumaOperation.php index c918f694f..edd59343e 100644 --- a/app/Http/Controllers/Admin/Operations/FluidbookPublication/Services/PumaOperation.php +++ b/app/Http/Controllers/Admin/Operations/FluidbookPublication/Services/PumaOperation.php @@ -53,16 +53,28 @@ trait PumaOperation $subtitle = trim(trim($data['Age Group'] ?? '') . ' - ' . $data['Genre'] . ' - ' . trim($data['Product Line'] ?? ''), '- '); $key = md5($title . $subtitle); if (!isset($planches[$key])) { - $planches[$key] = ['class' => $data['Catégorie'], 'title' => $title, 'subtitle' => $subtitle, 'groups' => ['top' => [], 'bottom' => []]]; + $planches[$key] = ['class' => $data['Catégorie'], 'title' => $title, 'subtitle' => $subtitle, 'bottomsbycolor' => [], 'groups' => ['top' => [], 'bottom' => []]]; } - $group = 'top'; - foreach ($bottomStrings as $str) { - if (stristr($data['Article Type'], $str) !== false) { - $group = 'bottom'; - break; + if ($data['Catégorie'] === 'Footwear') { + $group = 'footwear'; + } else { + $group = 'top'; + foreach ($bottomStrings as $str) { + if (stristr($data['Article Type'], $str) !== false) { + $group = 'bottom'; + break; + } } } + $data['group'] = $group; + if ($group === 'bottom') { + $colorCode = $data['Couleur']; + if (!isset($planches[$key]['bottomsbycolor'][$colorCode])) { + $planches[$key]['bottomsbycolor'][$colorCode] = []; + } + $planches[$key]['bottomsbycolor'][$colorCode][$reference] = $data; + } $planches[$key]['groups'][$group][$reference] = $data; } @@ -76,10 +88,13 @@ trait PumaOperation $html .= ''; foreach ($planches as $data) { $cols = $data['class'] === 'Footwear' ? 5 : 6; - $rows = $data['class'] === 'Footwear' ? 4 : 2; + $rows = $data['class'] === 'Footwear' ? 4 : 1; $lines = []; foreach ($data['groups'] as $group => $products) { + if ($group === 'bottom') { + continue; + } if (!count($products)) { continue; } @@ -87,63 +102,39 @@ trait PumaOperation } $subs = array_chunk($lines, $rows, true); - $csubs = count($subs); - $emptyImg = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+P+/HgAFhAJ/wlseKgAAAABJRU5ErkJggg=='; - $emptyImgAttr = ' class="empty" '; + $countSection = 0; + + $all = ''; foreach ($subs as $i => $lines) { - $pos = $csubs == 1 ? '' : ' (' . ($i + 1) . '/' . $csubs . ')'; - $html .= '
'; - $html .= '

' . $data['title'] . '

'; - $html .= '

' . $data['subtitle'] . $pos . '

'; - $html .= '
'; - 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']); - if (file_exists($f)) { - $img = Files::asDataURI($f); - $img_attr = ' data-file="' . $f . '" '; - } else { - $img = $emptyImg; - $img_attr = $emptyImgAttr; - } - } else { - $img = $emptyImg; - $img_attr = $emptyImgAttr; - } - - $html .= '
'; - $html .= ''; - $html .= '
'; - $html .= '

' . $reference . '

'; - $html .= '
' . $product['Désignation'] ?? '' . '
'; - $html .= '
' . $product['Color Name'] ?? '' . '
'; - if ($pa || $pvp) { - $html .= '
'; - if ($pa) { - $html .= 'PA : ' . number_format(floatval($product['Tarif'] ?? 0), 2, ',', ' ') . ' € '; - } - if ($pa && $pvp) { - $html .= ' / '; - } - if ($pvp) { - $html .= 'PVP : ' . number_format(floatval($product['PVC'] ?? 0), 2, ',', ' ') . ' €'; - } - $html .= '
'; - } - $html .= '
'; - $html .= '
'; - } - for ($i = count($line); $i < $cols; $i++) { - $html .= '
'; - } + $all .= $this->_renderSection($data, $lines, $cols, $id, $pa, $pvp); + $countSection++; + } + + if (count($data['groups']['bottom']) > 0) { + $rows = 2; + $products = $data['groups']['bottom']; + $lines = array_chunk($products, $cols, true); + $subs = array_chunk($lines, $rows, true); + foreach ($subs as $i => $lines) { + $all .= $this->_renderSection($data, $lines, $cols, $id, $pa, $pvp); + $countSection++; } + } - $html .= '
'; - $html .= '
'; + if ($countSection <= 1) { + $all = str_replace('$pos', '', $all); + } else { + $i = 1; + $all = preg_replace_callback('/\$pos/', function ($matches) use ($countSection, &$i) { + $res = ' (' . $i . '/' . $countSection . ')'; + $i++; + return $res; + }, $all); } + + $html .= $all; } $html .= ''; return $html; @@ -154,4 +145,82 @@ trait PumaOperation return file_get_contents(resource_path('puma/planogramme/style.css')); } + protected function _renderSection(&$data, $lines, $cols, $id, $pa, $pvp) + { + $html = '
'; + $html .= '

' . $data['title'] . '

'; + $html .= '

' . $data['subtitle'] . '$pos

'; + $html .= '
'; + foreach ($lines as $line) { + $bottomLine = []; + $hasBottomLine = false; + foreach ($line as $reference => $product) { + $html .= '
' . $this->_renderProduct($reference, $product, $id, $pa, $pvp) . '
'; + if ($product['group'] === 'top' && isset($data['bottomsbycolor'][$product['Couleur']])) { + foreach ($data['bottomsbycolor'][$product['Couleur']] as $r => $p) { + $bottomLine[] = $this->_renderProduct($r, $p, $id, $pa, $pvp); + $hasBottomLine = true; + unset($data['groups']['bottom'][$r]); + unset($data['bottomsbycolor'][$product['Couleur']][$r]); + break; + } + } else { + $bottomLine[] = ''; + } + } + for ($i = count($line); $i < $cols; $i++) { + $html .= '
'; + } + + if ($hasBottomLine) { + $html .= '
' . implode('
', $bottomLine) . '
'; + } + } + $html .= '
'; + $html .= '
'; + return $html; + } + + protected function _renderProduct($reference, $product, $id, $pa, $pvp) + { + $emptyImg = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+P+/HgAFhAJ/wlseKgAAAABJRU5ErkJggg=='; + $emptyImgAttr = ' class="empty" '; + $html = ''; + if (isset($product['zoom_image'])) { + $f = protected_path('fluidbookpublication/cache/zoomarea/zoomarea/books/' . $id . '/' . $product['zoom_image']); + if (file_exists($f)) { + $img = Files::asDataURI($f); + $img_attr = ' data-file="' . $f . '" '; + } else { + $img = $emptyImg; + $img_attr = $emptyImgAttr; + } + } else { + $img = $emptyImg; + $img_attr = $emptyImgAttr; + } + + + $html .= ''; + $html .= '
'; + $html .= '

' . $reference . '

'; + $html .= '
' . $product['Désignation'] ?? '' . '
'; + $html .= '
' . $product['Color Name'] ?? '' . '
'; + if ($pa || $pvp) { + $html .= '
'; + if ($pa) { + $html .= 'PA : ' . number_format(floatval($product['Tarif'] ?? 0), 2, ',', ' ') . ' € '; + } + if ($pa && $pvp) { + $html .= ' / '; + } + if ($pvp) { + $html .= 'PVP : ' . number_format(floatval($product['PVC'] ?? 0), 2, ',', ' ') . ' €'; + } + $html .= '
'; + } + $html .= '
'; + return $html; + } + }