This repository was archived by the owner on Apr 20, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathIndexController.php
More file actions
184 lines (153 loc) · 6.89 KB
/
IndexController.php
File metadata and controls
184 lines (153 loc) · 6.89 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<?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\Bundle\EcommerceFrameworkBundle\Event\AdminEvents;
use Pimcore\Bundle\EcommerceFrameworkBundle\Factory;
use Pimcore\Bundle\EcommerceFrameworkBundle\IndexService\ProductList\ProductListInterface;
use Pimcore\Controller\KernelControllerEventInterface;
use Pimcore\Controller\Traits\JsonHelperTrait;
use Pimcore\Controller\UserAwareController;
use Symfony\Component\EventDispatcher\GenericEvent;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
/**
* Class IndexController
*
* @internal
*/
#[Route('/index')]
class IndexController extends UserAwareController implements KernelControllerEventInterface
{
use JsonHelperTrait;
public function onKernelControllerEvent(ControllerEvent $event): void
{
$this->checkPermission('bundle_ecommerce_back-office_order');
}
#[Route('/get-filter-groups', name: 'pimcore_ecommerceframework_index_getfiltergroups', methods: ['GET'])]
public function getFilterGroupsAction(): JsonResponse
{
$indexService = Factory::getInstance()->getIndexService();
$tenants = Factory::getInstance()->getAllTenants();
$filterGroups = $indexService->getAllFilterGroups();
if ($tenants) {
foreach ($tenants as $tenant) {
$filterGroups = array_merge($filterGroups, $indexService->getAllFilterGroups($tenant));
}
}
$data = [];
if ($filterGroups) {
sort($filterGroups);
foreach ($filterGroups as $group) {
$data[$group] = ['data' => $group];
}
}
return $this->jsonResponse(['data' => array_values($data)]);
}
#[Route(
'/get-values-for-filter-field',
name: 'pimcore_ecommerceframework_index_getvaluesforfilterfield',
methods: ['GET']
)]
public function getValuesForFilterFieldAction(Request $request, EventDispatcherInterface $eventDispatcher): JsonResponse
{
try {
$data = [];
$factory = Factory::getInstance();
if ($request->get('field')) {
if ($request->get('tenant')) {
Factory::getInstance()->getEnvironment()->setCurrentAssortmentTenant($request->get('tenant'));
}
$indexService = $factory->getIndexService();
$filterService = $factory->getFilterService();
$columnGroup = '';
$filterGroups = $indexService->getAllFilterGroups();
foreach ($filterGroups as $filterGroup) {
$fields = $indexService->getIndexAttributesByFilterGroup($filterGroup);
foreach ($fields as $field) {
if ($field == $request->get('field')) {
$columnGroup = $filterGroup;
break 2;
}
}
}
$factory->getEnvironment()->setCurrentAssortmentSubTenant(null);
$productList = $factory->getIndexService()->getProductListForCurrentTenant();
$helper = $filterService->getFilterGroupHelper();
$data = $helper->getGroupByValuesForFilterGroup($columnGroup, $productList, $request->get('field'));
}
$event = new GenericEvent(null, ['data' => $data, 'field' => $request->get('field')]);
$eventDispatcher->dispatch($event, AdminEvents::GET_VALUES_FOR_FILTER_FIELD_PRE_SEND_DATA);
$data = $event->getArgument('data');
return $this->jsonResponse(['data' => array_values($data)]);
} catch (\Exception $e) {
return $this->jsonResponse(['message' => $e->getMessage()]);
}
}
#[Route('/get-fields', name: 'pimcore_ecommerceframework_index_getfields', methods: ['GET'])]
public function getFieldsAction(Request $request, EventDispatcherInterface $eventDispatcher, TranslatorInterface $translator): JsonResponse
{
$indexService = Factory::getInstance()->getIndexService();
if ($request->get('filtergroup')) {
$filtergroups = $request->get('filtergroup');
$indexColumns = [];
foreach ($filtergroups as $filtergroup) {
$indexColumns = array_merge($indexColumns, $indexService->getIndexAttributesByFilterGroup($filtergroup, $request->get('tenant')));
}
} else {
if ($request->get('show_all_fields') == 'true') {
$indexColumns = $indexService->getIndexAttributes(false, $request->get('tenant'));
} else {
$indexColumns = $indexService->getIndexAttributes(true, $request->get('tenant'));
}
}
if (!$indexColumns) {
$indexColumns = [];
}
$fields = [];
if ($request->get('add_empty') == 'true') {
$fields[' '] = ['key' => '', 'name' => '(' . $translator->trans('empty', [], 'messages') . ')'];
}
foreach ($indexColumns as $c) {
$fields[$c] = ['key' => $c, 'name' => $translator->trans($c, [], 'admin')];
}
if ($request->get('specific_price_field') == 'true') {
$fields[ProductListInterface::ORDERKEY_PRICE] = [
'key' => ProductListInterface::ORDERKEY_PRICE,
'name' => $translator->trans(ProductListInterface::ORDERKEY_PRICE, [], 'admin'),
];
}
ksort($fields);
$event = new GenericEvent(null, ['data' => $fields]);
$eventDispatcher->dispatch($event, AdminEvents::GET_INDEX_FIELD_NAMES_PRE_SEND_DATA);
$data = $event->getArgument('data');
return $this->jsonResponse(['data' => array_values($data)]);
}
#[Route('/get-all-tenants', name: 'pimcore_ecommerceframework_index_getalltenants', methods: ['GET'])]
public function getAllTenantsAction(TranslatorInterface $translator): JsonResponse
{
$tenants = Factory::getInstance()->getAllTenants();
$data = [];
if ($tenants) {
foreach ($tenants as $tenant) {
$data[] = ['key' => $tenant, 'name' => $translator->trans($tenant, [], 'admin')];
}
}
return $this->jsonResponse(['data' => $data]);
}
}