I created a helper in opencart following information I found here on stackoverflow, but I have a problem:
First I created a helper file called general.php
and placed inside the folder:
system/helper/general.php
Then started in startup.php
file
require_once(DIR_SYSTEM 'helper/general.php');
Finally, I use it inside the controller: register.php
which is inside the folder catalog/controller/account/register.php
.
I used it in this way:
if (empty($this->request->post['doc']) && $this->general->validate($this->request->post['doc'])) {
$this->error['doc'] = 'doc is invalid';
}
And is returning the following error:
Fatal error: Call to a member function validate() on a non-object in / home/centralshopdistribuidora/www/vqmod/vqcache/vq2-catalog_controller_account_register.php on line 515
line 515:
if (empty($this->request->post['doc']) && $this->general->validate($this->request->post['doc'])) {
The general.php file:
function validate($doc) {
$d1 = 0;
$d2 = 0;
$doc = preg_replace("/[^0-9]/", "", $doc);
$ignore_list = array(
'00000000000',
'01234567890',
'11111111111',
'22222222222',
'33333333333',
'44444444444',
'55555555555',
'66666666666',
'77777777777',
'88888888888',
'99999999999'
);
if (strlen($doc) != 11 || in_array($doc, $ignore_list)) {
return false;
} else {
for ($i = 0; $i < 9; $i++) {
$d1 += $doc[$i] * (10 - $i);
}
$r1 = $d1 % 11;
$d1 = ($r1 > 1) ? (11 - $r1) : 0;
for ($i = 0; $i < 9; $i++) {
$d2 += $doc[$i] * (11 - $i);
}
$r2 = ($d2 + ($d1 * 2)) % 11;
$d2 = ($r2 > 1) ? (11 - $r2) : 0;
return (substr($doc, -2) == $d1 . $d2) ? true : false;
}
}