- 17 Jun 2019, 08:56
#82393
Olá tudo, gostaria de pedir ajuda para o OC Brasil fórum para fazer uma modificação do módulo de Validação de CPF CNPJ https://www.opencart.com/index.php?rout ... %A3o%20cpf disponível gratuitamente no market place. Eu modifiquei o modo como as pessoas fazem cadastro na minha loja. Inicialmente no register, eu solicito apenas email e senha, e depois no checkout, apliquei o campo cpf no payment addres e outras infos como: endereço, nome, sobrenome, etc. Quando tento aplicar o código no módulo Validação de CPF CNPJ do OC BRASIL aparece o seguinte erro:
Parse error: syntax error, unexpected '$ativo_module' (T_VARIABLE), expecting function (T_FUNCTION) in C:\xampp\htdocs\nome-da-loja\catalog\controller\checkout\payment_address.php on line 6
Isso acontece claro pq ele não foi pelo para ser aplicado neste arquivo. Vou mostrar o que fiz:
<file path="catalog/controller/checkout/payment_address.php">
<search trim="true"><![CDATA[class ControllerCheckoutPaymentAddress extends Controller { ]]></search>
<add position="before"><![CDATA[
<file path="catalog/controller/checkout/payment_address.php">
<search trim="true"><![CDATA[foreach ($custom_fields as $custom_field) { ]]></search>
<add position="after"><![CDATA[
Alguém pode me dizer por qual caminho seguir?
Parse error: syntax error, unexpected '$ativo_module' (T_VARIABLE), expecting function (T_FUNCTION) in C:\xampp\htdocs\nome-da-loja\catalog\controller\checkout\payment_address.php on line 6
Isso acontece claro pq ele não foi pelo para ser aplicado neste arquivo. Vou mostrar o que fiz:
<file path="catalog/controller/checkout/payment_address.php">
<search trim="true"><![CDATA[class ControllerCheckoutPaymentAddress extends Controller { ]]></search>
<add position="before"><![CDATA[
Código: Selecionar todos
//validação cpf/cnpj Opencart Master
$ativo_module = $this->config->get('validar_status');
$ativo_cpf = $this->config->get('validar_ativo');
$ativo_cnpj = $this->config->get('validar_ativo1');
$ativo_misto = $this->config->get('validar_ativo2');
$val_cpf = $this->config->get('validar_cpf');
$val_cnpj = $this->config->get('validar_cnpj');
$val_misto = $this->config->get('validar_misto');
if (($ativo_cpf) && (!$ativo_cnpj) && ($ativo_module)){
$cpf = new ValidaCPFCNPJ($this->request->post['custom_field']['address'][$val_cpf]);
if ($cpf->valida()) {
} else {
$json['error']['custom_field' . $val_cpf] = sprintf($this->language->get('error_custom_field'), $custom_field['name']);
}
} elseif (($ativo_cnpj) && (!$ativo_cpf) && ($ativo_module)){
$cnpj = new ValidaCPFCNPJ($this->request->post['custom_field']['address'][$val_cnpj] );
if ($cnpj->valida()) {
} else {
$json['error']['custom_field' . $val_cnpj] =sprintf($this->language->get('error_custom_field'), $custom_field['name']);
}
}elseif (($ativo_misto) && ($ativo_module)){
$misto = new ValidaCPFCNPJ($this->request->post['custom_field']['address'][$val_misto] );
if ($misto->valida()) {
} else {
$json['error']['custom_field' . $val_misto] = sprintf($this->language->get('error_custom_field'), $custom_field['name']);
}
} elseif (($ativo_cnpj) && ($ativo_cpf) && ($ativo_module)){
$cnpj = new ValidaCPFCNPJ($this->request->post['custom_field']['address'][$val_cnpj]);
$cpf = new ValidaCPFCNPJ($this->request->post['custom_field']['address'][$val_cpf]);
if ( $cpf->valida() && !$cnpj->valida() || !$cpf->valida() && $cnpj->valida()) {
}
else {
$json['error']['custom_field' . $val_cnpj] =sprintf($this->language->get('error_custom_field'), $custom_field['name']);
$json['error']['custom_field' . $val_cpf] =sprintf($this->language->get('error_custom_field'), $custom_field['name']);
}
}
//validação cpf/cnpj Opencart Master
/*validação cpf*/
<file path="catalog/controller/checkout/payment_address.php">
<search trim="true"><![CDATA[foreach ($custom_fields as $custom_field) { ]]></search>
<add position="after"><![CDATA[
Código: Selecionar todos
Me baseei no modo de inclusão para o arquivo <file path="catalog/controller/checkout/register.php">//validação Opencart Master
$ativo_module = $this->config->get('validar_status');
$ativo_cpf = $this->config->get('validar_ativo');
$ativo_cnpj = $this->config->get('validar_ativo1');
$ativo_misto = $this->config->get('validar_ativo2');
$val_cpf = $this->config->get('validar_cpf');
$val_cnpj = $this->config->get('validar_cnpj');
$val_misto = $this->config->get('validar_misto');
if (($ativo_cpf) && (!$ativo_cnpj) && ($ativo_module)){
$cpf = new ValidaCPFCNPJ($this->request->post['custom_field']['account'][$val_cpf]);
if ($cpf->valida()) {
} else {
$json['error']['custom_field' . $val_cpf] = sprintf($this->language->get('error_custom_field'), $custom_field['name']);
}
} elseif (($ativo_cnpj) && (!$ativo_cpf) && ($ativo_module)){
$cnpj = new ValidaCPFCNPJ($this->request->post['custom_field']['account'][$val_cnpj] );
if ($cnpj->valida()) {
} else {
$json['error']['custom_field' . $val_cnpj] =sprintf($this->language->get('error_custom_field'), $custom_field['name']);
}
}elseif (($ativo_misto) && ($ativo_module)){
$misto = new ValidaCPFCNPJ($this->request->post['custom_field']['account'][$val_misto] );
if ($misto->valida()) {
} else {
$json['error']['custom_field' . $val_misto] = sprintf($this->language->get('error_custom_field'), $custom_field['name']);
}
} elseif (($ativo_cnpj) && ($ativo_cpf) && ($ativo_module)){
$cnpj = new ValidaCPFCNPJ($this->request->post['custom_field']['account'][$val_cnpj]);
$cpf = new ValidaCPFCNPJ($this->request->post['custom_field']['account'][$val_cpf]);
if ( $cpf->valida() && !$cnpj->valida() || !$cpf->valida() && $cnpj->valida()) {
}
else {
$json['error']['custom_field' . $val_cnpj] =sprintf($this->language->get('error_custom_field'), $custom_field['name']);
$json['error']['custom_field' . $val_cpf] =sprintf($this->language->get('error_custom_field'), $custom_field['name']);
}
}
/*validação cpf*/
if (($custom_field['location'] == 'address') && $custom_field['required'] && empty($this->request->post['custom_field'][$custom_field['custom_field_id']])) {
$json['error']['custom_field' . $custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']);
} elseif (($custom_field['location'] == 'address') && ($custom_field['type'] == 'text') && !empty($custom_field['validation']) && !filter_var($this->request->post['custom_field'][$custom_field['custom_field_id']], FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => '/' . html_entity_decode($custom_field['validation'], ENT_QUOTES, 'UTF-8') . '/')))) {
$json['error']['custom_field' . $custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']);
}
}
/*validação cpf*/
Alguém pode me dizer por qual caminho seguir?