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\TaxDocumentValidationBr\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 - Get Configs Module. |
18
|
|
|
*/ |
19
|
|
|
class Config extends AbstractHelper |
20
|
|
|
{ |
21
|
|
|
public const CONFIG_PATH_GENERAL = 'tax_document_validation_br/general/%s'; |
22
|
|
|
|
23
|
|
|
public const CONFIG_PATH_VAT_ID = 'tax_document_validation_br/general/vat_id/%s'; |
24
|
|
|
|
25
|
|
|
public const CONFIG_PATH_TAXVAT = 'tax_document_validation_br/general/taxvat/%s'; |
26
|
|
|
|
27
|
|
|
public const VAT_ONLY_CPF = 'vatid-br-rule-only-cpf'; |
28
|
|
|
|
29
|
|
|
public const VAT_ONLY_CNPJ = 'vatid-br-rule-only-cnpj'; |
30
|
|
|
|
31
|
|
|
public const VAT_CPF_OR_CNPJ = 'vatid-br-rule-cpf-or-cnpj'; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var ScopeConfigInterface |
35
|
|
|
*/ |
36
|
|
|
protected $scopeConfig; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var StoreManagerInterface |
40
|
|
|
*/ |
41
|
|
|
protected $storeManagerInterface; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param ScopeConfigInterface $scopeConfig |
45
|
|
|
* @param StoreManagerInterface $storeManagerInterface |
46
|
|
|
*/ |
47
|
|
|
public function __construct( |
48
|
|
|
ScopeConfigInterface $scopeConfig, |
49
|
|
|
StoreManagerInterface $storeManagerInterface |
50
|
|
|
) { |
51
|
|
|
$this->scopeConfig = $scopeConfig; |
52
|
|
|
$this->storeManagerInterface = $storeManagerInterface; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Get Configs Module. |
57
|
|
|
* |
58
|
|
|
* @param string $field |
59
|
|
|
* |
60
|
|
|
* @return string |
61
|
|
|
*/ |
62
|
|
|
public function getConfigModule(string $field): ?bool |
63
|
|
|
{ |
64
|
|
|
$storeId = $this->storeManagerInterface->getStore()->getId(); |
65
|
|
|
$path = str_replace('%s', $field, self::CONFIG_PATH_GENERAL); |
66
|
|
|
|
67
|
|
|
return $this->scopeConfig->getValue($path, ScopeInterface::SCOPE_STORE, $storeId); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Get Config By VatId. |
72
|
|
|
* |
73
|
|
|
* @param string $field |
74
|
|
|
* |
75
|
|
|
* @return string |
76
|
|
|
*/ |
77
|
|
|
public function getConfigByVatId(string $field): ?bool |
78
|
|
|
{ |
79
|
|
|
$storeId = $this->storeManagerInterface->getStore()->getId(); |
80
|
|
|
$path = str_replace('%s', $field, self::CONFIG_PATH_VAT_ID); |
81
|
|
|
|
82
|
|
|
return $this->scopeConfig->getValue($path, ScopeInterface::SCOPE_STORE, $storeId); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Get Config By Taxvat. |
87
|
|
|
* |
88
|
|
|
* @param string $field |
89
|
|
|
* |
90
|
|
|
* @return string |
91
|
|
|
*/ |
92
|
|
|
public function getConfigByTaxvat(string $field): ?bool |
93
|
|
|
{ |
94
|
|
|
$storeId = $this->storeManagerInterface->getStore()->getId(); |
95
|
|
|
$path = str_replace('%s', $field, self::CONFIG_PATH_TAXVAT); |
96
|
|
|
|
97
|
|
|
return $this->scopeConfig->getValue($path, ScopeInterface::SCOPE_STORE, $storeId); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Get If is Enabled Module. |
102
|
|
|
* |
103
|
|
|
* @return bool |
104
|
|
|
*/ |
105
|
|
|
public function isEnabled(): ?bool |
106
|
|
|
{ |
107
|
|
|
return $this->getConfigModule('enabled'); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|