-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCommunication.php
More file actions
executable file
·120 lines (97 loc) · 3.96 KB
/
Copy pathCommunication.php
File metadata and controls
executable file
·120 lines (97 loc) · 3.96 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
<?php
declare(strict_types=1);
namespace Omikron\FactFinder\Oxid\Model\Config;
use Omikron\FactFinder\Oxid\Contract\Config\ParametersSourceInterface;
use Omikron\FactFinder\Oxid\Export\Filter\TextFilter;
use OxidEsales\Eshop\Application\Model\Category;
use OxidEsales\Eshop\Core\Controller\BaseController;
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
use OxidEsales\EshopCommunity\Internal\Framework\Module\Facade\ModuleSettingServiceInterface;
class Communication implements ParametersSourceInterface
{
private TextFilter $filter;
private ModuleSettingServiceInterface $moduleSettingService;
public function __construct(protected readonly BaseController $view)
{
$this->filter = oxNew(TextFilter::class);
$this->moduleSettingService = ContainerFactory::getInstance()
->getContainer()
->get(ModuleSettingServiceInterface::class);
}
/**
* @SuppressWarnings("PMD.CyclomaticComplexity")
*
* @return array
*/
public function getParameters(): array
{
$category = $this->view->getActiveCategory();
$params = [
'url' => $this->getServerUrl(),
'version' => 'ng',
'api' => $this->getApiVersion(),
'channel' => $this->getChannel($this->view->getActiveLangAbbr()),
'currency-code' => $this->view->getActCurrency()->name,
'currency-country-code' => $this->getLocale($this->view->getActiveLangAbbr()),
'search-immediate' => $this->isSearch() || $this->useForCategories() || $this->useProxy() ? 'true' : 'false',
'category-page' => $this->useForCategories() ? $this->getCategoryPath($category) : null,
];
return $params;
}
public function getTrackingSettings(): array
{
return [
'addToCart' => [
'count' => (string) $this->moduleSettingService->getString('ffTrackingAddToCartCount', 'ffwebcomponents') ?? 'count_selected_amount',
],
];
}
public function useSidAsUserId(): bool
{
return $this->moduleSettingService->getBoolean('ffSidAsUserId', 'ffwebcomponents') ?? false;
}
protected function getLocale(string $abbr): string
{
$locales = ['de' => 'de-DE', 'en' => 'en-US'];
return $locales[$abbr] ?? $locales['en'];
}
protected function getServerUrl(): string
{
return (string) $this->moduleSettingService->getBoolean('ffUseProxy', 'ffwebcomponents') ?
'' :
(string) $this->moduleSettingService->getString('ffServerUrl', 'ffwebcomponents');
}
protected function getCategoryPath(Category $category): string
{
$categories = [$this->filter->filterValue($category->getTitle())];
while ($parent = $category->getParentCategory()) {
$categories[] = $this->filter->filterValue($parent->getTitle());
$category = $parent;
}
return implode(',', array_reverse($categories));
}
protected function isSearch(): bool
{
return $this->view->getActionClassName() === 'search_result';
}
protected function useForCategories(): bool
{
return $this->moduleSettingService->getBoolean('ffUseForCategories', 'ffwebcomponents') && $this->view->getActionClassName() === 'alist';
}
protected function getChannel(string $langAbbr): string
{
$channels = $this->moduleSettingService->getCollection('ffChannel', 'ffwebcomponents');
if (!isset($channels[$langAbbr])) {
throw new \RuntimeException("No channel for used language: $langAbbr");
}
return $channels[$langAbbr];
}
protected function getApiVersion(): string
{
return 'v5';
}
private function useProxy(): bool
{
return (bool) $this->moduleSettingService->getBoolean('ffUseProxy', 'ffwebcomponents');
}
}