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
*

View File

@@ -23,11 +23,10 @@
<field name="active"/>
</fields>
<entities>
<address id="Mon_adresse" id_country="FR" id_state="" id_customer="John" id_manufacturer="" id_supplier="" id_warehouse="0" alias="Mon adresse" lastname="DOE" firstname="John" postcode="75002" phone="0102030405" phone_mobile="" vat_number="" dni="" active="1">
<company>My Company</company>
<address id="My_address" id_country="FR" id_state="" id_customer="John" id_manufacturer="" id_supplier="" id_warehouse="0" alias="My Address" lastname="Doe" firstname="John" postcode="75002" phone="0102030405" phone_mobile="" vat_number="" dni="" active="1">
<address1>16, Main street</address1>
<address2>2nd floor</address2>
<city>Paris </city>
<city>Demo City</city>
<other/>
</address>
</entities>

View File

@@ -19,7 +19,7 @@
<field name="is_guest"/>
</fields>
<entities>
<customer id="John" id_gender="1" id_default_group="3" firstname="John" lastname="DOE" passwd="b7d897d438f634f23548b32a2d7e8983" last_passwd_gen="2013-12-13 02:19:15" birthday="1970-01-15" newsletter="1" ip_registration_newsletter="" newsletter_date_add="2013-12-13 08:19:15" optin="1" secure_key="b44a6d9efd7a0076a0fbce6b15eaf3b1" active="1" is_guest="0">
<customer id="John" id_gender="1" id_default_group="3" firstname="John" lastname="Doe" passwd="b7d897d438f634f23548b32a2d7e8983" last_passwd_gen="2013-12-13 02:19:15" birthday="1970-01-15" newsletter="1" ip_registration_newsletter="" newsletter_date_add="2013-12-13 08:19:15" optin="1" secure_key="b44a6d9efd7a0076a0fbce6b15eaf3b1" active="1" is_guest="0">
<email>pub@qloapps.com</email>
<note/>
</customer>

View File

@@ -36,8 +36,33 @@ class InstallFixturesFashion extends InstallXmlLoader
{
if ($identifier == 'John') {
$data['passwd'] = Tools::encrypt('123456789');
$data['last_passwd_gen'] = date('Y-m-d H:i:s');
$data['birthday'] = date('Y-m-d', strtotime('-30 years'));
$data['newsletter_date_add'] = date('Y-m-d H:i:s');
}
return $this->createEntity('customer', $identifier, 'Customer', $data, $data_lang);
}
public function createEntityAddress($identifier, array $data, array $data_lang)
{
if ($identifier == 'My_address') {
$idCountry = Configuration::get('PS_COUNTRY_DEFAULT');
$data['id_country'] = $idCountry;
if (Country::containsStates($idCountry)) {
if ($states = State::getStatesByIdCountry($idCountry)) {
$data['id_state'] = $states[0]['id_state'];
} else {
$data['id_state'] = 0;
}
}
if (Country::getNeedZipCode($idCountry)) {
$data['postcode'] = Tools::generateRandomZipcode($idCountry);
}
}
return $this->createEntity('address', $identifier, 'Address', $data, $data_lang);
}
}

View File

@@ -357,7 +357,7 @@ class HotelHelper
$objAddress->city = 'Demo City';
$objAddress->id_state = $state_id;
$objAddress->id_country = $def_cont_id;
$objAddress->postcode = self::getRandomZipcodeByForCountry($def_cont_id);
$objAddress->postcode = Tools::generateRandomZipcode($def_cont_id);
$objAddress->address1 = 'Monticello Dr, Montgomery, AL 36117, USA';
$objAddress->alias = 'The Hotel Prime';
$objAddress->lastname = 'The Hotel Prime';
@@ -713,26 +713,6 @@ class HotelHelper
return true;
}
public static function getRandomZipcodeByForCountry($idCountry)
{
$randZipCode = '';
$alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
if (Validate::isLoadedObject($objCountry = new Country($idCountry))) {
if ($objCountry->need_zip_code) {
if ($randZipCode = $objCountry->zip_code_format) {
$randZipCode = str_replace('N', mt_rand(0, 9), $randZipCode);
$randZipCode = str_replace('L', $alphabet[mt_rand(0, Tools::strlen($alphabet) - 1)], $randZipCode);
$randZipCode = str_replace('C', $objCountry->iso_code, $randZipCode);
} else {
for ($i = 0; $i < 5; ++$i) {
$randZipCode .= mt_rand(0, 9);
}
}
}
}
return $randZipCode;
}
/**
* Get Super Admin Of Prestashop
* @return int Super Admin Employee ID