diff --git a/admin-dev/tabs/AdminCustomers.php b/admin-dev/tabs/AdminCustomers.php
index f4b97c9e8..103ae2813 100644
--- a/admin-dev/tabs/AdminCustomers.php
+++ b/admin-dev/tabs/AdminCustomers.php
@@ -50,8 +50,8 @@ class AdminCustomers extends AdminTab
$genders = array(0 => $this->l('?'));
foreach (Gender::getGenders() as $gender)
{
- $genders_icon[$gender['id_gender']] = '../genders/'.$gender['id_gender'].'.jpg';
- $genders[$gender['id_gender']] = $gender['name'];
+ $genders_icon[$gender->id] = '../genders/'.$gender->id.'.jpg';
+ $genders[$gender->id] = $gender->name;
}
$this->fieldsDisplay = array(
@@ -723,8 +723,8 @@ class AdminCustomers extends AdminTab
';
foreach (Gender::getGenders() as $gender)
{
- echo '
getFieldValue($obj, 'id_gender') == $gender['id_gender'] ? 'checked="checked" ' : '').'/>';
- echo '
';
+ echo '
getFieldValue($obj, 'id_gender') == $gender->id ? 'checked="checked" ' : '').'/>';
+ echo '
';
}
echo '
getFieldValue($obj, 'id_gender') == 9 || !$this->getFieldValue($obj, 'id_gender')) ? 'checked="checked" ' : '').'/>
diff --git a/cache/class_index.php b/cache/class_index.php
index e2c72f61c..dbecb372d 100644
--- a/cache/class_index.php
+++ b/cache/class_index.php
@@ -6,7 +6,7 @@
'AddressFormatCore' => 'classes/AddressFormat.php',
'AddressFormat' => 'override/classes/AddressFormat.php',
'AdminControllerCore' => 'classes/AdminController.php',
- 'AdminController' => '',
+ 'AdminController' => 'override/classes/AdminController.php',
'AdminTabCore' => 'classes/AdminTab.php',
'AdminTab' => 'override/classes/AdminTab.php',
'AliasCore' => 'classes/Alias.php',
@@ -108,6 +108,7 @@
'HelpAccess' => 'override/classes/HelpAccess.php',
'HelperCore' => 'classes/Helper.php',
'Helper' => 'override/classes/Helper.php',
+ 'HelperList' => 'classes/HelperList.php',
'HookCore' => 'classes/Hook.php',
'Hook' => 'override/classes/Hook.php',
'ImageCore' => 'classes/Image.php',
@@ -192,7 +193,8 @@
'RangeWeight' => 'override/classes/RangeWeight.php',
'ReferrerCore' => 'classes/Referrer.php',
'Referrer' => 'override/classes/Referrer.php',
- 'RequestSql' => 'classes/RequestSql.php',
+ 'RequestSqlCore' => 'classes/RequestSql.php',
+ 'RequestSql' => 'override/classes/RequestSql.php',
'RijndaelCore' => 'classes/Rijndael.php',
'Rijndael' => 'override/classes/Rijndael.php',
'SceneCore' => 'classes/Scene.php',
@@ -289,10 +291,12 @@
'WebserviceSpecificManagementSearchCore' => 'classes/webservice/WebserviceSpecificManagementSearch.php',
'WebserviceSpecificManagementSearch' => 'override/classes/webservice/WebserviceSpecificManagementSearch.php',
'FB' => 'override/classes/fb.php',
+ 'AdminAddressesControllerCore' => 'controllers/admin/AdminAddressesController.php',
+ 'AdminAddressesController' => '',
'AdminHomeControllerCore' => 'controllers/admin/AdminHomeController.php',
- 'AdminHomeController' => '',
+ 'AdminHomeController' => 'override/controllers/admin/AdminHomeController.php',
'AdminToolsControllerCore' => 'controllers/admin/AdminToolsController.php',
- 'AdminToolsController' => '',
+ 'AdminToolsController' => 'override/controllers/admin/AdminToolsController.php',
'AddressControllerCore' => 'controllers/front/AddressController.php',
'AddressController' => 'override/controllers/front/AddressController.php',
'AddressesControllerCore' => 'controllers/front/AddressesController.php',
@@ -358,9 +362,9 @@
'PdfInvoiceControllerCore' => 'controllers/front/PdfInvoiceController.php',
'PdfInvoiceController' => 'override/controllers/front/PdfInvoiceController.php',
'PdfOrderReturnControllerCore' => 'controllers/front/PdfOrderReturnController.php',
- 'PdfOrderReturnController' => 'override/controllers/front/pdfOrderReturnController.php',
+ 'PdfOrderReturnController' => 'override/controllers/front/PdfOrderReturnController.php',
'PdfOrderSlipControllerCore' => 'controllers/front/PdfOrderSlipController.php',
- 'PdfOrderSlipController' => 'override/controllers/front/pdfOrderSlipController.php',
+ 'PdfOrderSlipController' => 'override/controllers/front/PdfOrderSlipController.php',
'PricesDropControllerCore' => 'controllers/front/PricesDropController.php',
'PricesDropController' => 'override/controllers/front/PricesDropController.php',
'ProductControllerCore' => 'controllers/front/ProductController.php',
diff --git a/classes/Gender.php b/classes/Gender.php
index 06fff9f16..14e3413d9 100644
--- a/classes/Gender.php
+++ b/classes/Gender.php
@@ -77,10 +77,12 @@ class GenderCore extends ObjectModel
if (is_null($id_lang))
$id_lang = Context::getContext()->language->id;
- $sql = 'SELECT g.id_gender, gl.name
+ $sql = 'SELECT g.*, gl.*
FROM '._DB_PREFIX_.'gender g
LEFT JOIN '._DB_PREFIX_.'gender_lang gl ON g.id_gender = gl.id_gender AND gl.id_lang = '.(int)$id_lang;
- return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql);
+ $results = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql);
+
+ return ObjectModel::hydrateCollection('Gender', $results, $id_lang);
}
public static function getStaticImage($id, $useUnknown = false)
diff --git a/classes/ObjectModel.php b/classes/ObjectModel.php
index 006adad1e..f064e7486 100644
--- a/classes/ObjectModel.php
+++ b/classes/ObjectModel.php
@@ -31,23 +31,23 @@ abstract class ObjectModelCore
public $id;
/** @var integer lang id */
- protected $id_lang = NULL;
+ protected $id_lang = null;
- protected $id_shop = NULL;
+ protected $id_shop = null;
private $getShopFromContext = true;
/** @var string SQL Table name */
- protected $table = NULL;
+ protected $table = null;
/** @var string SQL Table identifier */
- protected $identifier = NULL;
+ protected $identifier = null;
/** @var array Required fields for admin panel forms */
protected $fieldsRequired = array();
/** @var fieldsRequiredDatabase */
- protected static $fieldsRequiredDatabase = NULL;
+ protected static $fieldsRequiredDatabase = null;
/** @var array Maximum fields size for admin panel forms */
protected $fieldsSize = array();
@@ -75,7 +75,7 @@ abstract class ObjectModelCore
protected static $_cache = array();
/** @var string path to image directory. Used for image deletion. */
- protected $image_dir = NULL;
+ protected $image_dir = null;
/** @var string file type of image files. Used for image deletion. */
protected $image_format = 'jpg';
@@ -922,4 +922,110 @@ abstract class ObjectModelCore
$query->where('`active` = 1');
return (bool)Db::getInstance()->getValue($query);
}
+
+ /**
+ * Get object identifier name
+ *
+ * @since 1.5.0
+ * @return string
+ */
+ public function getIdentifier()
+ {
+ return $this->identifier;
+ }
+
+ /**
+ * Get list of fields related to language to validate
+ *
+ * @since 1.5.0
+ * @return array
+ */
+ public function getFieldsValidateLang()
+ {
+ return $this->fieldsValidateLang;
+ }
+
+ /**
+ * Fill an object with given data. Data must be an array with this syntax: array(objProperty => value, objProperty2 => value, etc.)
+ *
+ * @since 1.5.0
+ * @param array $data
+ * @param int $id_lang
+ */
+ public function hydrate(array $data, $id_lang = null)
+ {
+ $identifier = $this->getIdentifier();
+ if (!array_key_exists($identifier, $data))
+ throw new PrestashopException("Identifier '$identifier' not found for class '".get_class($this)."'");
+
+ $this->id_lang = null;
+ $this->id = $data[$identifier];
+ foreach ($data as $key => $value)
+ if (array_key_exists($key, $this))
+ $this->$key = $value;
+ }
+
+ /**
+ * Fill (hydrate) a list of objects in order to get a collection of these objects
+ *
+ * @since 1.5.0
+ * @param string $class Class of objects to hydrate
+ * @param array $datas List of data (multi-dimensional array)
+ * @param int $id_lang
+ * @return array
+ */
+ public static function hydrateCollection($class, array $datas, $id_lang = null)
+ {
+ if (!class_exists($class))
+ throw new PrestashopException("Class '$class' not found");
+
+ $collection = array();
+ $group_keys = array();
+ $rows = array();
+ $identifier = $fieldsValidateLang = null;
+ foreach ($datas as $row)
+ {
+ // Get class identifier and fieldsValidateLang only the first time
+ if (is_null($identifier))
+ {
+ $obj = new $class;
+ if (!$obj instanceof ObjectModel)
+ throw new PrestashopException("Class '$class' must be an instance of class ObjectModel");
+ $identifier = $obj->getIdentifier();
+ $fieldsValidateLang = $obj->getFieldsValidateLang();
+ }
+
+ // Get primary key
+ if (!array_key_exists($identifier, $row))
+ throw new PrestashopException("Identifier '$identifier' not found for class '$class'");
+ $id = $row[$identifier];
+
+ // Get object common properties
+ if (!isset($rows[$id]))
+ $rows[$id] = $row;
+
+ // Get object lang properties
+ if (isset($row['id_lang']) && !$id_lang)
+ {
+ foreach ($fieldsValidateLang as $field => $validator)
+ {
+ if (!$id_lang)
+ {
+ if (!is_array($rows[$id][$field]))
+ $rows[$id][$field] = array();
+ $rows[$id][$field][$row['id_lang']] = $row[$field];
+ }
+ }
+ }
+ }
+
+ // Hydrate objects
+ foreach ($rows as $row)
+ {
+ $obj = new $class;
+ $obj->hydrate($row, $id_lang);
+ $collection[] = $obj;
+ }
+ return $collection;
+ }
}
diff --git a/controllers/front/AddressController.php b/controllers/front/AddressController.php
index bba973786..5411a9887 100644
--- a/controllers/front/AddressController.php
+++ b/controllers/front/AddressController.php
@@ -107,15 +107,6 @@ class AddressControllerCore extends FrontController
$_POST['firstname'] = $this->context->customer->firstname;
$_POST['lastname'] = $this->context->customer->lastname;
}
-
- if ($this->ajax && count($this->errors))
- {
- $return = array(
- 'hasError' => !empty($this->errors),
- 'errors' => $this->errors
- );
- die(Tools::jsonEncode($return));
- }
}
/**
@@ -365,5 +356,16 @@ class AddressControllerCore extends FrontController
'vat_display' => $vat_display,
));
}
-}
+ public function displayAjax()
+ {
+ if (count($this->errors))
+ {
+ $return = array(
+ 'hasError' => !empty($this->errors),
+ 'errors' => $this->errors
+ );
+ die(Tools::jsonEncode($return));
+ }
+ }
+}
diff --git a/controllers/front/AddressesController.php b/controllers/front/AddressesController.php
index eb5cbf50a..52f711c46 100644
--- a/controllers/front/AddressesController.php
+++ b/controllers/front/AddressesController.php
@@ -48,6 +48,8 @@ class AddressesControllerCore extends FrontController
*/
public function init()
{
+ parent::init();
+
if (!Validate::isLoadedObject($this->context->customer))
die(Tools::displayError('Customer not found'));
}
diff --git a/index.php b/index.php
index cc5ce8475..61e8a05bb 100644
--- a/index.php
+++ b/index.php
@@ -26,4 +26,4 @@
*/
require(dirname(__FILE__).'/config/config.inc.php');
-Dispatcher::getInstance()->dispatch();
+Dispatcher::getInstance()->dispatch();
\ No newline at end of file
diff --git a/modules/blockpaymentlogo/blockpaymentlogo.php b/modules/blockpaymentlogo/blockpaymentlogo.php
index 3b1105795..21c411849 100644
--- a/modules/blockpaymentlogo/blockpaymentlogo.php
+++ b/modules/blockpaymentlogo/blockpaymentlogo.php
@@ -1,6 +1,6 @@
need_instance = 0;
parent::__construct();
-
+
$this->displayName = $this->l('Block payment logo');
$this->description = $this->l('Adds a block to display all payment logos.');
}
@@ -55,7 +55,7 @@ class BlockPaymentLogo extends Module
return false;
return true;
}
-
+
public function uninstall()
{
Configuration::deleteByName('PS_PAYMENT_LOGO_CMS_ID');
@@ -67,16 +67,16 @@ class BlockPaymentLogo extends Module
$html = '
'.$this->l('Payment logo').'
';
-
+
if (Tools::isSubmit('submitConfiguration'))
if (Validate::isUnsignedInt(Tools::getValue('id_cms')))
{
Configuration::updateValue('PS_PAYMENT_LOGO_CMS_ID', (int)(Tools::getValue('id_cms')));
$html .= $this->displayConfirmation($this->l('Settings are updated'));
}
-
+
$cmss = CMS::listCms($this->context->language->id);
-
+
if (!sizeof($cmss))
$html .= $this->displayError($this->l('No CMS page is available'));
else
@@ -110,8 +110,8 @@ class BlockPaymentLogo extends Module
{
if (Configuration::get('PS_CATALOG_MODE'))
return ;
-
-
+
+
if (!Configuration::get('PS_PAYMENT_LOGO_CMS_ID'))
return;
$cms = new CMS(Configuration::get('PS_PAYMENT_LOGO_CMS_ID'), $this->context->language->id);
@@ -120,7 +120,7 @@ class BlockPaymentLogo extends Module
$this->context->smarty->assign('cms_payement_logo', $cms);
return $this->display(__FILE__, 'blockpaymentlogo.tpl');
}
-
+
public function hookRightColumn($params)
{
return $this->hookLeftColumn($params);
diff --git a/modules/paypal/express/authentication.tpl b/modules/paypal/express/authentication.tpl
index d194f9afc..a064edf42 100644
--- a/modules/paypal/express/authentication.tpl
+++ b/modules/paypal/express/authentication.tpl
@@ -52,8 +52,8 @@ countries = new Array();
{l s='Title'}
{foreach from=$genders key=k item=gender}
-
-
+ id}checked="checked"{/if} />
+
{/foreach}
diff --git a/themes/prestashop/authentication.tpl b/themes/prestashop/authentication.tpl
index 671215e45..21e3c0990 100644
--- a/themes/prestashop/authentication.tpl
+++ b/themes/prestashop/authentication.tpl
@@ -147,8 +147,8 @@ $(function(){ldelim}
{l s='Title'}
{foreach from=$genders key=k item=gender}
-
-
+ id}checked="checked"{/if} />
+
{/foreach}
diff --git a/themes/prestashop/identity.tpl b/themes/prestashop/identity.tpl
index f95bdcf2b..23a180fcf 100644
--- a/themes/prestashop/identity.tpl
+++ b/themes/prestashop/identity.tpl
@@ -44,8 +44,8 @@
{l s='Title'}
{foreach from=$genders key=k item=gender}
-
-
+ id}checked="checked"{/if} />
+
{/foreach}