1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright © O2TI. All rights reserved. |
4
|
|
|
* |
5
|
|
|
* @author Bruno Elisei <[email protected]> |
6
|
|
|
* See COPYING.txt for license details. |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace O2TI\AutoCompleteAddressBr\Helper; |
10
|
|
|
|
11
|
|
|
use Magento\Framework\App\Config\ScopeConfigInterface; |
12
|
|
|
use Magento\Framework\App\Helper\AbstractHelper; |
13
|
|
|
use Magento\Store\Model\ScopeInterface; |
14
|
|
|
use Magento\Store\Model\StoreManagerInterface; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class Config - Helper configuration. |
18
|
|
|
*/ |
19
|
|
|
class Config extends AbstractHelper |
20
|
|
|
{ |
21
|
|
|
public const CONFIG_PATH_GENERAL = 'auto_complete_address_br/general/%s'; |
22
|
|
|
|
23
|
|
|
public const CONFIG_PATH_RELATIONSHIP = 'auto_complete_address_br/general/relationship/%s'; |
24
|
|
|
|
25
|
|
|
public const CONFIG_PATH_UX = 'auto_complete_address_br/general/ux/%s'; |
26
|
|
|
|
27
|
|
|
public const CONFIG_PATH_DEVELOPER = 'auto_complete_address_br/general/developer/%s'; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var ScopeConfigInterface |
31
|
|
|
*/ |
32
|
|
|
protected $scopeConfig; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var StoreManagerInterface |
36
|
|
|
*/ |
37
|
|
|
protected $storeManagerInterface; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param ScopeConfigInterface $scopeConfig |
41
|
|
|
* @param StoreManagerInterface $storeManagerInterface |
42
|
|
|
*/ |
43
|
|
|
public function __construct( |
44
|
|
|
ScopeConfigInterface $scopeConfig, |
45
|
|
|
StoreManagerInterface $storeManagerInterface |
46
|
|
|
) { |
47
|
|
|
$this->scopeConfig = $scopeConfig; |
48
|
|
|
$this->storeManagerInterface = $storeManagerInterface; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Get Configs Module. |
53
|
|
|
* |
54
|
|
|
* @param string $field |
55
|
|
|
* |
56
|
|
|
* @return string |
57
|
|
|
*/ |
58
|
|
|
public function getConfigModule(string $field): ?string |
59
|
|
|
{ |
60
|
|
|
$storeId = $this->storeManagerInterface->getStore()->getId(); |
61
|
|
|
$configPath = sprintf(self::CONFIG_PATH_GENERAL, $field); |
62
|
|
|
|
63
|
|
|
return $this->scopeConfig->getValue($configPath, ScopeInterface::SCOPE_STORE, $storeId); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Get Config For Relation Ship. |
68
|
|
|
* |
69
|
|
|
* @param string $field |
70
|
|
|
* |
71
|
|
|
* @return string |
72
|
|
|
*/ |
73
|
|
|
public function getConfigForRelationShip(string $field): ?string |
74
|
|
|
{ |
75
|
|
|
$storeId = $this->storeManagerInterface->getStore()->getId(); |
76
|
|
|
$configPath = sprintf(self::CONFIG_PATH_RELATIONSHIP, $field); |
77
|
|
|
|
78
|
|
|
return $this->scopeConfig->getValue($configPath, ScopeInterface::SCOPE_STORE, $storeId); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Get Config For Ux. |
83
|
|
|
* |
84
|
|
|
* @param string $field |
85
|
|
|
* |
86
|
|
|
* @return string |
87
|
|
|
*/ |
88
|
|
|
public function getConfigForUx(string $field): ?string |
89
|
|
|
{ |
90
|
|
|
$storeId = $this->storeManagerInterface->getStore()->getId(); |
91
|
|
|
$configPath = sprintf(self::CONFIG_PATH_UX, $field); |
92
|
|
|
|
93
|
|
|
return $this->scopeConfig->getValue($configPath, ScopeInterface::SCOPE_STORE, $storeId); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Get Config For Developer. |
98
|
|
|
* |
99
|
|
|
* @param string $field |
100
|
|
|
* |
101
|
|
|
* @return string |
102
|
|
|
*/ |
103
|
|
|
public function getConfigForDeveloper(string $field): ?string |
104
|
|
|
{ |
105
|
|
|
$storeId = $this->storeManagerInterface->getStore()->getId(); |
106
|
|
|
$configPath = sprintf(self::CONFIG_PATH_DEVELOPER, $field); |
107
|
|
|
|
108
|
|
|
return $this->scopeConfig->getValue($configPath, ScopeInterface::SCOPE_STORE, $storeId); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* If module is Enabled. |
113
|
|
|
* |
114
|
|
|
* @return bool |
115
|
|
|
*/ |
116
|
|
|
public function isEnabled(): ?bool |
117
|
|
|
{ |
118
|
|
|
return $this->getConfigModule('enabled'); |
|
|
|
|
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* If use Input Masking. |
123
|
|
|
* |
124
|
|
|
* @return bool |
125
|
|
|
*/ |
126
|
|
|
public function useInputMasking(): ?bool |
127
|
|
|
{ |
128
|
|
|
return $this->getConfigForUx('compatibility_o2ti_inputmasking'); |
|
|
|
|
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* If Hide Taret Fields. |
133
|
|
|
* |
134
|
|
|
* @return bool |
135
|
|
|
*/ |
136
|
|
|
public function isHideTargetFields(): ?bool |
137
|
|
|
{ |
138
|
|
|
return $this->getConfigForUx('hide_target_fields'); |
|
|
|
|
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
|