From 18edd9bf75698c4eae0f5a4107e7e9f75c146c01 Mon Sep 17 00:00:00 2001 From: PrestaEdit Date: Fri, 29 Mar 2013 10:40:07 +0100 Subject: [PATCH 01/57] [*] Class: Tools::fileAttachment() --- classes/Tools.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/classes/Tools.php b/classes/Tools.php index c6022516b..5dc9fa518 100644 --- a/classes/Tools.php +++ b/classes/Tools.php @@ -2259,6 +2259,21 @@ FileETag INode MTime Size return $pattern; return preg_replace('/\\\[px]\{[a-z]\}{1,2}|(\/[a-z]*)u([a-z]*)$/i', "$1$2", $pattern); } + + public static function fileAttachment($input = 'fileUpload') + { + $fileAttachment = null; + if (isset($_FILES[$input]['name']) && !empty($_FILES[$input]['name']) && !empty($_FILES[$input]['tmp_name'])) + { + $filename = uniqid().substr($_FILES[$input]['name'], -5); + $fileAttachment['content'] = file_get_contents($_FILES[$input]['tmp_name']); + $fileAttachment['name'] = $_FILES[$input]['name']; + $fileAttachment['mime'] = $_FILES[$input]['type']; + $fileAttachment['error'] = $_FILES[$input]['error']; + } + + return $fileAttachment; + } } /** From b6fbbe6187f58f373a07c03dabf43967270fcb11 Mon Sep 17 00:00:00 2001 From: PrestaEdit Date: Tue, 30 Apr 2013 20:46:34 +0200 Subject: [PATCH 02/57] [*] FO: use Tools::fileAttachment() in ContactController --- controllers/front/ContactController.php | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/controllers/front/ContactController.php b/controllers/front/ContactController.php index dd133b8fc..7a32b96ba 100644 --- a/controllers/front/ContactController.php +++ b/controllers/front/ContactController.php @@ -38,15 +38,10 @@ class ContactControllerCore extends FrontController { if (Tools::isSubmit('submitMessage')) { - $fileAttachment = null; - if (isset($_FILES['fileUpload']['name']) && !empty($_FILES['fileUpload']['name']) && !empty($_FILES['fileUpload']['tmp_name'])) - { - $extension = array('.txt', '.rtf', '.doc', '.docx', '.pdf', '.zip', '.png', '.jpeg', '.gif', '.jpg'); - $filename = uniqid().substr($_FILES['fileUpload']['name'], -5); - $fileAttachment['content'] = file_get_contents($_FILES['fileUpload']['tmp_name']); - $fileAttachment['name'] = $_FILES['fileUpload']['name']; - $fileAttachment['mime'] = $_FILES['fileUpload']['type']; - } + $extension = array('.txt', '.rtf', '.doc', '.docx', '.pdf', '.zip', '.png', '.jpeg', '.gif', '.jpg'); + + $fileAttachment = Tools::fileAttachment('fileUpload'); + $message = Tools::getValue('message'); // Html entities is not usefull, iscleanHtml check there is no bad html tags. if (!($from = trim(Tools::getValue('from'))) || !Validate::isEmail($from)) $this->errors[] = Tools::displayError('Invalid e-mail address'); @@ -56,9 +51,9 @@ class ContactControllerCore extends FrontController $this->errors[] = Tools::displayError('Invalid message'); else if (!($id_contact = (int)(Tools::getValue('id_contact'))) || !(Validate::isLoadedObject($contact = new Contact($id_contact, $this->context->language->id)))) $this->errors[] = Tools::displayError('Please select a subject from the list.'); - else if (!empty($_FILES['fileUpload']['name']) && $_FILES['fileUpload']['error'] != 0) + else if (!empty($fileAttachment['name']) && $fileAttachment['error'] != 0) $this->errors[] = Tools::displayError('An error occurred during the file upload'); - else if (!empty($_FILES['fileUpload']['name']) && !in_array(substr($_FILES['fileUpload']['name'], -4), $extension) && !in_array(substr($_FILES['fileUpload']['name'], -5), $extension)) + else if (!empty($fileAttachment['name']) && !in_array(substr($fileAttachment['name'], -4), $extension) && !in_array(substr($fileAttachment['name'], -5), $extension)) $this->errors[] = Tools::displayError('Bad file extension'); else { @@ -125,7 +120,7 @@ class ContactControllerCore extends FrontController '{message}' => Tools::nl2br(stripslashes($message)), '{id_order}' => $id_order, '{order_name}' => $order->getUniqReference(), - '{attached_file}' => isset($_FILES['fileUpload'], $_FILES['fileUpload']['name']) ? $_FILES['fileUpload']['name'] : '' + '{attached_file}' => isset($fileAttachment, $fileAttachment['name']) ? $fileAttachment['name'] : '' ); if (Mail::Send($this->context->language->id, 'contact', Mail::l('Message from contact form'), @@ -174,7 +169,7 @@ class ContactControllerCore extends FrontController $cm = new CustomerMessage(); $cm->id_customer_thread = $ct->id; $cm->message = Tools::htmlentitiesUTF8($message); - if (isset($filename) && rename($_FILES['fileUpload']['tmp_name'], _PS_MODULE_DIR_.'../upload/'.$filename)) + if (isset($filename) && rename($fileAttachment['tmp_name'], _PS_MODULE_DIR_.'../upload/'.$filename)) $cm->file_name = $filename; $cm->ip_address = ip2long($_SERVER['REMOTE_ADDR']); $cm->user_agent = $_SERVER['HTTP_USER_AGENT']; @@ -193,7 +188,7 @@ class ContactControllerCore extends FrontController $var_list['{order_name}'] = $order->reference; } if (isset($filename)) - $var_list['{attached_file}'] = $_FILES['fileUpload']['name']; + $var_list['{attached_file}'] = $fileAttachment['name']; Mail::Send($this->context->language->id, 'contact_form', Mail::l('Your message has been correctly sent'), $var_list, $from); } $this->context->smarty->assign('confirmation', 1); From 6ae0dbb4cafdfb5ec9f3a05f0726e065e127dd9f Mon Sep 17 00:00:00 2001 From: PrestaEdit Date: Sat, 1 Jun 2013 00:21:28 +0200 Subject: [PATCH 03/57] [*] BO: use Translate::getAdminTranslation instead of translate() --- admin-dev/footer.inc.php | 8 +-- admin-dev/functions.php | 27 +++----- admin-dev/header.inc.php | 62 +++++++++---------- admin-dev/password.php | 1 + .../admin/AdminTranslationsController.php | 2 +- 5 files changed, 45 insertions(+), 55 deletions(-) diff --git a/admin-dev/footer.inc.php b/admin-dev/footer.inc.php index e41c93db3..e375ecb2f 100644 --- a/admin-dev/footer.inc.php +++ b/admin-dev/footer.inc.php @@ -30,14 +30,14 @@ echo ' diff --git a/admin-dev/functions.php b/admin-dev/functions.php index a79749b62..dd5dea623 100644 --- a/admin-dev/functions.php +++ b/admin-dev/functions.php @@ -223,17 +223,6 @@ function checkPSVersion() return $upgrader->checkPSVersion(); } -function translate($string) -{ - global $_LANGADM; - if (!is_array($_LANGADM)) - return str_replace('"', '"', $string); - $key = md5(str_replace('\'', '\\\'', $string)); - $str = (key_exists('index'.$key, $_LANGADM)) ? $_LANGADM['index'.$key] : ((key_exists('index'.$key, $_LANGADM)) ? $_LANGADM['index'.$key] : $string); - return str_replace('"', '"', stripslashes($str)); -} - - /** * Returns a new Tab object * @@ -461,7 +450,7 @@ function runAdminTab($tab, $ajaxMode = false) echo ''; if (!$ajaxMode && Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_ALL && Context::getContext()->controller->multishop_context != Shop::CONTEXT_ALL) @@ -470,10 +459,10 @@ function runAdminTab($tab, $ajaxMode = false) if (Shop::getContext() == Shop::CONTEXT_GROUP) { $shop_group = new ShopGroup((int)Shop::getContextShopGroupID()); - printf(translate('You are configuring your store for group shop %s'), ''.$shop_group->name.''); + printf(Translate::getAdminTranslation('You are configuring your store for group shop %s'), ''.$shop_group->name.''); } elseif (Shop::getContext() == Shop::CONTEXT_SHOP) - printf(translate('You are configuring your store for shop %s'), ''.Context::getContext()->shop->name.''); + printf(Translate::getAdminTranslation('You are configuring your store for shop %s'), ''.Context::getContext()->shop->name.''); echo ''; } if (Validate::isLoadedObject($adminObj)) @@ -546,8 +535,8 @@ function runAdminTab($tab, $ajaxMode = false) // we can display the correct url - // die(Tools::jsonEncode(array(translate('Invalid security token'),$url))); - die(Tools::jsonEncode(translate('Invalid security token'))); + // die(Tools::jsonEncode(array(Translate::getAdminTranslation('Invalid security token'),$url))); + die(Tools::jsonEncode(Translate::getAdminTranslation('Invalid security token'))); } else { @@ -559,17 +548,17 @@ function runAdminTab($tab, $ajaxMode = false) if (false === strpos($url, '?token=') AND false === strpos($url, '&token=')) $url .= '&token='.$adminObj->token; - $message = translate('Invalid security token'); + $message = Translate::getAdminTranslation('Invalid security token'); echo ''.$message.'
'.$message.'
'; echo ' - + - + '; die; diff --git a/admin-dev/header.inc.php b/admin-dev/header.inc.php index 0f92567d4..44d2ca1f8 100644 --- a/admin-dev/header.inc.php +++ b/admin-dev/header.inc.php @@ -41,7 +41,7 @@ echo ' - PrestaShop™ - '.translate('Administration panel').' + PrestaShop™ - '.Translate::getAdminTranslation('Administration panel').' {elseif !isset($customerThread.id_order) && !isset($isLogged)} - + {elseif $customerThread.id_order|intval > 0} {/if} From 78ddec3ac724d78907a20ba74cccb526721f664b Mon Sep 17 00:00:00 2001 From: Damien Metzger Date: Thu, 18 Jul 2013 18:51:23 +0200 Subject: [PATCH 43/57] [-] BO : translation copy is now easier #PSCFV-8886 --- classes/Language.php | 4 ++-- controllers/admin/AdminTranslationsController.php | 14 ++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/classes/Language.php b/classes/Language.php index 5b4659f70..0228a63ac 100644 --- a/classes/Language.php +++ b/classes/Language.php @@ -262,7 +262,7 @@ class LanguageCore extends ObjectModel $mPath_to = _PS_MAIL_DIR_.(string)$iso_to.'/'; } - $lFiles = array('admin.php', 'errors.php', 'fields.php', 'pdf.php', 'tabs.php', 'index.php'); + $lFiles = array('admin.php', 'errors.php', 'fields.php', 'pdf.php', 'tabs.php'); // Added natives mails files $mFiles = array( @@ -297,7 +297,7 @@ class LanguageCore extends ObjectModel 'test.html', 'test.txt', 'voucher.html', 'voucher.txt', 'voucher_new.html', 'voucher_new.txt', - 'order_changed.html', 'order_changed.txt', 'index.php' + 'order_changed.html', 'order_changed.txt' ); $number = -1; diff --git a/controllers/admin/AdminTranslationsController.php b/controllers/admin/AdminTranslationsController.php index 2d34a74d1..784f15c59 100644 --- a/controllers/admin/AdminTranslationsController.php +++ b/controllers/admin/AdminTranslationsController.php @@ -353,13 +353,15 @@ class AdminTranslationsControllerCore extends AdminController $items = Language::getFilesList($from_lang, $from_theme, $to_lang, $to_theme, false, false, true); foreach ($items as $source => $dest) { - $bool &= $this->checkDirAndCreate($dest); - $bool &= @copy($source, $dest); - - if (strpos($dest, 'modules') && basename($source) === $from_lang.'.php' && $bool !== false) - $bool &= $this->changeModulesKeyTranslation($dest, $from_theme, $to_theme); + if (!$this->checkDirAndCreate($dest)) + $this->errors[] = sprintf($this->l('Impossible to create the directory "%s".'), $dest); + elseif (!copy($source, $dest)) + $this->errors[] = sprintf($this->l('Impossible to copy "%s" to "%s".'), $source, $dest); + elseif (strpos($dest, 'modules') && basename($source) === $from_lang.'.php' && $bool !== false) + if (!$this->changeModulesKeyTranslation($dest, $from_theme, $to_theme)) + $this->errors[] = sprintf($this->l('Impossible to translate "$dest".'), $dest); } - if ($bool) + if (!count($this->errors)) $this->redirect(false, 14); $this->errors[] = $this->l('A part of the data has been copied but some of the language files could not be found.'); } From 219ec6e8bef8b2166541a619afe3f4443e75b757 Mon Sep 17 00:00:00 2001 From: Damien Metzger Date: Fri, 19 Jul 2013 09:50:30 +0200 Subject: [PATCH 44/57] [-] FO : Removed useless live edit query #PSCFV-9845 --- classes/controller/FrontController.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/classes/controller/FrontController.php b/classes/controller/FrontController.php index 798446e34..88ebd4b4f 100755 --- a/classes/controller/FrontController.php +++ b/classes/controller/FrontController.php @@ -775,9 +775,11 @@ class FrontControllerCore extends Controller public function checkLiveEditAccess() { - $live_token = Tools::getAdminToken('AdminModulesPositions'.(int)Tab::getIdFromClassName('AdminModulesPositions').(int)Tools::getValue('id_employee')); - $ad = Tools::getValue('ad'); - return Tools::isSubmit('live_edit') && $ad && Tools::getValue('liveToken') == $live_token && is_dir(_PS_ROOT_DIR_.DIRECTORY_SEPARATOR.$ad); + if (!Tools::isSubmit('live_edit') || !Tools::getValue('ad') || !Tools::getValue('liveToken')) + return false; + if (Tools::getValue('liveToken') != Tools::getAdminToken('AdminModulesPositions'.(int)Tab::getIdFromClassName('AdminModulesPositions').(int)Tools::getValue('id_employee'))) + return false; + return is_dir(_PS_ROOT_DIR_.DIRECTORY_SEPARATOR.Tools::getValue('ad')); } public function getLiveEditFooter() From bd4ece095b002ba3cced051a92a3aed5145cb1a4 Mon Sep 17 00:00:00 2001 From: Damien Metzger Date: Fri, 19 Jul 2013 10:58:51 +0200 Subject: [PATCH 45/57] [*] FO : lots of performance improvements (removed or merged useless SQL queries) --- classes/Group.php | 7 +++++ classes/Hook.php | 25 ++++++++++------ classes/ObjectModel.php | 27 ++++++++++------- classes/module/Module.php | 63 +++++++++++++++++++++------------------ 4 files changed, 74 insertions(+), 48 deletions(-) diff --git a/classes/Group.php b/classes/Group.php index aa7f6cccd..eb8b95e3d 100644 --- a/classes/Group.php +++ b/classes/Group.php @@ -70,6 +70,13 @@ class GroupCore extends ObjectModel protected $webserviceParameters = array(); + public function __construct($id = null, $id_lang = null, $id_shop = null) + { + parent::__construct($id, $id_lang, $id_shop); + if ($this->id && !isset(Group::$group_price_display_method[$this->id])) + self::$group_price_display_method[$this->id] = $this->price_display_method; + } + public static function getGroups($id_lang, $id_shop = false) { $shop_criteria = ''; diff --git a/classes/Hook.php b/classes/Hook.php index 420d5b798..407a8a83c 100644 --- a/classes/Hook.php +++ b/classes/Hook.php @@ -113,19 +113,26 @@ class HookCore extends ObjectModel if (!Validate::isHookName($hook_name)) return false; - $cache_id = 'hook_idbyname_'.$hook_name; + $cache_id = 'hook_idsbyname'; if (!Cache::isStored($cache_id)) { - $retro_hook_name = Hook::getRetroHookName($hook_name); - Cache::store($cache_id, Db::getInstance()->getValue(' - SELECT `id_hook` - FROM `'._DB_PREFIX_.'hook` - WHERE `name` = \''.pSQL($hook_name).'\' - OR `name` = \''.pSQL($retro_hook_name).'\' - ')); + // Get all hook ID by name and alias + $hook_ids = array(); + $result = Db::getInstance()->ExecuteS(' + SELECT `id_hook`, `name` + FROM `'._DB_PREFIX_.'hook` + UNION + SELECT `id_hook`, ha.`alias` as name + FROM `ps_hook_alias` ha + INNER JOIN `ps_hook` h ON ha.name = h.name'); + foreach ($result as $row) + $hook_ids[$row['name']] = $row['id_hook']; + Cache::store($cache_id, $hook_ids); } + else + $hook_ids = Cache::retrieve($cache_id); - return Cache::retrieve($cache_id); + return (isset($hook_ids[$hook_name]) ? $hook_ids[$hook_name] : false); } /** diff --git a/classes/ObjectModel.php b/classes/ObjectModel.php index a9aadd82d..d1cd8f5ad 100644 --- a/classes/ObjectModel.php +++ b/classes/ObjectModel.php @@ -242,16 +242,6 @@ abstract class ObjectModelCore $this->{$key} = $value; } } - - if (!is_array(self::$fieldsRequiredDatabase)) - { - $fields = $this->getfieldsRequiredDatabase(true); - if ($fields) - foreach ($fields as $row) - self::$fieldsRequiredDatabase[$row['object_name']][(int)$row['id_required_field']] = pSQL($row['field_name']); - else - self::$fieldsRequiredDatabase = array(); - } } /** @@ -901,6 +891,7 @@ abstract class ObjectModelCore */ public function validateField($field, $value, $id_lang = null) { + $this->cacheFieldsRequiredDatabase(); $data = $this->def['fields'][$field]; // Check if field is required @@ -983,6 +974,7 @@ abstract class ObjectModelCore public function validateController($htmlentities = true) { + $this->cacheFieldsRequiredDatabase(); $errors = array(); $required_fields_database = (isset(self::$fieldsRequiredDatabase[get_class($this)])) ? self::$fieldsRequiredDatabase[get_class($this)] : array(); foreach ($this->def['fields'] as $field => $data) @@ -1029,6 +1021,7 @@ abstract class ObjectModelCore public function getWebserviceParameters($ws_params_attribute_name = null) { + $this->cacheFieldsRequiredDatabase(); $default_resource_parameters = array( 'objectSqlId' => $this->def['primary'], 'retrieveData' => array( @@ -1139,6 +1132,7 @@ abstract class ObjectModelCore public function validateFieldsRequiredDatabase($htmlentities = true) { + $this->cacheFieldsRequiredDatabase(); $errors = array(); $required_fields = (isset(self::$fieldsRequiredDatabase[get_class($this)])) ? self::$fieldsRequiredDatabase[get_class($this)] : array(); @@ -1166,6 +1160,19 @@ abstract class ObjectModelCore FROM '._DB_PREFIX_.'required_field '.(!$all ? 'WHERE object_name = \''.pSQL(get_class($this)).'\'' : '')); } + + public function cacheFieldsRequiredDatabase() + { + if (!is_array(self::$fieldsRequiredDatabase)) + { + $fields = $this->getfieldsRequiredDatabase(true); + if ($fields) + foreach ($fields as $row) + self::$fieldsRequiredDatabase[$row['object_name']][(int)$row['id_required_field']] = pSQL($row['field_name']); + else + self::$fieldsRequiredDatabase = array(); + } + } public function addFieldsRequiredDatabase($fields) { diff --git a/classes/module/Module.php b/classes/module/Module.php index 6067612b6..b521e0fe4 100644 --- a/classes/module/Module.php +++ b/classes/module/Module.php @@ -153,18 +153,22 @@ abstract class ModuleCore // If cache is not generated, we generate it if (self::$modules_cache == null && !is_array(self::$modules_cache)) { - // Join clause is done to check if the module is activated in current shop context - $sql_limit_shop = 'SELECT COUNT(*) FROM `'._DB_PREFIX_.'module_shop` ms WHERE m.`id_module` = ms.`id_module` AND ms.`id_shop` = '.((is_object(Context::getContext()->shop) && $id = (int)Context::getContext()->shop->id) ? $id : 1); - - $sql = 'SELECT m.`id_module`, m.`name`, ('.$sql_limit_shop.') as total FROM `'._DB_PREFIX_.'module` m'; - - // Result is cached + $id_shop = (Validate::isLoadedObject($this->context->shop) ? $this->context->shop->id : 1); self::$modules_cache = array(); - $result = Db::getInstance()->executeS($sql); + // Join clause is done to check if the module is activated in current shop context + $result = Db::getInstance()->executeS(' + SELECT m.`id_module`, m.`name`, ( + SELECT id_module + FROM `'._DB_PREFIX_.'module_shop` ms + WHERE m.`id_module` = ms.`id_module` + AND ms.`id_shop` = '.(int)$id_shop.' + LIMIT 1 + ) as mshop + FROM `'._DB_PREFIX_.'module` m'); foreach ($result as $row) { self::$modules_cache[$row['name']] = $row; - self::$modules_cache[$row['name']]['active'] = ($row['total'] > 0) ? 1 : 0; + self::$modules_cache[$row['name']]['active'] = ($row['mshop'] > 0) ? 1 : 0; } } @@ -1511,12 +1515,12 @@ abstract class ModuleCore * @param int $id_hook Hook ID * @return array Exceptions */ - protected static $exceptionsCache = null; - public function getExceptions($hookID, $dispatch = false) + public function getExceptions($id_hook, $dispatch = false) { - if (self::$exceptionsCache === null) + $cache_id = 'exceptionsCache'; + if (!Cache::isStored($cache_id)) { - self::$exceptionsCache = array(); + $exceptionsCache = array(); $sql = 'SELECT * FROM `'._DB_PREFIX_.'hook_module_exceptions` WHERE `id_shop` IN ('.implode(', ', Shop::getContextListShopID()).')'; $result = Db::getInstance()->executeS($sql); @@ -1525,33 +1529,34 @@ abstract class ModuleCore if (!$row['file_name']) continue; $key = $row['id_hook'].'-'.$row['id_module']; - if (!isset(self::$exceptionsCache[$key])) - self::$exceptionsCache[$key] = array(); - if (!isset(self::$exceptionsCache[$key][$row['id_shop']])) - self::$exceptionsCache[$key][$row['id_shop']] = array(); - self::$exceptionsCache[$key][$row['id_shop']][] = $row['file_name']; + if (!isset($exceptionsCache[$key])) + $exceptionsCache[$key] = array(); + if (!isset($exceptionsCache[$key][$row['id_shop']])) + $exceptionsCache[$key][$row['id_shop']] = array(); + $exceptionsCache[$key][$row['id_shop']][] = $row['file_name']; } + Cache::store($cache_id, $exceptionsCache); } + else + $exceptionsCache = !Cache::retrieve($cache_id); - $key = $hookID.'-'.$this->id; - if (!$dispatch) + $key = $id_hook.'-'.$this->id; + $array_return = array(); + if ($dispatch) { - $files = array(); foreach (Shop::getContextListShopID() as $shop_id) - if (isset(self::$exceptionsCache[$key], self::$exceptionsCache[$key][$shop_id])) - foreach (self::$exceptionsCache[$key][$shop_id] as $file) - if (!in_array($file, $files)) - $files[] = $file; - return $files; + if (isset($exceptionsCache[$key], $exceptionsCache[$key][$shop_id])) + $array_return[$shop_id] = $exceptionsCache[$key][$shop_id]; } else { - $list = array(); foreach (Shop::getContextListShopID() as $shop_id) - if (isset(self::$exceptionsCache[$key], self::$exceptionsCache[$key][$shop_id])) - $list[$shop_id] = self::$exceptionsCache[$key][$shop_id]; - return $list; + if (isset($exceptionsCache[$key], $exceptionsCache[$key][$shop_id])) + foreach ($exceptionsCache[$key][$shop_id] as $file) + if (!in_array($file, $array_return)) + $array_return[] = $file; } + return $array_return; } public static function isInstalled($module_name) From 7570c9eb87dd7d31700759050cc6f582beb8b83b Mon Sep 17 00:00:00 2001 From: Fabio Chelly Date: Fri, 19 Jul 2013 11:15:14 +0200 Subject: [PATCH 46/57] [-] MO loyalty : minimum amount is now taken into account when creating discount vouchers #PNM-1561 --- modules/loyalty/controllers/front/default.php | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/loyalty/controllers/front/default.php b/modules/loyalty/controllers/front/default.php index 64e152db0..e28f5b7a6 100644 --- a/modules/loyalty/controllers/front/default.php +++ b/modules/loyalty/controllers/front/default.php @@ -89,6 +89,7 @@ class LoyaltyDefaultModuleFrontController extends ModuleFrontController $cart_rule->date_to = date('Y-m-d H:i:s', strtotime($cart_rule->date_from.' +1 year')); $cart_rule->minimum_amount = (float)Configuration::get('PS_LOYALTY_MINIMAL'); + $cart_rule->minimum_amount_currency = (int)$this->context->currency->id; $cart_rule->active = 1; $categories = Configuration::get('PS_LOYALTY_VOUCHER_CATEGORY'); From 989dafce21688d6997df621ebffe11ec25bea76c Mon Sep 17 00:00:00 2001 From: Damien Metzger Date: Fri, 19 Jul 2013 11:29:18 +0200 Subject: [PATCH 47/57] [*] FO : a few more SQL improvements --- classes/Connection.php | 4 ++++ classes/Hook.php | 2 +- classes/shop/ShopUrl.php | 35 ++++++++++++++++------------------- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/classes/Connection.php b/classes/Connection.php index b250e4ea5..4b171b1f0 100644 --- a/classes/Connection.php +++ b/classes/Connection.php @@ -82,8 +82,12 @@ class ConnectionCore extends ObjectModel // The connection is created if it does not exist yet and we get the current page id if (!isset($cookie->id_connections) || !strstr(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '', Tools::getHttpHost(false, false))) $id_page = Connection::setNewConnection($cookie); + // If we do not track the pages, no need to get the page id + if (!Configuration::get('PS_STATSDATA_PAGESVIEWS') && !Configuration::get('PS_STATSDATA_CUSTOMER_PAGESVIEWS')) + return array(); if (!isset($id_page) || !$id_page) $id_page = Page::getCurrentId(); + // If we do not track the page views by customer, the id_page is the only information needed if (!Configuration::get('PS_STATSDATA_CUSTOMER_PAGESVIEWS')) return array('id_page' => $id_page); diff --git a/classes/Hook.php b/classes/Hook.php index 407a8a83c..d9ba5f57e 100644 --- a/classes/Hook.php +++ b/classes/Hook.php @@ -83,7 +83,7 @@ class HookCore extends ObjectModel public function add($autodate = true, $null_values = false) { - Cache::clean('hook_idbyname_'.$this->name); + Cache::clean('hook_idsbyname'); return parent::add($autodate, $null_values); } diff --git a/classes/shop/ShopUrl.php b/classes/shop/ShopUrl.php index c8e4b6074..e1594c86b 100644 --- a/classes/shop/ShopUrl.php +++ b/classes/shop/ShopUrl.php @@ -143,22 +143,21 @@ class ShopUrlCore extends ObjectModel return Db::getInstance()->getValue($sql); } - public static function getMainShopDomain($id_shop = null) - { - if (!self::$main_domain || $id_shop !== null) - self::$main_domain = Db::getInstance()->getValue('SELECT domain - FROM '._DB_PREFIX_.'shop_url - WHERE main=1 AND id_shop = '.($id_shop !== null ? (int)$id_shop : Context::getContext()->shop->id)); - return self::$main_domain; - } - public static function cacheMainDomainForShop($id_shop) { if (!Validate::isUnsignedId($id_shop)) return false; - ShopUrl::getMainShopDomain($id_shop); - ShopUrl::getMainShopDomainSSL($id_shop); + if (!self::$main_domain_ssl || !self::$main_domain || $id_shop !== null) + { + $row = Db::getInstance()->getRow(' + SELECT domain, domain_ssl + FROM '._DB_PREFIX_.'shop_url + WHERE main = 1 + AND id_shop = '.($id_shop !== null ? (int)$id_shop : Context::getContext()->shop->id)); + self::$main_domain = $row['domain']; + self::$main_domain_ssl = $row['domain_ssl']; + } } public static function resetMainDomainCache() @@ -167,17 +166,15 @@ class ShopUrlCore extends ObjectModel self::$main_domain_ssl = null; } + public static function getMainShopDomain($id_shop = null) + { + ShopUrl::cacheMainDomainForShop($id_shop); + return self::$main_domain; + } public static function getMainShopDomainSSL($id_shop = null) { - if (!self::$main_domain_ssl || $id_shop !== null) - { - $sql = 'SELECT domain_ssl - FROM '._DB_PREFIX_.'shop_url - WHERE main = 1 - AND id_shop = '.($id_shop !== null ? (int)$id_shop : Context::getContext()->shop->id); - self::$main_domain_ssl = Db::getInstance()->getValue($sql); - } + ShopUrl::cacheMainDomainForShop($id_shop); return self::$main_domain_ssl; } } \ No newline at end of file From 8c47ca3edf9ccbf23569eb61bcc6aba5d0ef19e3 Mon Sep 17 00:00:00 2001 From: Damien Metzger Date: Fri, 19 Jul 2013 11:40:52 +0200 Subject: [PATCH 48/57] [-] BO : fixed sort by currency exchange rate #PSCFV-9840 --- controllers/admin/AdminCurrenciesController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/admin/AdminCurrenciesController.php b/controllers/admin/AdminCurrenciesController.php index c5d719483..bf8690b64 100644 --- a/controllers/admin/AdminCurrenciesController.php +++ b/controllers/admin/AdminCurrenciesController.php @@ -38,7 +38,7 @@ class AdminCurrenciesControllerCore extends AdminController 'iso_code' => array('title' => $this->l('ISO code'), 'align' => 'center', 'width' => 80), 'iso_code_num' => array('title' => $this->l('ISO code number'), 'align' => 'center', 'width' => 120), 'sign' => array('title' => $this->l('Symbol'), 'width' => 20, 'align' => 'center', 'orderby' => false, 'search' => false), - 'conversion_rate' => array('title' => $this->l('Exchange rate'), 'type' => 'float', 'align' => 'center', 'width' => 130, 'search' => false), + 'conversion_rate' => array('title' => $this->l('Exchange rate'), 'type' => 'float', 'align' => 'center', 'width' => 130, 'search' => false, 'filter_key' => 'currency_shop!conversion_rate'), 'active' => array('title' => $this->l('Enabled'), 'width' => 25, 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false), ); From 8d034a7ebf644fc1bffbcf48aee25e525a485ad3 Mon Sep 17 00:00:00 2001 From: Damien Metzger Date: Fri, 19 Jul 2013 13:33:41 +0200 Subject: [PATCH 49/57] // up --- modules/blockmyaccountfooter/config.xml | 2 +- modules/cheque/config.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/blockmyaccountfooter/config.xml b/modules/blockmyaccountfooter/config.xml index 0266fa7ae..aa3e350ae 100644 --- a/modules/blockmyaccountfooter/config.xml +++ b/modules/blockmyaccountfooter/config.xml @@ -2,7 +2,7 @@ blockmyaccountfooter - + diff --git a/modules/cheque/config.xml b/modules/cheque/config.xml index dd5655265..e49cd3934 100755 --- a/modules/cheque/config.xml +++ b/modules/cheque/config.xml @@ -1,7 +1,7 @@ cheque - + From 3389cf8acb77caa951456cf4d4e5b9bee5238746 Mon Sep 17 00:00:00 2001 From: Damien Metzger Date: Fri, 19 Jul 2013 14:08:24 +0200 Subject: [PATCH 50/57] [-] FO : fixed pagination for p = 0 #PSCFV-9746 --- classes/controller/FrontController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/classes/controller/FrontController.php b/classes/controller/FrontController.php index 88ebd4b4f..52c090097 100755 --- a/classes/controller/FrontController.php +++ b/classes/controller/FrontController.php @@ -849,8 +849,8 @@ class FrontControllerCore extends Controller $range = 2; /* how many pages around page selected */ - if ($this->p < 0) - $this->p = 0; + if ($this->p < 1) + $this->p = 1; if (isset($this->context->cookie->nb_item_per_page) && $this->n != $this->context->cookie->nb_item_per_page && in_array($this->n, $nArray)) $this->context->cookie->nb_item_per_page = $this->n; From 5646e682bc41386ab2f471b1ae6a2ef54852b5b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Nadaud?= Date: Fri, 19 Jul 2013 15:21:06 +0200 Subject: [PATCH 51/57] [-] BO : FIxBug Correct image language in product --- .../default/template/controllers/products/images.tpl | 9 ++++++--- controllers/admin/AdminProductsController.php | 3 +++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/admin-dev/themes/default/template/controllers/products/images.tpl b/admin-dev/themes/default/template/controllers/products/images.tpl index a686c8ec8..6c5cc4368 100644 --- a/admin-dev/themes/default/template/controllers/products/images.tpl +++ b/admin-dev/themes/default/template/controllers/products/images.tpl @@ -78,7 +78,7 @@ - image_id + image_id @@ -313,12 +313,13 @@ { line = $("#lineType").html(); line = line.replace(/image_id/g, id); - line = line.replace(/en-default/g, path); - line = line.replace(/image_path/g, path); + line = line.replace(/[a-z]{2}-default/g, path); + line = line.replace(/image_path/g, path); line = line.replace(/image_position/g, position); line = line.replace(/blank/g, cover); line = line.replace(//gi, ""); line = line.replace(/<\/tbody>/gi, ""); + if (shops != false) { $.each(shops, function(key, value){ @@ -326,8 +327,10 @@ line = line.replace('id="' + key + '' + id + '"','id="' + key + '' + id + '" checked=checked'); }); } + $("#imageList").append(line); } + $('.fancybox').fancybox(); }); {/literal} diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php index 614f386c2..91aac1d37 100644 --- a/controllers/admin/AdminProductsController.php +++ b/controllers/admin/AdminProductsController.php @@ -3659,12 +3659,15 @@ class AdminProductsControllerCore extends AdminController $current_shop_id = (int)$this->context->shop->id; else $current_shop_id = 0; + + $languages = Language::getLanguages(true); $data->assign(array( 'countImages' => $count_images, 'id_product' => (int)Tools::getValue('id_product'), 'id_category_default' => (int)$this->_category->id, 'images' => $images, + 'iso_lang' => $languages[0]['iso_code'], 'token' => $this->token, 'table' => $this->table, 'max_image_size' => $this->max_image_size / 1024 / 1024, From 84d9caca81227abea564ba8f31e0cd2255779b48 Mon Sep 17 00:00:00 2001 From: Damien Metzger Date: Fri, 19 Jul 2013 16:29:02 +0200 Subject: [PATCH 52/57] // Blind fix --- classes/module/Module.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/classes/module/Module.php b/classes/module/Module.php index b521e0fe4..225f492bf 100644 --- a/classes/module/Module.php +++ b/classes/module/Module.php @@ -1354,7 +1354,7 @@ abstract class ModuleCore elseif (isset($context->customer)) { $groups = $context->customer->getGroups(); - if (empty($groups)) + if (!count($groups)) $groups = array(Configuration::get('PS_UNIDENTIFIED_GROUP')); } @@ -1377,7 +1377,7 @@ abstract class ModuleCore '.(isset($billing) && $frontend ? 'AND mc.id_country = '.(int)$billing->id_country : '').' AND (SELECT COUNT(*) FROM '._DB_PREFIX_.'module_shop ms WHERE ms.id_module = m.id_module AND ms.id_shop IN('.implode(', ', $list).')) = '.count($list).' AND hm.id_shop IN('.implode(', ', $list).') - '.(count($groups) && $frontend ? 'AND (mg.`id_group` IN('.implode(', ', $groups).'))' : '').$paypal_condition.' + '.((count($groups) && $frontend) ? 'AND (mg.`id_group` IN ('.implode(', ', $groups).'))' : '').$paypal_condition.' GROUP BY hm.id_hook, hm.id_module ORDER BY hm.`position`, m.`name` DESC'); } From abf874d5760b17b5171ed8b0943ea45639c72cb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Nadaud?= Date: Fri, 19 Jul 2013 16:30:04 +0200 Subject: [PATCH 53/57] [-] BO : FixBug #PSCFV-9049 Bad actionOrderSlipAdd hook description --- install-dev/data/xml/hook.xml | 2 +- install-dev/upgrade/sql/1.5.5.0.sql | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/install-dev/data/xml/hook.xml b/install-dev/data/xml/hook.xml index 1139431f2..005284227 100644 --- a/install-dev/data/xml/hook.xml +++ b/install-dev/data/xml/hook.xml @@ -86,7 +86,7 @@ displayCustomerAccountCustomer account displayed in Front OfficeThis hook displays new elements on the customer account page - actionOrderSlipAddOrder slip creationThis hook is called when a product's quantity is modified + actionOrderSlipAddOrder slip creationThis hook is called when a new credit slip is added regarding client order displayProductTabTabs on product pageThis hook is called on the product page's tab diff --git a/install-dev/upgrade/sql/1.5.5.0.sql b/install-dev/upgrade/sql/1.5.5.0.sql index 934492867..152e75ea9 100644 --- a/install-dev/upgrade/sql/1.5.5.0.sql +++ b/install-dev/upgrade/sql/1.5.5.0.sql @@ -24,3 +24,5 @@ ALTER TABLE `PREFIX_log` ADD `id_employee` INT(10) UNSIGNED NULL AFTER `object_i SET @id_parent = (SELECT IFNULL(id_tab, 1) FROM `PREFIX_tab` WHERE `class_name` = 'AdminPriceRule' LIMIT 1); UPDATE `PREFIX_tab` SET id_parent = @id_parent WHERE `id_parent` = 1 AND `class_name` = 'AdminMarketing' LIMIT 1; + +UPDATE `PREFIX_hook` SET `description` = 'This hook is called when a new credit slip is added regarding client order' WHERE `name` = 'actionOrderSlipAdd'; \ No newline at end of file From b1f380c120951c2a5e2619102b53f8ad9c020748 Mon Sep 17 00:00:00 2001 From: Damien Metzger Date: Fri, 19 Jul 2013 16:59:39 +0200 Subject: [PATCH 54/57] // Fixed statsforecast category distribution --- modules/statsforecast/statsforecast.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/statsforecast/statsforecast.php b/modules/statsforecast/statsforecast.php index 23b3f4c52..ddd93c921 100644 --- a/modules/statsforecast/statsforecast.php +++ b/modules/statsforecast/statsforecast.php @@ -470,7 +470,7 @@ class StatsForecast extends Module $where = ' AND co.id_zone = '.(int)$this->context->cookie->stats_id_zone.' '; } - $sql = 'SELECT SUM(od.`product_price` * od.`product_quantity` / o.conversion_rate) as orderSum, COUNT(*) AS orderQty, cl.name, AVG(od.`product_price` / o.conversion_rate) as priveAvg + $sql = 'SELECT SUM(od.`product_price` * od.`product_quantity` / o.conversion_rate) as orderSum, SUM(od.product_quantity) as orderQty, cl.name, AVG(od.`product_price` / o.conversion_rate) as priveAvg FROM `'._DB_PREFIX_.'orders` o LEFT JOIN `'._DB_PREFIX_.'order_detail` od ON o.id_order = od.id_order LEFT JOIN `'._DB_PREFIX_.'product` p ON p.id_product = od.product_id From 5825dda836078eff6355f272aa3bfd67c229e6f7 Mon Sep 17 00:00:00 2001 From: Fabio Chelly Date: Fri, 19 Jul 2013 17:36:51 +0200 Subject: [PATCH 55/57] [-] MO mailalerts : infinite coverage (-1) is taken into account when sending coverage e-mails #PNM-1563 #PNM-1597 --- modules/mailalerts/mailalerts.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/mailalerts/mailalerts.php b/modules/mailalerts/mailalerts.php index 82e9da99a..1516c0de5 100644 --- a/modules/mailalerts/mailalerts.php +++ b/modules/mailalerts/mailalerts.php @@ -540,8 +540,7 @@ class MailAlerts extends Module $coverage = StockManagerFactory::getManager()->getProductCoverage($id_product, $id_product_attribute, $warning_coverage, $id_warehouse); // if we need to send a notification - if ($product->active == 1 && - ($coverage < $warning_coverage) && !empty($this->_merchant_mails) && + if ($product->active == 1 && $coverage !== -1 && ($coverage < $warning_coverage) && !empty($this->_merchant_mails) && Configuration::getGlobalValue('MA_MERCHANT_COVERAGE')) { $id_lang = (int)Context::getContext()->language->id; From 1581a371c564dc5ba6bd35c73deb60df2f15282e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Nadaud?= Date: Fri, 19 Jul 2013 18:41:46 +0200 Subject: [PATCH 56/57] [-] BO : FixBug #PSCFV-9251 Meta Tag delete previous --- js/jquery/plugins/tagify/jquery.tagify.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/js/jquery/plugins/tagify/jquery.tagify.js b/js/jquery/plugins/tagify/jquery.tagify.js index 87eea42b0..7ba821de5 100755 --- a/js/jquery/plugins/tagify/jquery.tagify.js +++ b/js/jquery/plugins/tagify/jquery.tagify.js @@ -40,10 +40,6 @@ // if backspace is hit with no input, remove the last tag if (pressed == 8) { // backspace - if ( $this.val() == "" ) { - self.remove(); - return false; - } return; } }); From 3483706951cca2bb88b892cd41227c5e8f94e2f5 Mon Sep 17 00:00:00 2001 From: gRoussac Date: Sat, 20 Jul 2013 19:07:10 +0200 Subject: [PATCH 57/57] [-] FO : Prevent unsassigned category id, thans @PrestaCaptainFLAM --- controllers/front/ProductController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/front/ProductController.php b/controllers/front/ProductController.php index d55dc92b9..46aa593c9 100644 --- a/controllers/front/ProductController.php +++ b/controllers/front/ProductController.php @@ -158,7 +158,7 @@ class ProductControllerCore extends FrontController $this->category = new Category($regs[5], (int)$this->context->cookie->id_lang); } } - else + if ( ! isset($this->category)) // Set default product category $this->category = new Category($this->product->id_category_default, (int)$this->context->cookie->id_lang); }