-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathConfigController.php
More file actions
74 lines (61 loc) · 2.22 KB
/
ConfigController.php
File metadata and controls
74 lines (61 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
declare(strict_types=1);
/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/
namespace Pimcore\Bundle\EcommerceFrameworkBundle\Controller;
use Pimcore\Controller\KernelControllerEventInterface;
use Pimcore\Controller\UserAwareController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Routing\RouterInterface;
/**
* Class ConfigController
*
* @internal
*/
#[Route('/config')]
class ConfigController extends UserAwareController implements KernelControllerEventInterface
{
/**
* ConfigController constructor.
*
*/
public function __construct(private RouterInterface $router)
{
$this->router = $router;
}
public function onKernelControllerEvent(ControllerEvent $event): void
{
$this->checkPermission('bundle_ecommerce_back-office_order');
}
#[Route('/js-config', name: 'pimcore_ecommerceframework_config_jsconfig', methods: ['GET'])]
public function jsConfigAction(): Response
{
$config = $this->getParameter('pimcore_ecommerce.pimcore.config');
$orderList = $config['menu']['order_list'];
if ($orderList['route']) {
$orderList['route'] = $this->router->generate($orderList['route']);
} elseif ($orderList['path']) {
$orderList['route'] = $orderList['path'];
}
unset($orderList['path']);
$config['menu']['order_list'] = $orderList;
$javascript = 'pimcore.registerNS("pimcore.bundle.EcommerceFramework.config");' . PHP_EOL;
$javascript .= 'pimcore.bundle.EcommerceFramework.config = ';
$javascript .= json_encode($config) . ';';
$response = new Response($javascript);
$response->headers->set('Content-Type', 'application/javascript');
return $response;
}
}