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\Plugin; |
10
|
|
|
|
11
|
|
|
use Magento\Customer\Helper\Address; |
12
|
|
|
use O2TI\TaxDocumentValidationBr\Helper\Config; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class CustomerTaxDocumentValidationBrAddRule - Add classes for validation atribute. |
16
|
|
|
*/ |
17
|
|
|
class CustomerTaxDocumentValidationBrAddRule |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var Config |
21
|
|
|
*/ |
22
|
|
|
private $config; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* TaxDocumentValidationBrAddRule constructor. |
26
|
|
|
* |
27
|
|
|
* @param Config $config |
28
|
|
|
*/ |
29
|
|
|
public function __construct( |
30
|
|
|
Config $config |
31
|
|
|
) { |
32
|
|
|
$this->config = $config; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Add Class to VatId. |
37
|
|
|
* |
38
|
|
|
* @param Address $subject |
39
|
|
|
* @param callable $proceed |
40
|
|
|
* @param string $args |
41
|
|
|
* |
42
|
|
|
* @return string |
43
|
|
|
*/ |
44
|
|
|
public function aroundGetAttributeValidationClass(Address $subject, callable $proceed, string $args): string |
|
|
|
|
45
|
|
|
{ |
46
|
|
|
$result = $proceed($args); |
47
|
|
|
if ($args == 'vat_id') { |
48
|
|
|
if ($this->config->isEnabled()) { |
49
|
|
|
$add = 'required-entry '; |
50
|
|
|
if ($this->config->getConfigByVatId('enabled_cpf') && $this->config->getConfigByVatId('enabled_cnpj')) { |
51
|
|
|
$add .= Config::VAT_CPF_OR_CNPJ; |
52
|
|
|
} elseif ($this->config->getConfigByVatId('enabled_cpf')) { |
53
|
|
|
$add .= Config::VAT_ONLY_CPF; |
54
|
|
|
} elseif ($this->config->getConfigByVatId('enabled_cnpj')) { |
55
|
|
|
$add .= Config::VAT_ONLY_CNPJ; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
$result .= $add; |
59
|
|
|
} |
60
|
|
|
} elseif ($args == 'taxvat') { |
61
|
|
|
if ($this->config->getConfigByTaxvat('enabled_cpf') && $this->config->getConfigByTaxvat('enabled_cnpj')) { |
62
|
|
|
$add = Config::VAT_CPF_OR_CNPJ; |
63
|
|
|
} elseif ($this->config->getConfigByTaxvat('enabled_cpf')) { |
64
|
|
|
$add = Config::VAT_ONLY_CPF; |
65
|
|
|
} elseif ($this->config->getConfigByTaxvat('enabled_cnpj')) { |
66
|
|
|
$add = Config::VAT_ONLY_CNPJ; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
$result .= $add; |
|
|
|
|
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
return $result; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.