|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file was created by developers working at BitBag |
|
5
|
|
|
* Do you need more information about us and what we do? Visit our https://bitbag.io website! |
|
6
|
|
|
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
declare(strict_types=1); |
|
10
|
|
|
|
|
11
|
|
|
namespace BitBag\SyliusCmsPlugin\Twig\Runtime; |
|
12
|
|
|
|
|
13
|
|
|
use BitBag\SyliusCmsPlugin\Repository\PageRepositoryInterface; |
|
14
|
|
|
use BitBag\SyliusCmsPlugin\Sorter\SectionsSorterInterface; |
|
15
|
|
|
use Sylius\Component\Channel\Context\ChannelContextInterface; |
|
16
|
|
|
use Sylius\Component\Core\Model\ProductInterface; |
|
17
|
|
|
use Twig\Environment; |
|
18
|
|
|
use Webmozart\Assert\Assert; |
|
19
|
|
|
|
|
20
|
|
|
final class RenderProductPagesRuntime implements RenderProductPagesRuntimeInterface |
|
21
|
|
|
{ |
|
22
|
|
|
/** @var PageRepositoryInterface */ |
|
23
|
|
|
private $pageRepository; |
|
24
|
|
|
|
|
25
|
|
|
/** @var ChannelContextInterface */ |
|
26
|
|
|
private $channelContext; |
|
27
|
|
|
|
|
28
|
|
|
/** @var Environment */ |
|
29
|
|
|
private $templatingEngine; |
|
30
|
|
|
|
|
31
|
|
|
/** @var SectionsSorterInterface */ |
|
32
|
|
|
private $sectionsSorter; |
|
33
|
|
|
|
|
34
|
|
|
public function __construct( |
|
35
|
|
|
PageRepositoryInterface $pageRepository, |
|
36
|
|
|
ChannelContextInterface $channelContext, |
|
37
|
|
|
Environment $templatingEngine, |
|
38
|
|
|
SectionsSorterInterface $sectionsSorter |
|
39
|
|
|
) { |
|
40
|
|
|
$this->pageRepository = $pageRepository; |
|
41
|
|
|
$this->channelContext = $channelContext; |
|
42
|
|
|
$this->templatingEngine = $templatingEngine; |
|
43
|
|
|
$this->sectionsSorter = $sectionsSorter; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function renderProductPages(ProductInterface $product, string $sectionCode = null): string |
|
47
|
|
|
{ |
|
48
|
|
|
$channelCode = $this->channelContext->getChannel()->getCode(); |
|
49
|
|
|
Assert::notNull($channelCode, 'Channel code for channel is null'); |
|
50
|
|
|
if (null !== $sectionCode) { |
|
51
|
|
|
$pages = $this->pageRepository->findByProductAndSectionCode($product, $sectionCode, $channelCode, null); |
|
|
|
|
|
|
52
|
|
|
} else { |
|
53
|
|
|
$pages = $this->pageRepository->findByProduct($product, $channelCode, null); |
|
|
|
|
|
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
$data = $this->sectionsSorter->sortBySections($pages); |
|
57
|
|
|
|
|
58
|
|
|
return $this->templatingEngine->render('@BitBagSyliusCmsPlugin/Shop/Product/_pagesBySection.html.twig', [ |
|
59
|
|
|
'data' => $data, |
|
60
|
|
|
]); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|