|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file has been created by developers from BitBag. |
|
5
|
|
|
* Feel free to contact us once you face any issues or want to start |
|
6
|
|
|
* another great project. |
|
7
|
|
|
* You can find more information about us on https://bitbag.shop and write us |
|
8
|
|
|
* an email on [email protected]. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
declare(strict_types=1); |
|
12
|
|
|
|
|
13
|
|
|
namespace BitBag\SyliusCmsPlugin\Twig\Extension; |
|
14
|
|
|
|
|
15
|
|
|
use BitBag\SyliusCmsPlugin\Twig\Runtime\RenderProductPagesRuntime; |
|
16
|
|
|
use Twig\Extension\AbstractExtension; |
|
17
|
|
|
use Twig\TwigFunction; |
|
18
|
|
|
|
|
19
|
|
|
final class RenderProductPagesExtension extends AbstractExtension |
|
20
|
|
|
{ |
|
21
|
|
|
public function getFunctions(): array |
|
22
|
|
|
{ |
|
23
|
|
|
return [ |
|
24
|
|
|
new TwigFunction('bitbag_cms_render_product_pages', [RenderProductPagesRuntime::class, 'renderProductPages'], ['is_safe' => ['html']]), |
|
25
|
|
|
]; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function renderProductPages(ProductInterface $product, ?string $sectionCode = null, ?string $date = null): string |
|
|
|
|
|
|
29
|
|
|
{ |
|
30
|
|
|
$channelCode = $this->channelContext->getChannel()->getCode(); |
|
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
$parsedDate = null; |
|
33
|
|
|
if (!empty($date)) { |
|
34
|
|
|
$parsedDate = new \DateTimeImmutable($date); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
if (null !== $sectionCode) { |
|
38
|
|
|
$pages = $this->pageRepository->findByProductAndSectionCode($product, $sectionCode, $channelCode, $parsedDate); |
|
|
|
|
|
|
39
|
|
|
} else { |
|
40
|
|
|
$pages = $this->pageRepository->findByProduct($product, $channelCode, $parsedDate); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
$data = $this->sortBySections($pages); |
|
44
|
|
|
|
|
45
|
|
|
return $this->templatingEngine->render('@BitBagSyliusCmsPlugin/Shop/Product/_pagesBySection.html.twig', [ |
|
|
|
|
|
|
46
|
|
|
'data' => $data, |
|
47
|
|
|
]); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
private function sortBySections(array $pages): array |
|
51
|
|
|
{ |
|
52
|
|
|
$result = []; |
|
53
|
|
|
|
|
54
|
|
|
/** @var PageInterface $page */ |
|
55
|
|
|
foreach ($pages as $page) { |
|
56
|
|
|
foreach ($page->getSections() as $section) { |
|
57
|
|
|
$sectionCode = $section->getCode(); |
|
58
|
|
|
if (!array_key_exists($sectionCode, $result)) { |
|
59
|
|
|
$result[$sectionCode] = []; |
|
60
|
|
|
$result[$sectionCode]['section'] = $section; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
$result[$sectionCode][] = $page; |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
return $result; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths