Use website country as demo customer address country

This commit is contained in:
Abhishek Kumar
2023-12-05 13:29:32 +05:30
parent ce93a9826f
commit 3b06a668fb
5 changed files with 62 additions and 25 deletions

View File

@@ -80,6 +80,39 @@ class ToolsCore
return $result;
}
public static function generateRandomZipcode($idCountry)
{
$randomZipCode = '';
$alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$alphabetLength = Tools::strlen($alphabet);
if (Validate::isLoadedObject($objCountry = new Country($idCountry))
&& $objCountry->need_zip_code
) {
if ($zipCodeFormat = $objCountry->zip_code_format) {
for ($i = 0; $i < Tools::strlen($zipCodeFormat); $i++) {
$formatCharacter = $zipCodeFormat[$i];
if (in_array($formatCharacter, array('N', 'L', 'C'))) {
if ($formatCharacter == 'N') {
$randomZipCode .= mt_rand(0, 9);
} elseif ($formatCharacter == 'L') {
$randomZipCode .= $alphabet[mt_rand(0, $alphabetLength - 1)];
} elseif ($formatCharacter == 'C') {
$randomZipCode .= $objCountry->iso_code;
}
} else {
$randomZipCode .= $formatCharacter;
}
}
} else {
for ($i = 1; $i <= 5; $i++) {
$randomZipCode .= mt_rand(0, 9);
}
}
}
return $randomZipCode;
}
/**
* Random bytes generator
*