|
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.io and write us |
|
8
|
|
|
* an email on [email protected]. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
declare(strict_types=1); |
|
12
|
|
|
|
|
13
|
|
|
namespace BitBag\SyliusCmsPlugin\Twig\Runtime; |
|
14
|
|
|
|
|
15
|
|
|
use BitBag\SyliusCmsPlugin\Repository\PageRepositoryInterface; |
|
16
|
|
|
use BitBag\SyliusCmsPlugin\Sorter\SectionsSorterInterface; |
|
17
|
|
|
use Sylius\Component\Channel\Context\ChannelContextInterface; |
|
18
|
|
|
use Sylius\Component\Core\Model\ProductInterface; |
|
19
|
|
|
use Twig\Environment; |
|
20
|
|
|
|
|
21
|
|
|
final class RenderProductPagesRuntime implements RenderProductPagesRuntimeInterface |
|
22
|
|
|
{ |
|
23
|
|
|
/** @var PageRepositoryInterface */ |
|
24
|
|
|
private $pageRepository; |
|
25
|
|
|
|
|
26
|
|
|
/** @var ChannelContextInterface */ |
|
27
|
|
|
private $channelContext; |
|
28
|
|
|
|
|
29
|
|
|
/** @var Environment */ |
|
30
|
|
|
private $templatingEngine; |
|
31
|
|
|
|
|
32
|
|
|
/** @var SectionsSorterInterface */ |
|
33
|
|
|
private $sectionsSorter; |
|
34
|
|
|
|
|
35
|
|
|
public function __construct( |
|
36
|
|
|
PageRepositoryInterface $pageRepository, |
|
37
|
|
|
ChannelContextInterface $channelContext, |
|
38
|
|
|
Environment $templatingEngine, |
|
39
|
|
|
SectionsSorterInterface $sectionsSorter |
|
40
|
|
|
) { |
|
41
|
|
|
$this->pageRepository = $pageRepository; |
|
42
|
|
|
$this->channelContext = $channelContext; |
|
43
|
|
|
$this->templatingEngine = $templatingEngine; |
|
44
|
|
|
$this->sectionsSorter = $sectionsSorter; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function renderProductPages(ProductInterface $product, string $sectionCode = null): string |
|
48
|
|
|
{ |
|
49
|
|
|
$channelCode = $this->channelContext->getChannel()->getCode(); |
|
50
|
|
|
|
|
51
|
|
|
if (null !== $sectionCode) { |
|
52
|
|
|
$pages = $this->pageRepository->findByProductAndSectionCode($product, $sectionCode, $channelCode); |
|
|
|
|
|
|
53
|
|
|
} else { |
|
54
|
|
|
$pages = $this->pageRepository->findByProduct($product, $channelCode); |
|
|
|
|
|
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
$data = $this->sectionsSorter->sortBySections($pages); |
|
58
|
|
|
|
|
59
|
|
|
return $this->templatingEngine->render('@BitBagSyliusCmsPlugin/Shop/Product/_pagesBySection.html.twig', [ |
|
60
|
|
|
'data' => $data, |
|
61
|
|
|
]); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.