diff --git a/classes/Tools.php b/classes/Tools.php
index fb0fe493a..50b9cdf23 100644
--- a/classes/Tools.php
+++ b/classes/Tools.php
@@ -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
*
diff --git a/install/fixtures/fashion/data/address.xml b/install/fixtures/fashion/data/address.xml
index d4cee69e2..4ea2f1a8d 100644
--- a/install/fixtures/fashion/data/address.xml
+++ b/install/fixtures/fashion/data/address.xml
@@ -23,11 +23,10 @@
-
- My Company
+
16, Main street
2nd floor
- Paris
+ Demo City
diff --git a/install/fixtures/fashion/data/customer.xml b/install/fixtures/fashion/data/customer.xml
index 7f983693a..f067091b4 100644
--- a/install/fixtures/fashion/data/customer.xml
+++ b/install/fixtures/fashion/data/customer.xml
@@ -19,7 +19,7 @@
-
+
pub@qloapps.com
diff --git a/install/fixtures/fashion/install.php b/install/fixtures/fashion/install.php
index acf572770..f7ef6fcca 100644
--- a/install/fixtures/fashion/install.php
+++ b/install/fixtures/fashion/install.php
@@ -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);
+ }
}
diff --git a/modules/hotelreservationsystem/classes/HotelHelper.php b/modules/hotelreservationsystem/classes/HotelHelper.php
index 998cf362e..2ddd664a8 100644
--- a/modules/hotelreservationsystem/classes/HotelHelper.php
+++ b/modules/hotelreservationsystem/classes/HotelHelper.php
@@ -360,7 +360,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';
@@ -884,22 +884,7 @@ class HotelHelper
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;
+ return Tools::generateRandomZipcode($idCountry);
}
/**