|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Locastic\SyliusComparerPlugin\Controller\Action; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
8
|
|
|
use Locastic\SyliusComparerPlugin\Context\ComparerContextInterface; |
|
9
|
|
|
use Locastic\SyliusComparerPlugin\Entity\ComparerInterface; |
|
10
|
|
|
use Sylius\Component\Core\Model\ProductInterface; |
|
11
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
12
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
13
|
|
|
use Symfony\Component\Templating\EngineInterface; |
|
14
|
|
|
|
|
15
|
|
|
final class ListComparerProductsAction |
|
16
|
|
|
{ |
|
17
|
|
|
/** @var EngineInterface */ |
|
18
|
|
|
private $templatingEngine; |
|
19
|
|
|
|
|
20
|
|
|
/** @var EntityManagerInterface */ |
|
21
|
|
|
private $comparerManager; |
|
22
|
|
|
|
|
23
|
|
|
/** @var ComparerContextInterface */ |
|
24
|
|
|
private $comparerContext; |
|
25
|
|
|
|
|
26
|
|
|
/** @var string */ |
|
27
|
|
|
private $comparerCookieToken; |
|
28
|
|
|
|
|
29
|
|
|
public function __construct( |
|
30
|
|
|
EngineInterface $templatingEngine, |
|
31
|
|
|
EntityManagerInterface $comparerManager, |
|
32
|
|
|
ComparerContextInterface $comparerContext, |
|
33
|
|
|
string $comparerCookieToken |
|
34
|
|
|
) { |
|
35
|
|
|
$this->templatingEngine = $templatingEngine; |
|
36
|
|
|
$this->comparerManager = $comparerManager; |
|
37
|
|
|
$this->comparerContext = $comparerContext; |
|
38
|
|
|
$this->comparerCookieToken = $comparerCookieToken; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function __invoke(Request $request): Response |
|
42
|
|
|
{ |
|
43
|
|
|
/** @var ComparerInterface $comparer */ |
|
44
|
|
|
$comparer = $this->comparerContext->getComparer($request); |
|
45
|
|
|
|
|
46
|
|
|
/** @var ProductInterface $product */ |
|
47
|
|
|
$products = $comparer->getProducts(); |
|
48
|
|
|
$attributes = $comparer->getComparerAttributes($products, $request->getLocale(), $request->getDefaultLocale()); |
|
49
|
|
|
|
|
50
|
|
|
return new Response($this->templatingEngine->render( |
|
51
|
|
|
'@LocasticSyliusComparerPlugin/listComparer.html.twig', [ |
|
52
|
|
|
'products' => $comparer->getProducts(), |
|
53
|
|
|
'attributes' => $attributes, |
|
54
|
|
|
] |
|
55
|
|
|
)); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|