// Normalize
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@12652 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
+46
-48
@@ -59,20 +59,20 @@ class MediaCore
|
||||
'effects.shake' => array('fileName' => 'jquery.ui.mouse.min.js', 'dependencies' => array('effects.core'), 'theme' => false),
|
||||
'effects.slide' => array('fileName' => 'jquery.ui.mouse.min.js', 'dependencies' => array('effects.core'), 'theme' => false),
|
||||
'effects.transfer' => array('fileName' => 'jquery.ui.mouse.min.js', 'dependencies' => array('effects.core'), 'theme' => false)
|
||||
);
|
||||
|
||||
);
|
||||
|
||||
public static function minifyHTML($html_content)
|
||||
{
|
||||
if (strlen($html_content) > 0)
|
||||
{
|
||||
//set an alphabetical order for args
|
||||
$html_content = preg_replace_callback(
|
||||
'/(<[a-zA-Z0-9]+)((\s?[a-zA-Z0-9]+=[\"\\\'][^\"\\\']*[\"\\\']\s?)*)>/'
|
||||
,array('Media', 'minifyHTMLpregCallback')
|
||||
,$html_content);
|
||||
'/(<[a-zA-Z0-9]+)((\s?[a-zA-Z0-9]+=[\"\\\'][^\"\\\']*[\"\\\']\s?)*)>/',
|
||||
array('Media', 'minifyHTMLpregCallback'),
|
||||
$html_content);
|
||||
|
||||
require_once(_PS_TOOL_DIR_.'minify_html/minify_html.class.php');
|
||||
$html_content = str_replace(chr(194) . chr(160), ' ', $html_content);
|
||||
$html_content = str_replace(chr(194).chr(160), ' ', $html_content);
|
||||
$html_content = Minify_HTML::minify($html_content, array('xhtml', 'cssMinifier', 'jsMinifier'));
|
||||
|
||||
if (Configuration::get('PS_HIGH_HTML_THEME_COMPRESSION'))
|
||||
@@ -117,17 +117,18 @@ class MediaCore
|
||||
{
|
||||
if (strlen($html_content) > 0)
|
||||
{
|
||||
$htmlContentCopy = $html_content;
|
||||
$html_content_copy = $html_content;
|
||||
$html_content = preg_replace_callback(
|
||||
'/\\s*(<script\\b[^>]*?>)([\\s\\S]*?)(<\\/script>)\\s*/i'
|
||||
,array('Media', 'packJSinHTMLpregCallback')
|
||||
,$html_content);
|
||||
'/\\s*(<script\\b[^>]*?>)([\\s\\S]*?)(<\\/script>)\\s*/i',
|
||||
array('Media', 'packJSinHTMLpregCallback'),
|
||||
$html_content);
|
||||
|
||||
// If the string is too big preg_replace return an error
|
||||
// In this case, we don't compress the content
|
||||
if( preg_last_error() == PREG_BACKTRACK_LIMIT_ERROR ) {
|
||||
if (preg_last_error() == PREG_BACKTRACK_LIMIT_ERROR)
|
||||
{
|
||||
error_log('ERROR: PREG_BACKTRACK_LIMIT_ERROR in function packJSinHTML');
|
||||
return $htmlContentCopy;
|
||||
return $html_content_copy;
|
||||
}
|
||||
return $html_content;
|
||||
}
|
||||
@@ -138,7 +139,7 @@ class MediaCore
|
||||
{
|
||||
$preg_matches[1] = $preg_matches[1].'/* <![CDATA[ */';
|
||||
$preg_matches[2] = Media::packJS($preg_matches[2]);
|
||||
$preg_matches[count($preg_matches)-1] = '/* ]]> */'.$preg_matches[count($preg_matches)-1];
|
||||
$preg_matches[count($preg_matches) - 1] = '/* ]]> */'.$preg_matches[count($preg_matches) - 1];
|
||||
unset($preg_matches[0]);
|
||||
$output = implode('', $preg_matches);
|
||||
return $output;
|
||||
@@ -163,9 +164,9 @@ class MediaCore
|
||||
if (strlen($css_content) > 0)
|
||||
{
|
||||
$css_content = preg_replace('#/\*.*?\*/#s', '', $css_content);
|
||||
$css_content = preg_replace_callback('#url\((?:\'|")?([^\)\'"]*)(?:\'|")?\)#s',array('Tools', 'replaceByAbsoluteURL'), $css_content);
|
||||
$css_content = preg_replace_callback('#url\((?:\'|")?([^\)\'"]*)(?:\'|")?\)#s', array('Tools', 'replaceByAbsoluteURL'), $css_content);
|
||||
|
||||
$css_content = preg_replace('#\s+#',' ',$css_content);
|
||||
$css_content = preg_replace('#\s+#', ' ', $css_content);
|
||||
$css_content = str_replace("\t", '', $css_content);
|
||||
$css_content = str_replace("\n", '', $css_content);
|
||||
//$css_content = str_replace('}', "}\n", $css_content);
|
||||
@@ -208,7 +209,7 @@ class MediaCore
|
||||
*/
|
||||
public static function getJSPath($js_uri)
|
||||
{
|
||||
if (is_array($js_uri) OR is_null($js_uri) OR empty($js_uri))
|
||||
if (is_array($js_uri) || is_null($js_uri) || empty($js_uri))
|
||||
return false;
|
||||
$url_data = parse_url($js_uri);
|
||||
if (!array_key_exists('host', $url_data))
|
||||
@@ -247,7 +248,7 @@ class MediaCore
|
||||
return $css_uri;
|
||||
return array($css_uri => $css_media_type);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* return jquery path.
|
||||
*
|
||||
@@ -255,12 +256,12 @@ class MediaCore
|
||||
* @return string
|
||||
*/
|
||||
public static function getJqueryPath($version = null, $folder = null, $minifier = true)
|
||||
{
|
||||
$addNoConflict = false;
|
||||
{
|
||||
$add_no_conflict = false;
|
||||
if (is_null($version))
|
||||
$version = _PS_JQUERY_VERSION_; //set default version
|
||||
else if (preg_match('/^([0-9]+\.)+[0-9]$/Ui', $version))
|
||||
$addNoConflict = true;
|
||||
$add_no_conflict = true;
|
||||
else
|
||||
return false;
|
||||
|
||||
@@ -279,9 +280,9 @@ class MediaCore
|
||||
else
|
||||
$return[] = Media::getJSPath(Tools::getCurrentUrlProtocolPrefix().'ajax.googleapis.com/ajax/libs/jquery/'.$version.'/jquery'.($minifier ? '.min.js' : '.js'));
|
||||
|
||||
if ($addNoConflict)
|
||||
if ($add_no_conflict)
|
||||
$return[] = Media::getJSPath(_PS_JS_DIR_.'jquery/jquery.noConflict.php?version='.$version);
|
||||
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
@@ -302,40 +303,39 @@ class MediaCore
|
||||
if ($check_dependencies && array_key_exists($component, self::$jquery_ui_dependencies))
|
||||
foreach (self::$jquery_ui_dependencies[$component]['dependencies'] as $dependency)
|
||||
$ui_tmp[] = Media::getJqueryUIPath($dependency, $theme, false);
|
||||
|
||||
if (self::$jquery_ui_dependencies[$component]['theme'] AND $check_dependencies)
|
||||
|
||||
if (self::$jquery_ui_dependencies[$component]['theme'] && $check_dependencies)
|
||||
{
|
||||
$theme_css = Media::getCSSPath($folder.'themes/'.$theme.'/jquery.ui.theme.css');
|
||||
$comp_css = Media::getCSSPath($folder.'themes/'.$theme.'/jquery.'.$component.'.css');
|
||||
if (!empty($theme_css) OR $theme_css)
|
||||
if (!empty($theme_css) || $theme_css)
|
||||
$ui_path['css'] = array_merge($ui_path['css'], $theme_css);
|
||||
if (!empty($comp_css) OR $comp_css)
|
||||
if (!empty($comp_css) || $comp_css)
|
||||
$ui_path['css'] = array_merge($ui_path['css'], $comp_css);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (file_exists($file_uri))
|
||||
{
|
||||
if (!empty($ui_tmp))
|
||||
{
|
||||
foreach($ui_tmp as $ui)
|
||||
foreach ($ui_tmp as $ui)
|
||||
{
|
||||
$ui_path['js'][] = $ui['js'];
|
||||
$ui_path['css'][] = $ui['css'];
|
||||
}
|
||||
}
|
||||
$ui_path['js'][] = Media::getJSPath($folder.$file);
|
||||
}
|
||||
else
|
||||
$ui_path['js'] = Media::getJSPath($folder.$file);
|
||||
}
|
||||
|
||||
|
||||
//add i18n file for datepicker
|
||||
if ($component == 'ui.datepicker')
|
||||
$ui_path['js'][] = Media::getJSPath($folder.'i18n/jquery.ui.datepicker-'.Context::getContext()->language->iso_code.'.js');
|
||||
|
||||
|
||||
return $ui_path;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* return jquery plugin path.
|
||||
*
|
||||
@@ -347,7 +347,7 @@ class MediaCore
|
||||
$plugin_path = array('js' => array(), 'css' => array());
|
||||
if (is_null($folder))
|
||||
$folder = _PS_JS_DIR_.'jquery/plugins/'; //set default folder
|
||||
|
||||
|
||||
$file = 'jquery.'.$name.'.js';
|
||||
$url_data = parse_url($folder);
|
||||
$file_uri = _PS_ROOT_DIR_.Tools::str_replace_once(__PS_BASE_URI__, DIRECTORY_SEPARATOR, $url_data['path']);
|
||||
@@ -360,7 +360,7 @@ class MediaCore
|
||||
$plugin_path['css'] = Media::getJqueryPluginCSSPath($name);
|
||||
return $plugin_path;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* return jquery plugin css path if exist.
|
||||
*
|
||||
@@ -369,8 +369,7 @@ class MediaCore
|
||||
*/
|
||||
public static function getJqueryPluginCSSPath($name)
|
||||
{
|
||||
$plugin_path = array('js' => array(), 'css' => array());
|
||||
$folder = _PS_JS_DIR_.'jquery/plugins/';
|
||||
$folder = _PS_JS_DIR_.'jquery/plugins/';
|
||||
$file = 'jquery.'.$name.'.css';
|
||||
$url_data = parse_url($folder);
|
||||
$file_uri = _PS_ROOT_DIR_.Tools::str_replace_once(__PS_BASE_URI__, DIRECTORY_SEPARATOR, $url_data['path']);
|
||||
@@ -381,21 +380,21 @@ class MediaCore
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Combine Compress and Cache CSS (ccc) calls
|
||||
*
|
||||
* @param array css_files
|
||||
* @return array processed css_files
|
||||
*/
|
||||
public static function cccCss($css_files)
|
||||
public static function cccCss($css_files)
|
||||
{
|
||||
//inits
|
||||
$css_files_by_media = array();
|
||||
$compressed_css_files = array();
|
||||
$compressed_css_files_not_found = array();
|
||||
$compressed_css_files_infos = array();
|
||||
$protocolLink = Tools::getCurrentUrlProtocolPrefix();
|
||||
$protocol_link = Tools::getCurrentUrlProtocolPrefix();
|
||||
|
||||
// group css files by media
|
||||
foreach ($css_files as $filename => $media)
|
||||
@@ -423,7 +422,7 @@ class MediaCore
|
||||
// get compressed css file infos
|
||||
foreach ($compressed_css_files_infos as $media => &$info)
|
||||
{
|
||||
$key = md5($info['key'].$protocolLink);
|
||||
$key = md5($info['key'].$protocol_link);
|
||||
$filename = _PS_THEME_DIR_.'cache/'.$key.'_'.$media.'.css';
|
||||
$info = array(
|
||||
'key' => $key,
|
||||
@@ -436,7 +435,7 @@ class MediaCore
|
||||
foreach ($css_files_by_media as $media => $media_infos)
|
||||
{
|
||||
$cache_filename = _PS_THEME_DIR_.'cache/'.$compressed_css_files_infos[$media]['key'].'_'.$media.'.css';
|
||||
if (1||$media_infos['date'] > $compressed_css_files_infos[$media]['date'])
|
||||
if ($media_infos['date'] > $compressed_css_files_infos[$media]['date'])
|
||||
{
|
||||
$compressed_css_files[$media] = '';
|
||||
foreach ($media_infos['files'] as $file_infos)
|
||||
@@ -465,7 +464,7 @@ class MediaCore
|
||||
foreach ($compressed_css_files as $media => $filename)
|
||||
{
|
||||
$url = str_replace(_PS_THEME_DIR_, _THEMES_DIR_._THEME_NAME_.'/', $filename);
|
||||
$css_files[$protocolLink.Tools::getMediaServer($url).$url] = $media;
|
||||
$css_files[$protocol_link.Tools::getMediaServer($url).$url] = $media;
|
||||
}
|
||||
return $css_files;
|
||||
}
|
||||
@@ -477,16 +476,15 @@ class MediaCore
|
||||
* @param array js_files
|
||||
* @return array processed js_files
|
||||
*/
|
||||
public static function cccJS($js_files)
|
||||
public static function cccJS($js_files)
|
||||
{
|
||||
//inits
|
||||
$compressed_js_files_not_found = array();
|
||||
$js_files_infos = array();
|
||||
$js_files_date = 0;
|
||||
$compressed_js_file_date = 0;
|
||||
$compressed_js_filename = '';
|
||||
$js_external_files = array();
|
||||
$protocolLink = Tools::getCurrentUrlProtocolPrefix();
|
||||
$protocol_link = Tools::getCurrentUrlProtocolPrefix();
|
||||
|
||||
// get js files infos
|
||||
foreach ($js_files as $filename)
|
||||
@@ -500,7 +498,7 @@ class MediaCore
|
||||
$infos = array();
|
||||
$infos['uri'] = $filename;
|
||||
$url_data = parse_url($filename);
|
||||
$infos['path'] =_PS_ROOT_DIR_.Tools::str_replace_once(__PS_BASE_URI__, '/', $url_data['path']);
|
||||
$infos['path'] = _PS_ROOT_DIR_.Tools::str_replace_once(__PS_BASE_URI__, '/', $url_data['path']);
|
||||
$js_files_infos[] = $infos;
|
||||
|
||||
$js_files_date = max(
|
||||
@@ -542,7 +540,7 @@ class MediaCore
|
||||
// rebuild the original js_files array
|
||||
$url = str_replace(_PS_ROOT_DIR_.'/', __PS_BASE_URI__, $compressed_js_path);
|
||||
|
||||
return array_merge(array($protocolLink.Tools::getMediaServer($url).$url), $js_external_files);
|
||||
return array_merge(array($protocol_link.Tools::getMediaServer($url).$url), $js_external_files);
|
||||
}
|
||||
|
||||
}
|
||||
+55
-51
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2011 PrestaShop
|
||||
* 2007-2011 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
@@ -27,28 +27,28 @@
|
||||
|
||||
class MessageCore extends ObjectModel
|
||||
{
|
||||
public $id;
|
||||
|
||||
public $id;
|
||||
|
||||
/** @var string message content */
|
||||
public $message;
|
||||
|
||||
public $message;
|
||||
|
||||
/** @var integer Cart ID (if applicable) */
|
||||
public $id_cart;
|
||||
|
||||
public $id_cart;
|
||||
|
||||
/** @var integer Order ID (if applicable) */
|
||||
public $id_order;
|
||||
|
||||
public $id_order;
|
||||
|
||||
/** @var integer Customer ID (if applicable) */
|
||||
public $id_customer;
|
||||
|
||||
public $id_customer;
|
||||
|
||||
/** @var integer Employee ID (if applicable) */
|
||||
public $id_employee;
|
||||
|
||||
public $id_employee;
|
||||
|
||||
/** @var boolean Message is not displayed to the customer */
|
||||
public $private;
|
||||
|
||||
public $private;
|
||||
|
||||
/** @var string Object creation date */
|
||||
public $date_add;
|
||||
public $date_add;
|
||||
|
||||
/**
|
||||
* @see ObjectModel::$definition
|
||||
@@ -75,15 +75,13 @@ class MessageCore extends ObjectModel
|
||||
*/
|
||||
public static function getMessageByCartId($id_cart)
|
||||
{
|
||||
$db = Db::getInstance();
|
||||
$result = $db->getRow('
|
||||
SELECT *
|
||||
FROM `'._DB_PREFIX_.'message`
|
||||
WHERE `id_cart` = '.(int)($id_cart));
|
||||
|
||||
return $result;
|
||||
return Db::getInstance()->getRow('
|
||||
SELECT *
|
||||
FROM `'._DB_PREFIX_.'message`
|
||||
WHERE `id_cart` = '.(int)$id_cart
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return messages from Order ID
|
||||
*
|
||||
@@ -91,26 +89,30 @@ class MessageCore extends ObjectModel
|
||||
* @param boolean $private return WITH private messages
|
||||
* @return array Messages
|
||||
*/
|
||||
static public function getMessagesByOrderId($id_order, $private = false, Context $context = null)
|
||||
public static function getMessagesByOrderId($id_order, $private = false, Context $context = null)
|
||||
{
|
||||
if (!Validate::isBool($private))
|
||||
die(Tools::displayError());
|
||||
|
||||
if (!$context)
|
||||
$context = Context::getContext();
|
||||
|
||||
|
||||
return Db::getInstance()->executeS('
|
||||
SELECT m.*, c.`firstname` AS cfirstname, c.`lastname` AS clastname, e.`firstname` AS efirstname, e.`lastname` AS elastname, (COUNT(mr.id_message) = 0 AND m.id_customer != 0) AS is_new_for_me
|
||||
FROM `'._DB_PREFIX_.'message` m
|
||||
LEFT JOIN `'._DB_PREFIX_.'customer` c ON m.`id_customer` = c.`id_customer`
|
||||
LEFT JOIN `'._DB_PREFIX_.'message_readed` mr ON (mr.`id_message` = m.`id_message` AND mr.`id_employee` = '.(isset($context->employee) ? (int)$context->employee->id : '\'\'').')
|
||||
LEFT OUTER JOIN `'._DB_PREFIX_.'employee` e ON e.`id_employee` = m.`id_employee`
|
||||
WHERE id_order = '.(int)$id_order.'
|
||||
'.(!$private ? ' AND m.`private` = 0' : '').'
|
||||
GROUP BY m.id_message
|
||||
ORDER BY m.date_add DESC');
|
||||
SELECT m.*, c.`firstname` AS cfirstname, c.`lastname` AS clastname, e.`firstname` AS efirstname, e.`lastname` AS elastname,
|
||||
(COUNT(mr.id_message) = 0 AND m.id_customer != 0) AS is_new_for_me
|
||||
FROM `'._DB_PREFIX_.'message` m
|
||||
LEFT JOIN `'._DB_PREFIX_.'customer` c ON m.`id_customer` = c.`id_customer`
|
||||
LEFT JOIN `'._DB_PREFIX_.'message_readed` mr
|
||||
ON mr.`id_message` = m.`id_message`
|
||||
AND mr.`id_employee` = '.(isset($context->employee) ? (int)$context->employee->id : '\'\'').'
|
||||
LEFT OUTER JOIN `'._DB_PREFIX_.'employee` e ON e.`id_employee` = m.`id_employee`
|
||||
WHERE id_order = '.(int)$id_order.'
|
||||
'.(!$private ? ' AND m.`private` = 0' : '').'
|
||||
GROUP BY m.id_message
|
||||
ORDER BY m.date_add DESC
|
||||
');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return messages from Cart ID
|
||||
*
|
||||
@@ -118,26 +120,28 @@ class MessageCore extends ObjectModel
|
||||
* @param boolean $private return WITH private messages
|
||||
* @return array Messages
|
||||
*/
|
||||
static public function getMessagesByCartId($id_cart, $private = false, Context $context = null)
|
||||
public static function getMessagesByCartId($id_cart, $private = false, Context $context = null)
|
||||
{
|
||||
if (!Validate::isBool($private))
|
||||
die(Tools::displayError());
|
||||
|
||||
if (!$context)
|
||||
$context = Context::getContext();
|
||||
|
||||
|
||||
return Db::getInstance()->executeS('
|
||||
SELECT m.*, c.`firstname` AS cfirstname, c.`lastname` AS clastname, e.`firstname` AS efirstname, e.`lastname` AS elastname, (COUNT(mr.id_message) = 0 AND m.id_customer != 0) AS is_new_for_me
|
||||
FROM `'._DB_PREFIX_.'message` m
|
||||
LEFT JOIN `'._DB_PREFIX_.'customer` c ON m.`id_customer` = c.`id_customer`
|
||||
LEFT JOIN `'._DB_PREFIX_.'message_readed` mr ON (mr.id_message = m.id_message AND mr.id_employee = '.(int)$context->employee->id.')
|
||||
LEFT OUTER JOIN `'._DB_PREFIX_.'employee` e ON e.`id_employee` = m.`id_employee`
|
||||
WHERE id_cart = '.(int)$id_cart.'
|
||||
'.(!$private ? ' AND m.`private` = 0' : '').'
|
||||
GROUP BY m.id_message
|
||||
ORDER BY m.date_add DESC');
|
||||
SELECT m.*, c.`firstname` AS cfirstname, c.`lastname` AS clastname, e.`firstname` AS efirstname, e.`lastname` AS elastname,
|
||||
(COUNT(mr.id_message) = 0 AND m.id_customer != 0) AS is_new_for_me
|
||||
FROM `'._DB_PREFIX_.'message` m
|
||||
LEFT JOIN `'._DB_PREFIX_.'customer` c ON m.`id_customer` = c.`id_customer`
|
||||
LEFT JOIN `'._DB_PREFIX_.'message_readed` mr ON (mr.id_message = m.id_message AND mr.id_employee = '.(int)$context->employee->id.')
|
||||
LEFT OUTER JOIN `'._DB_PREFIX_.'employee` e ON e.`id_employee` = m.`id_employee`
|
||||
WHERE id_cart = '.(int)$id_cart.'
|
||||
'.(!$private ? ' AND m.`private` = 0' : '').'
|
||||
GROUP BY m.id_message
|
||||
ORDER BY m.date_add DESC
|
||||
');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Registered a message 'readed'
|
||||
*
|
||||
@@ -146,12 +150,12 @@ class MessageCore extends ObjectModel
|
||||
*/
|
||||
public static function markAsReaded($id_message, $id_employee)
|
||||
{
|
||||
if (!Validate::isUnsignedId($id_message) OR !Validate::isUnsignedId($id_employee))
|
||||
if (!Validate::isUnsignedId($id_message) || !Validate::isUnsignedId($id_employee))
|
||||
die(Tools::displayError());
|
||||
|
||||
$result = Db::getInstance()->execute('
|
||||
INSERT INTO '._DB_PREFIX_.'message_readed (id_message , id_employee , date_add) VALUES
|
||||
('.(int)($id_message).', '.(int)($id_employee).', NOW());
|
||||
INSERT INTO '._DB_PREFIX_.'message_readed (id_message , id_employee , date_add) VALUES
|
||||
('.(int)$id_message.', '.(int)$id_employee.', NOW());
|
||||
');
|
||||
return $result;
|
||||
}
|
||||
|
||||
+30
-27
@@ -28,11 +28,11 @@
|
||||
class MetaCore extends ObjectModel
|
||||
{
|
||||
/** @var string Name */
|
||||
public $page;
|
||||
public $title;
|
||||
public $description;
|
||||
public $keywords;
|
||||
public $url_rewrite;
|
||||
public $page;
|
||||
public $title;
|
||||
public $description;
|
||||
public $keywords;
|
||||
public $url_rewrite;
|
||||
|
||||
/**
|
||||
* @see ObjectModel::$definition
|
||||
@@ -53,33 +53,36 @@ class MetaCore extends ObjectModel
|
||||
),
|
||||
);
|
||||
|
||||
public static function getPages($excludeFilled = false, $addPage = false)
|
||||
public static function getPages($exclude_filled = false, $add_page = false)
|
||||
{
|
||||
$selectedPages = array();
|
||||
$selected_pages = array();
|
||||
if (!$files = scandir(_PS_ROOT_DIR_.'/controllers'))
|
||||
die(Tools::displayError('Cannot scan root directory'));
|
||||
|
||||
// Exclude pages forbidden
|
||||
$exludePages = array('category', 'changecurrency', 'cms', 'footer', 'header',
|
||||
'pagination', 'product', 'product-sort', 'statistics');
|
||||
$exlude_pages = array(
|
||||
'category', 'changecurrency', 'cms', 'footer', 'header',
|
||||
'pagination', 'product', 'product-sort', 'statistics'
|
||||
);
|
||||
|
||||
foreach ($files as $file)
|
||||
if (preg_match('/^[a-z0-9_.-]*\.php$/i', $file) AND !in_array(strtolower(str_replace('Controller.php', '', $file)), $exludePages))
|
||||
$selectedPages[] = strtolower(str_replace('Controller.php', '', $file));
|
||||
if (preg_match('/^[a-z0-9_.-]*\.php$/i', $file) && !in_array(strtolower(str_replace('Controller.php', '', $file)), $exlude_pages))
|
||||
$selected_pages[] = strtolower(str_replace('Controller.php', '', $file));
|
||||
// Exclude page already filled
|
||||
if ($excludeFilled)
|
||||
if ($exclude_filled)
|
||||
{
|
||||
$metas = Meta::getMetas();
|
||||
foreach ($metas as $meta)
|
||||
if (in_array($meta['page'], $selectedPages))
|
||||
unset($selectedPages[array_search($meta['page'], $selectedPages)]);
|
||||
if (in_array($meta['page'], $selected_pages))
|
||||
unset($selected_pages[array_search($meta['page'], $selected_pages)]);
|
||||
}
|
||||
// Add selected page
|
||||
if ($addPage)
|
||||
if ($add_page)
|
||||
{
|
||||
$selectedPages[] = $addPage;
|
||||
sort($selectedPages);
|
||||
$selected_pages[] = $add_page;
|
||||
sort($selected_pages);
|
||||
}
|
||||
return $selectedPages;
|
||||
return $selected_pages;
|
||||
}
|
||||
|
||||
public static function getMetas()
|
||||
@@ -90,7 +93,7 @@ class MetaCore extends ObjectModel
|
||||
ORDER BY page ASC');
|
||||
}
|
||||
|
||||
static public function getMetasByIdLang($id_lang, Shop $shop = null)
|
||||
public static function getMetasByIdLang($id_lang, Shop $shop = null)
|
||||
{
|
||||
if (!$shop)
|
||||
$shop = Context::getContext()->shop;
|
||||
@@ -105,7 +108,7 @@ class MetaCore extends ObjectModel
|
||||
|
||||
}
|
||||
|
||||
static public function getMetaByPage($page, $id_lang, Context $context = null)
|
||||
public static function getMetaByPage($page, $id_lang, Context $context = null)
|
||||
{
|
||||
if (!$context)
|
||||
$context = Context::getContext();
|
||||
@@ -119,9 +122,9 @@ class MetaCore extends ObjectModel
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
|
||||
}
|
||||
|
||||
public function update($nullValues = false)
|
||||
public function update($null_values = false)
|
||||
{
|
||||
if (!parent::update($nullValues))
|
||||
if (!parent::update($null_values))
|
||||
return false;
|
||||
|
||||
return Tools::generateHtaccess();
|
||||
@@ -140,10 +143,10 @@ class MetaCore extends ObjectModel
|
||||
if (!is_array($selection))
|
||||
die(Tools::displayError());
|
||||
$result = true;
|
||||
foreach ($selection AS $id)
|
||||
foreach ($selection as $id)
|
||||
{
|
||||
$this->id = (int)($id);
|
||||
$result = $result AND $this->delete();
|
||||
$this->id = (int)$id;
|
||||
$result = $result && $this->delete();
|
||||
}
|
||||
|
||||
return Tools::generateHtaccess();
|
||||
@@ -157,10 +160,10 @@ class MetaCore extends ObjectModel
|
||||
WHERE id_meta = (
|
||||
SELECT id_meta
|
||||
FROM `'._DB_PREFIX_.'meta_lang`
|
||||
WHERE url_rewrite = \''.pSQL($url_rewrite).'\' AND id_lang = '.(int)($id_lang).'
|
||||
WHERE url_rewrite = \''.pSQL($url_rewrite).'\' AND id_lang = '.(int)$id_lang.'
|
||||
AND id_shop = '.Context::getContext()->shop->getID(true).'
|
||||
)
|
||||
AND id_lang = '.(int)($new_id_lang).'
|
||||
AND id_lang = '.(int)$new_id_lang.'
|
||||
AND id_shop = '.Context::getContext()->shop->getID(true));
|
||||
}
|
||||
}
|
||||
|
||||
+161
-171
@@ -28,7 +28,7 @@
|
||||
abstract class ModuleCore
|
||||
{
|
||||
/** @var integer Module ID */
|
||||
public $id = NULL;
|
||||
public $id = null;
|
||||
|
||||
/** @var float Version */
|
||||
public $version;
|
||||
@@ -61,7 +61,7 @@ abstract class ModuleCore
|
||||
public $need_instance = 1;
|
||||
|
||||
/** @var string Admin tab correponding to the module */
|
||||
public $tab = NULL;
|
||||
public $tab = null;
|
||||
|
||||
/** @var boolean Status */
|
||||
public $active = false;
|
||||
@@ -79,12 +79,12 @@ abstract class ModuleCore
|
||||
protected $_lang = array();
|
||||
|
||||
/** @var string Module web path (eg. '/shop/modules/modulename/') */
|
||||
protected $_path = NULL;
|
||||
protected $_path = null;
|
||||
/**
|
||||
* @since 1.5.1
|
||||
* @var string Module local path (eg. '/home/prestashop/modules/modulename/')
|
||||
*/
|
||||
protected $local_path = NULL;
|
||||
protected $local_path = null;
|
||||
|
||||
/** @var protected array filled with module errors */
|
||||
protected $_errors = array();
|
||||
@@ -132,19 +132,19 @@ abstract class ModuleCore
|
||||
$this->smarty = $this->context->smarty->createData($this->context->smarty);
|
||||
|
||||
// If the module has no name we gave him its id as name
|
||||
if ($this->name == NULL)
|
||||
if ($this->name == null)
|
||||
$this->name = $this->id;
|
||||
|
||||
// If the module has the name we load the corresponding data from the cache
|
||||
if ($this->name != NULL)
|
||||
if ($this->name != null)
|
||||
{
|
||||
// If cache is not generated, we generate it
|
||||
if (self::$modules_cache == NULL AND !is_array(self::$modules_cache))
|
||||
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
|
||||
$list = $this->context->shop->getListOfID();
|
||||
$sqlLimitShop = 'SELECT COUNT(*) FROM `'._DB_PREFIX_.'module_shop` ms WHERE m.`id_module` = ms.`id_module` AND ms.`id_shop` IN ('.implode(',', $list).')';
|
||||
$sql = 'SELECT m.`id_module`, m.`name`, ('.$sqlLimitShop.') as total FROM `'._DB_PREFIX_.'module` m';
|
||||
$sql_limit_shop = 'SELECT COUNT(*) FROM `'._DB_PREFIX_.'module_shop` ms WHERE m.`id_module` = ms.`id_module` AND ms.`id_shop` IN ('.implode(',', $list).')';
|
||||
$sql = 'SELECT m.`id_module`, m.`name`, ('.$sql_limit_shop.') as total FROM `'._DB_PREFIX_.'module` m';
|
||||
|
||||
// Result is cached
|
||||
self::$modules_cache = array();
|
||||
@@ -161,7 +161,7 @@ abstract class ModuleCore
|
||||
{
|
||||
$this->active = self::$modules_cache[$this->name]['active'];
|
||||
$this->id = self::$modules_cache[$this->name]['id_module'];
|
||||
foreach (self::$modules_cache[$this->name] AS $key => $value)
|
||||
foreach (self::$modules_cache[$this->name] as $key => $value)
|
||||
if (key_exists($key, $this))
|
||||
$this->{$key} = $value;
|
||||
$this->_path = __PS_BASE_URI__.'modules/'.$this->name.'/';
|
||||
@@ -305,8 +305,7 @@ abstract class ModuleCore
|
||||
);
|
||||
|
||||
// Need Upgrade will check and load upgrade file to the moduleCache upgrade case detail
|
||||
return (bool)(Module::isInstalled($module_name) &&
|
||||
Module::needUpgrade($module_name, $module_version));
|
||||
return Module::isInstalled($module_name) && Module::needUpgrade($module_name, $module_version);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -317,7 +316,7 @@ abstract class ModuleCore
|
||||
public function runUpgradeModule()
|
||||
{
|
||||
$upgrade = &self::$modules_cache[$this->name]['upgrade'];
|
||||
foreach($upgrade['upgrade_file_left'] as $num => $file_detail)
|
||||
foreach ($upgrade['upgrade_file_left'] as $num => $file_detail)
|
||||
{
|
||||
// Default variable required in the included upgrade file need to be set by default there:
|
||||
// upgrade_version, success_upgrade
|
||||
@@ -377,8 +376,8 @@ abstract class ModuleCore
|
||||
|
||||
self::$modules_cache[$module_name]['upgrade']['upgraded_from'] = $registered_version;
|
||||
// Check the version of the module with the registered one and look if any upgrade file exist
|
||||
return (bool)(version_compare($module_version, $registered_version, '>') &&
|
||||
Module::loadUpgradeVersionList($module_name, $module_version, $registered_version));
|
||||
return version_compare($module_version, $registered_version, '>')
|
||||
&& Module::loadUpgradeVersionList($module_name, $module_version, $registered_version);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -394,10 +393,10 @@ abstract class ModuleCore
|
||||
{
|
||||
$list = array();
|
||||
|
||||
$upgradePath = _PS_MODULE_DIR_.$module_name.'/'.'upgrade/';
|
||||
$upgrade_path = _PS_MODULE_DIR_.$module_name.'/upgrade/';
|
||||
|
||||
// Check if folder exist and it could be read
|
||||
if (file_exists($upgradePath) && ($files = scandir($upgradePath)))
|
||||
if (file_exists($upgrade_path) && ($files = scandir($upgrade_path)))
|
||||
{
|
||||
// Read each file name
|
||||
foreach ($files as $file)
|
||||
@@ -411,7 +410,7 @@ abstract class ModuleCore
|
||||
version_compare($file_version, $registered_version, '>')))
|
||||
{
|
||||
$list[] = array(
|
||||
'file' => $upgradePath.$file,
|
||||
'file' => $upgrade_path.$file,
|
||||
'version' => $file_version,
|
||||
'upgrade_function' => 'upgrade_module_'.str_replace('.', '_', $file_version));
|
||||
}
|
||||
@@ -421,7 +420,7 @@ abstract class ModuleCore
|
||||
// Set the list to module cache
|
||||
self::$modules_cache[$module_name]['upgrade']['upgrade_file_left'] = $list;
|
||||
self::$modules_cache[$module_name]['upgrade']['available_upgrade'] = count($list);
|
||||
return (bool)(count($list));
|
||||
return (bool)count($list);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -441,7 +440,7 @@ abstract class ModuleCore
|
||||
// Retrieve hooks used by the module
|
||||
$sql = 'SELECT `id_hook` FROM `'._DB_PREFIX_.'hook_module` WHERE `id_module` = '.(int)$this->id;
|
||||
$result = Db::getInstance()->executeS($sql);
|
||||
foreach ($result AS $row)
|
||||
foreach ($result as $row)
|
||||
{
|
||||
$sql = 'DELETE FROM `'._DB_PREFIX_.'hook_module` WHERE `id_module` = '.(int)$this->id.' AND `id_hook` = '.(int)$row['id_hook'];
|
||||
Db::getInstance()->execute($sql);
|
||||
@@ -553,8 +552,9 @@ abstract class ModuleCore
|
||||
*/
|
||||
public function displayFlags($languages, $default_language, $ids, $id, $return = false, $use_vars_instead_of_ids = false)
|
||||
{
|
||||
if (sizeof($languages) == 1)
|
||||
if (count($languages) == 1)
|
||||
return false;
|
||||
|
||||
$output = '
|
||||
<div class="displayed_flag">
|
||||
<img src="../img/l/'.$default_language.'.jpg" class="pointer" id="language_current_'.$id.'" onclick="toggleLanguageFlags(this);" alt="" />
|
||||
@@ -562,10 +562,10 @@ abstract class ModuleCore
|
||||
<div id="languages_'.$id.'" class="language_flags">
|
||||
'.$this->l('Choose language:').'<br /><br />';
|
||||
foreach ($languages as $language)
|
||||
if($use_vars_instead_of_ids)
|
||||
$output .= '<img src="../img/l/'.(int)($language['id_lang']).'.jpg" class="pointer" alt="'.$language['name'].'" title="'.$language['name'].'" onclick="changeLanguage(\''.$id.'\', '.$ids.', '.$language['id_lang'].', \''.$language['iso_code'].'\');" /> ';
|
||||
if ($use_vars_instead_of_ids)
|
||||
$output .= '<img src="../img/l/'.(int)$language['id_lang'].'.jpg" class="pointer" alt="'.$language['name'].'" title="'.$language['name'].'" onclick="changeLanguage(\''.$id.'\', '.$ids.', '.$language['id_lang'].', \''.$language['iso_code'].'\');" /> ';
|
||||
else
|
||||
$output .= '<img src="../img/l/'.(int)($language['id_lang']).'.jpg" class="pointer" alt="'.$language['name'].'" title="'.$language['name'].'" onclick="changeLanguage(\''.$id.'\', \''.$ids.'\', '.$language['id_lang'].', \''.$language['iso_code'].'\');" /> ';
|
||||
$output .= '<img src="../img/l/'.(int)$language['id_lang'].'.jpg" class="pointer" alt="'.$language['name'].'" title="'.$language['name'].'" onclick="changeLanguage(\''.$id.'\', \''.$ids.'\', '.$language['id_lang'].', \''.$language['iso_code'].'\');" /> ';
|
||||
$output .= '</div>';
|
||||
|
||||
if ($return)
|
||||
@@ -577,10 +577,10 @@ abstract class ModuleCore
|
||||
* Connect module to a hook
|
||||
*
|
||||
* @param string $hook_name Hook name
|
||||
* @param array $shopList List of shop linked to the hook (if null, link hook to all shops)
|
||||
* @param array $shop_list List of shop linked to the hook (if null, link hook to all shops)
|
||||
* @return boolean result
|
||||
*/
|
||||
public function registerHook($hook_name, $shopList = null)
|
||||
public function registerHook($hook_name, $shop_list = null)
|
||||
{
|
||||
// Check hook name validation and if module is installed
|
||||
if (!Validate::isHookName($hook_name))
|
||||
@@ -608,24 +608,24 @@ abstract class ModuleCore
|
||||
}
|
||||
|
||||
// If shop lists is null, we fill it with all shops
|
||||
if (is_null($shopList))
|
||||
$shopList = Shop::getShops(true, null, true);
|
||||
if (is_null($shop_list))
|
||||
$shop_list = Shop::getShops(true, null, true);
|
||||
|
||||
$return = true;
|
||||
foreach ($shopList as $shopID)
|
||||
foreach ($shop_list as $shop_id)
|
||||
{
|
||||
// Check if already register
|
||||
$sql = 'SELECT hm.`id_module`
|
||||
FROM `'._DB_PREFIX_.'hook_module` hm, `'._DB_PREFIX_.'hook` h
|
||||
WHERE hm.`id_module` = '.(int)($this->id).' AND h.`id_hook` = '.$id_hook.'
|
||||
AND h.`id_hook` = hm.`id_hook` AND `id_shop` = '.(int)($shopID);
|
||||
AND h.`id_hook` = hm.`id_hook` AND `id_shop` = '.(int)$shop_id;
|
||||
if (Db::getInstance()->getRow($sql))
|
||||
continue;
|
||||
|
||||
// Get module position in hook
|
||||
$sql = 'SELECT MAX(`position`) AS position
|
||||
FROM `'._DB_PREFIX_.'hook_module`
|
||||
WHERE `id_hook` = '.(int)$id_hook.' AND `id_shop` = '.(int)$shopID;
|
||||
WHERE `id_hook` = '.(int)$id_hook.' AND `id_shop` = '.(int)$shop_id;
|
||||
if (!$position = Db::getInstance()->getValue($sql))
|
||||
$position = 0;
|
||||
|
||||
@@ -633,7 +633,7 @@ abstract class ModuleCore
|
||||
$return &= Db::getInstance()->insert('hook_module', array(
|
||||
'id_module' => (int)$this->id,
|
||||
'id_hook' => (int)$id_hook,
|
||||
'id_shop' => (int)$shopID,
|
||||
'id_shop' => (int)$shop_id,
|
||||
'position' => (int)($position + 1),
|
||||
));
|
||||
}
|
||||
@@ -645,10 +645,10 @@ abstract class ModuleCore
|
||||
* Unregister module from hook
|
||||
*
|
||||
* @param mixed $id_hook Hook id (can be a hook name since 1.5.0)
|
||||
* @param array $shopList List of shop
|
||||
* @param array $shop_list List of shop
|
||||
* @return boolean result
|
||||
*/
|
||||
public function unregisterHook($hook_id, $shopList = null)
|
||||
public function unregisterHook($hook_id, $shop_list = null)
|
||||
{
|
||||
// Get hook id if a name is given as argument
|
||||
if (!is_numeric($hook_id))
|
||||
@@ -662,11 +662,11 @@ abstract class ModuleCore
|
||||
// Unregister module on hook by id
|
||||
$sql = 'DELETE FROM `'._DB_PREFIX_.'hook_module`
|
||||
WHERE `id_module` = '.(int)$this->id.' AND `id_hook` = '.(int)$hook_id
|
||||
.(($shopList) ? ' AND `id_shop` IN('.implode(', ', $shopList).')' : '');
|
||||
.(($shop_list) ? ' AND `id_shop` IN('.implode(', ', $shop_list).')' : '');
|
||||
$result = Db::getInstance()->execute($sql);
|
||||
|
||||
// Clean modules position
|
||||
$this->cleanPositions($hook_id, $shopList);
|
||||
$this->cleanPositions($hook_id, $shop_list);
|
||||
|
||||
return $result;
|
||||
}
|
||||
@@ -675,14 +675,14 @@ abstract class ModuleCore
|
||||
* Unregister exceptions linked to module
|
||||
*
|
||||
* @param int $id_hook Hook id
|
||||
* @param array $shopList List of shop
|
||||
* @param array $shop_list List of shop
|
||||
* @return boolean result
|
||||
*/
|
||||
public function unregisterExceptions($hook_id, $shopList = null)
|
||||
public function unregisterExceptions($hook_id, $shop_list = null)
|
||||
{
|
||||
$sql = 'DELETE FROM `'._DB_PREFIX_.'hook_module_exceptions`
|
||||
WHERE `id_module` = '.(int)$this->id.' AND `id_hook` = '.(int)$hook_id
|
||||
.(($shopList) ? ' AND `id_shop` IN('.implode(', ', $shopList).')' : '');
|
||||
.(($shop_list) ? ' AND `id_shop` IN('.implode(', ', $shop_list).')' : '');
|
||||
return Db::getInstance()->execute($sql);
|
||||
}
|
||||
|
||||
@@ -691,26 +691,26 @@ abstract class ModuleCore
|
||||
*
|
||||
* @param int $id_hook Hook id
|
||||
* @param array $excepts List of file name
|
||||
* @param array $shopList List of shop
|
||||
* @param array $shop_list List of shop
|
||||
* @return boolean result
|
||||
*/
|
||||
public function registerExceptions($id_hook, $excepts, $shopList = null)
|
||||
public function registerExceptions($id_hook, $excepts, $shop_list = null)
|
||||
{
|
||||
// If shop lists is null, we fill it with all shops
|
||||
if (is_null($shopList))
|
||||
if (is_null($shop_list))
|
||||
Context::getContext()->shop->getListOfID();
|
||||
|
||||
// Save modules exception for each shop
|
||||
foreach ($shopList as $shopID)
|
||||
foreach ($shop_list as $shop_id)
|
||||
{
|
||||
foreach ($excepts AS $except)
|
||||
foreach ($excepts as $except)
|
||||
{
|
||||
if (!$except)
|
||||
continue;
|
||||
$insertException = array(
|
||||
'id_module' => (int)$this->id,
|
||||
'id_hook' => (int)$id_hook,
|
||||
'id_shop' => (int)$shopID,
|
||||
'id_shop' => (int)$shop_id,
|
||||
'file_name' => pSQL($except),
|
||||
);
|
||||
$result = Db::getInstance()->insert('hook_module_exceptions', $insertException);
|
||||
@@ -731,11 +731,11 @@ abstract class ModuleCore
|
||||
public function editExceptions($id_hook, $excepts)
|
||||
{
|
||||
$result = true;
|
||||
foreach ($excepts as $shopID => $except)
|
||||
foreach ($excepts as $shop_id => $except)
|
||||
{
|
||||
$shopList = ($shopID == 0) ? Context::getContext()->shop->getListOfID() : array($shopID);
|
||||
$this->unregisterExceptions($id_hook, $shopList);
|
||||
$result &= $this->registerExceptions($id_hook, $except, $shopList);
|
||||
$shop_list = ($shop_id == 0) ? Context::getContext()->shop->getListOfID() : array($shop_id);
|
||||
$this->unregisterExceptions($id_hook, $shop_list);
|
||||
$result &= $this->registerExceptions($id_hook, $except, $shop_list);
|
||||
}
|
||||
|
||||
return $result;
|
||||
@@ -763,9 +763,9 @@ abstract class ModuleCore
|
||||
$realpathModuleDir = realpath(_PS_MODULE_DIR_);
|
||||
if (substr(realpath($filePath), 0, strlen($realpathModuleDir)) == $realpathModuleDir)
|
||||
{
|
||||
self::$classInModule[$currentClass] = substr(dirname($filePath), strlen($realpathModuleDir)+1);
|
||||
self::$classInModule[$currentClass] = substr(dirname($filePath), strlen($realpathModuleDir) + 1);
|
||||
$file = _PS_MODULE_DIR_.self::$classInModule[$currentClass].'/'.Context::getContext()->language->iso_code.'.php';
|
||||
if (Tools::file_exists_cache($file) AND include_once($file))
|
||||
if (Tools::file_exists_cache($file) && include_once($file))
|
||||
$_MODULES = !empty($_MODULES) ? array_merge($_MODULES, $_MODULE) : $_MODULE;
|
||||
}
|
||||
else
|
||||
@@ -778,23 +778,23 @@ abstract class ModuleCore
|
||||
/**
|
||||
* Return an instance of the specified module
|
||||
*
|
||||
* @param string $moduleName Module name
|
||||
* @param string $module_name Module name
|
||||
* @return Module
|
||||
*/
|
||||
public static function getInstanceByName($moduleName)
|
||||
public static function getInstanceByName($module_name)
|
||||
{
|
||||
if (!isset(self::$_INSTANCE[$moduleName]))
|
||||
if (!isset(self::$_INSTANCE[$module_name]))
|
||||
{
|
||||
if (Tools::file_exists_cache(_PS_MODULE_DIR_.$moduleName.'/'.$moduleName.'.php'))
|
||||
if (Tools::file_exists_cache(_PS_MODULE_DIR_.$module_name.'/'.$module_name.'.php'))
|
||||
{
|
||||
include_once(_PS_MODULE_DIR_.$moduleName.'/'.$moduleName.'.php');
|
||||
include_once(_PS_MODULE_DIR_.$module_name.'/'.$module_name.'.php');
|
||||
|
||||
if (class_exists($moduleName, false))
|
||||
return self::$_INSTANCE[$moduleName] = new $moduleName;
|
||||
if (class_exists($module_name, false))
|
||||
return self::$_INSTANCE[$module_name] = new $module_name;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return self::$_INSTANCE[$moduleName];
|
||||
return self::$_INSTANCE[$module_name];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -803,7 +803,7 @@ abstract class ModuleCore
|
||||
* @param integer $id_module Module ID
|
||||
* @return Module instance
|
||||
*/
|
||||
static public function getInstanceById($moduleID)
|
||||
public static function getInstanceById($id_module)
|
||||
{
|
||||
static $id2name = null;
|
||||
|
||||
@@ -816,8 +816,8 @@ abstract class ModuleCore
|
||||
$id2name[$row['id_module']] = $row['name'];
|
||||
}
|
||||
|
||||
if (isset($id2name[$moduleID]))
|
||||
return Module::getInstanceByName($id2name[$moduleID]);
|
||||
if (isset($id2name[$id_module]))
|
||||
return Module::getInstanceByName($id2name[$id_module]);
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -838,8 +838,8 @@ abstract class ModuleCore
|
||||
global $_MODULES;
|
||||
|
||||
// Init var
|
||||
$moduleList = array();
|
||||
$moduleNameList = array();
|
||||
$module_list = array();
|
||||
$module_name_list = array();
|
||||
$modulesNameToCursor = array();
|
||||
$errors = array();
|
||||
|
||||
@@ -884,15 +884,15 @@ abstract class ModuleCore
|
||||
if (!count($errors) && (int)$xml_module->need_instance == 0 && !$needNewConfigFile)
|
||||
{
|
||||
$file = _PS_MODULE_DIR_.$module.'/'.Context::getContext()->language->iso_code.'.php';
|
||||
if (Tools::file_exists_cache($file) AND include_once($file))
|
||||
if(isset($_MODULE) AND is_array($_MODULE))
|
||||
if (Tools::file_exists_cache($file) && include_once($file))
|
||||
if (isset($_MODULE) && is_array($_MODULE))
|
||||
$_MODULES = !empty($_MODULES) ? array_merge($_MODULES, $_MODULE) : $_MODULE;
|
||||
|
||||
$item = new stdClass();
|
||||
$item->id = 0;
|
||||
$item->warning = '';
|
||||
foreach ($xml_module as $k => $v)
|
||||
$item->$k = (string) $v;
|
||||
$item->$k = (string)$v;
|
||||
$item->displayName = Module::findTranslation($xml_module->name, Module::configXmlStringFormat($xml_module->displayName), (string)$xml_module->name);
|
||||
$item->description = Module::findTranslation($xml_module->name, Module::configXmlStringFormat($xml_module->description), (string)$xml_module->name);
|
||||
$item->author = Module::findTranslation($xml_module->name, Module::configXmlStringFormat($xml_module->author), (string)$xml_module->name);
|
||||
@@ -901,14 +901,14 @@ abstract class ModuleCore
|
||||
$item->confirmUninstall = Module::findTranslation($xml_module->name, Module::configXmlStringFormat($xml_module->confirmUninstall), (string)$xml_module->name);
|
||||
|
||||
$item->active = 0;
|
||||
$moduleList[] = $item;
|
||||
$moduleNameList[] = '\''.pSQL($item->name).'\'';
|
||||
$module_list[] = $item;
|
||||
$module_name_list[] = '\''.pSQL($item->name).'\'';
|
||||
$modulesNameToCursor[strval($item->name)] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
// If use config flag is at false or config.xml does not exist OR need instance OR need a new config.xml file
|
||||
if (!$useConfig OR !$xml_exist OR (isset($xml_module->need_instance) AND (int)$xml_module->need_instance == 1) OR $needNewConfigFile)
|
||||
if (!$useConfig || !$xml_exist || (isset($xml_module->need_instance) && (int)$xml_module->need_instance == 1) || $needNewConfigFile)
|
||||
{
|
||||
// If class does not exists, we include the file
|
||||
if (!class_exists($module, false))
|
||||
@@ -930,33 +930,33 @@ abstract class ModuleCore
|
||||
}
|
||||
|
||||
// If class exists, we just instanciate it
|
||||
if (class_exists($module,false))
|
||||
if (class_exists($module, false))
|
||||
{
|
||||
$tmpModule = new $module;
|
||||
$tmp_module = new $module;
|
||||
|
||||
$item = new stdClass();
|
||||
$item->id = $tmpModule->id;
|
||||
$item->warning = $tmpModule->warning;
|
||||
$item->name = $tmpModule->name;
|
||||
$item->version = $tmpModule->version;
|
||||
$item->tab = $tmpModule->tab;
|
||||
$item->displayName = $tmpModule->displayName;
|
||||
$item->description = $tmpModule->description;
|
||||
$item->author = $tmpModule->author;
|
||||
$item->limited_countries = $tmpModule->limited_countries;
|
||||
$item->is_configurable = isset($tmpModule->is_configurable) ? $tmpModule->is_configurable : 1;
|
||||
$item->need_instance = isset($tmpModule->need_instance) ? $tmpModule->need_instance : 0;
|
||||
$item->active = $tmpModule->active;
|
||||
$item->currencies = isset($tmpModule->currencies) ? $tmpModule->currencies : null;
|
||||
$item->currencies_mode = isset($tmpModule->currencies_mode) ? $tmpModule->currencies_mode : null;
|
||||
unset($tmpModule);
|
||||
$item->id = $tmp_module->id;
|
||||
$item->warning = $tmp_module->warning;
|
||||
$item->name = $tmp_module->name;
|
||||
$item->version = $tmp_module->version;
|
||||
$item->tab = $tmp_module->tab;
|
||||
$item->displayName = $tmp_module->displayName;
|
||||
$item->description = $tmp_module->description;
|
||||
$item->author = $tmp_module->author;
|
||||
$item->limited_countries = $tmp_module->limited_countries;
|
||||
$item->is_configurable = isset($tmp_module->is_configurable) ? $tmp_module->is_configurable : 1;
|
||||
$item->need_instance = isset($tmp_module->need_instance) ? $tmp_module->need_instance : 0;
|
||||
$item->active = $tmp_module->active;
|
||||
$item->currencies = isset($tmp_module->currencies) ? $tmp_module->currencies : null;
|
||||
$item->currencies_mode = isset($tmp_module->currencies_mode) ? $tmp_module->currencies_mode : null;
|
||||
unset($tmp_module);
|
||||
|
||||
$moduleList[] = $item;
|
||||
if (!$xml_exist OR $needNewConfigFile)
|
||||
$module_list[] = $item;
|
||||
if (!$xml_exist || $needNewConfigFile)
|
||||
{
|
||||
self::$_generate_config_xml_mode = true;
|
||||
$tmpModule = new $module;
|
||||
$tmpModule->_generateConfigXml();
|
||||
$tmp_module = new $module;
|
||||
$tmp_module->_generateConfigXml();
|
||||
self::$_generate_config_xml_mode = false;
|
||||
}
|
||||
}
|
||||
@@ -966,7 +966,7 @@ abstract class ModuleCore
|
||||
}
|
||||
|
||||
// Get modules information from database
|
||||
if (!empty($moduleNameList))
|
||||
if (!empty($module_name_list))
|
||||
{
|
||||
$list = Context::getContext()->shop->getListOfID();
|
||||
|
||||
@@ -974,7 +974,7 @@ abstract class ModuleCore
|
||||
SELECT COUNT(*) FROM '._DB_PREFIX_.'module_shop ms WHERE m.id_module = ms.id_module AND ms.id_shop IN ('.implode(',', $list).')
|
||||
) as total
|
||||
FROM '._DB_PREFIX_.'module m
|
||||
WHERE m.name IN ('.implode(',', $moduleNameList).')';
|
||||
WHERE m.name IN ('.implode(',', $module_name_list).')';
|
||||
$results = Db::getInstance()->executeS($sql);
|
||||
foreach ($results as $result)
|
||||
{
|
||||
@@ -984,30 +984,29 @@ abstract class ModuleCore
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Get Default Country Modules and customer module
|
||||
$filesList = array(
|
||||
$files_list = array(
|
||||
array('type' => 'addonsNative', 'file' => _PS_ROOT_DIR_.'/config/xml/default_country_modules_list.xml', 'loggedOnAddons' => 0),
|
||||
array('type' => 'addonsBought', 'file' => _PS_ROOT_DIR_.'/config/xml/customer_modules_list.xml', 'loggedOnAddons' => 1),
|
||||
);
|
||||
foreach ($filesList as $f)
|
||||
foreach ($files_list as $f)
|
||||
if (file_exists($f['file']) && ($f['loggedOnAddons'] == 0 || $loggedOnAddons))
|
||||
{
|
||||
$file = $f['file'];
|
||||
$content = Tools::file_get_contents($file);
|
||||
$xml = @simplexml_load_string($content, NULL, LIBXML_NOCDATA);
|
||||
$xml = @simplexml_load_string($content, null, LIBXML_NOCDATA);
|
||||
if ($xml && isset($xml->module))
|
||||
foreach ($xml->module as $modaddons)
|
||||
{
|
||||
$flagFound = 0;
|
||||
foreach ($moduleList as $k => $m)
|
||||
$flag_found = 0;
|
||||
foreach ($module_list as $k => $m)
|
||||
if ($m->name == $modaddons->name && !isset($m->available_on_addons))
|
||||
{
|
||||
$flagFound = 1;
|
||||
$flag_found = 1;
|
||||
if ($m->version != $modaddons->version && version_compare($m->version, $modaddons->version) === -1)
|
||||
$moduleList[$k]->version_addons = $modaddons->version;
|
||||
$module_list[$k]->version_addons = $modaddons->version;
|
||||
}
|
||||
if ($flagFound == 0)
|
||||
if ($flag_found == 0)
|
||||
{
|
||||
$item = new stdClass();
|
||||
$item->id = 0;
|
||||
@@ -1032,34 +1031,28 @@ abstract class ModuleCore
|
||||
if (file_exists('../img/tmp/'.md5($modaddons->name).'.jpg'))
|
||||
$item->image = '../img/tmp/'.md5($modaddons->name).'.jpg';
|
||||
}
|
||||
$moduleList[] = $item;
|
||||
$module_list[] = $item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//echo round($current_memory / 1024 / 1024, 2).'Mo<br />';
|
||||
|
||||
// @TODO review
|
||||
function sortModules($a, $b)
|
||||
{
|
||||
usort($module_list, create_function('$a,$b', '
|
||||
if ($a->displayName == $b->displayName)
|
||||
return 0;
|
||||
return ($a->displayName < $b->displayName) ? -1 : 1;
|
||||
}
|
||||
usort($moduleList, "sortModules");
|
||||
'));
|
||||
|
||||
if ($errors)
|
||||
{
|
||||
echo '<div class="alert error"><h3>'.Tools::displayError('The following module(s) couldn\'t be loaded').':</h3><ol>';
|
||||
foreach ($errors AS $error)
|
||||
foreach ($errors as $error)
|
||||
echo '<li>'.$error.'</li>';
|
||||
echo '</ol></div>';
|
||||
}
|
||||
|
||||
return $moduleList;
|
||||
return $module_list;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return modules directory list
|
||||
*
|
||||
@@ -1067,18 +1060,18 @@ abstract class ModuleCore
|
||||
*/
|
||||
public static function getModulesDirOnDisk()
|
||||
{
|
||||
$moduleList = array();
|
||||
$module_list = array();
|
||||
$modules = scandir(_PS_MODULE_DIR_);
|
||||
foreach ($modules AS $name)
|
||||
foreach ($modules as $name)
|
||||
{
|
||||
if (is_dir(_PS_MODULE_DIR_.$name) && Tools::file_exists_cache(_PS_MODULE_DIR_.$name.'/'.$name.'.php'))
|
||||
{
|
||||
if (!Validate::isModuleName($name))
|
||||
throw new PrestaShopException(sprintf('Module %s is not a valid module name', $name));
|
||||
$moduleList[] = $name;
|
||||
$module_list[] = $name;
|
||||
}
|
||||
}
|
||||
return $moduleList;
|
||||
return $module_list;
|
||||
}
|
||||
|
||||
|
||||
@@ -1093,17 +1086,17 @@ abstract class ModuleCore
|
||||
$db = Db::getInstance();
|
||||
|
||||
$module_list_xml = _PS_ROOT_DIR_.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'xml'.DIRECTORY_SEPARATOR.'modules_list.xml';
|
||||
$nativeModules = simplexml_load_file($module_list_xml);
|
||||
$nativeModules = $nativeModules->modules;
|
||||
foreach ($nativeModules as $nativeModulesType)
|
||||
if (in_array($nativeModulesType['type'],array('native','partner')))
|
||||
$native_modules = simplexml_load_file($module_list_xml);
|
||||
$native_modules = $native_modules->modules;
|
||||
foreach ($native_modules as $native_modules_type)
|
||||
if (in_array($native_modules_type['type'], array('native', 'partner')))
|
||||
{
|
||||
$arrNativeModules[] = '""';
|
||||
foreach ($nativeModulesType->module as $module)
|
||||
$arrNativeModules[] = '"'.pSQL($module['name']).'"';
|
||||
$arr_native_modules[] = '""';
|
||||
foreach ($native_modules_type->module as $module)
|
||||
$arr_native_modules[] = '"'.pSQL($module['name']).'"';
|
||||
}
|
||||
|
||||
return $db->executeS('SELECT * FROM `'._DB_PREFIX_.'module` m WHERE `name` NOT IN ('.implode(',',$arrNativeModules).') ');
|
||||
return $db->executeS('SELECT * FROM `'._DB_PREFIX_.'module` m WHERE `name` NOT IN ('.implode(',', $arr_native_modules).') ');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1130,7 +1123,7 @@ abstract class ModuleCore
|
||||
* @param array $hookArgs Parameters for the functions
|
||||
* @return string modules output
|
||||
*/
|
||||
public static function hookExec($hook_name, $hookArgs = array(), $id_module = NULL)
|
||||
public static function hookExec($hook_name, $hookArgs = array(), $id_module = null)
|
||||
{
|
||||
Tools::displayAsDeprecated();
|
||||
return Hook::exec($hook_name, $hookArgs, $id_module);
|
||||
@@ -1142,14 +1135,11 @@ abstract class ModuleCore
|
||||
return Hook::exec('displayPayment');
|
||||
}
|
||||
|
||||
|
||||
public static function preCall($moduleName)
|
||||
public static function preCall($module_name)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns the list of the payment module associated to the current customer
|
||||
* @see PaymentModule::getInstalledPaymentModules() if you don't care about the context
|
||||
@@ -1176,7 +1166,7 @@ abstract class ModuleCore
|
||||
LEFT JOIN `'._DB_PREFIX_.'hook_module` hm ON hm.`id_module` = m.`id_module`
|
||||
LEFT JOIN `'._DB_PREFIX_.'hook` h ON hm.`id_hook` = h.`id_hook`
|
||||
WHERE h.`name` = \''.pSQL($hookPayment).'\'
|
||||
AND mc.id_country = '.(int)($billing->id_country).'
|
||||
AND mc.id_country = '.(int)$billing->id_country.'
|
||||
AND mc.id_shop = '.(int)$context->shop->getID(true).'
|
||||
AND mg.id_shop = '.(int)$context->shop->getID(true).'
|
||||
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).'
|
||||
@@ -1202,7 +1192,7 @@ abstract class ModuleCore
|
||||
{
|
||||
global $_MODULES;
|
||||
|
||||
$cache_key = $name . '|' . $string . '|' . $source;
|
||||
$cache_key = $name.'|'.$string.'|'.$source;
|
||||
|
||||
if (!isset(self::$l_cache[$cache_key]))
|
||||
{
|
||||
@@ -1250,7 +1240,7 @@ abstract class ModuleCore
|
||||
$id_lang = Context::getContext()->language->id;
|
||||
$file = _PS_MODULE_DIR_.$this->name.'/'.Context::getContext()->language->iso_code.'.php';
|
||||
|
||||
if (Tools::file_exists_cache($file) AND include_once($file))
|
||||
if (Tools::file_exists_cache($file) && include_once($file))
|
||||
$_MODULES = !empty($_MODULES) ? array_merge($_MODULES, $_MODULE) : $_MODULE;
|
||||
|
||||
$source = $specific ? $specific : $this->name;
|
||||
@@ -1266,42 +1256,42 @@ abstract class ModuleCore
|
||||
* @param boolean $way Up (1) or Down (0)
|
||||
* @param int $position
|
||||
*/
|
||||
public function updatePosition($id_hook, $way, $position = NULL)
|
||||
public function updatePosition($id_hook, $way, $position = null)
|
||||
{
|
||||
foreach ($this->context->shop->getListOfID() as $shopID)
|
||||
foreach ($this->context->shop->getListOfID() as $shop_id)
|
||||
{
|
||||
$sql = 'SELECT hm.`id_module`, hm.`position`, hm.`id_hook`
|
||||
FROM `'._DB_PREFIX_.'hook_module` hm
|
||||
WHERE hm.`id_hook` = '.(int)$id_hook.' AND hm.`id_shop` = '.$shopID.'
|
||||
WHERE hm.`id_hook` = '.(int)$id_hook.' AND hm.`id_shop` = '.$shop_id.'
|
||||
ORDER BY hm.`position` '.($way ? 'ASC' : 'DESC');
|
||||
if (!$res = Db::getInstance()->executeS($sql))
|
||||
continue;
|
||||
|
||||
foreach ($res AS $key => $values)
|
||||
if ((int)($values[$this->identifier]) == (int)($this->id))
|
||||
foreach ($res as $key => $values)
|
||||
if ((int)$values[$this->identifier] == (int)$this->id)
|
||||
{
|
||||
$k = $key ;
|
||||
break ;
|
||||
$k = $key;
|
||||
break;
|
||||
}
|
||||
if (!isset($k) OR !isset($res[$k]) OR !isset($res[$k + 1]))
|
||||
if (!isset($k) || !isset($res[$k]) || !isset($res[$k + 1]))
|
||||
return false;
|
||||
$from = $res[$k];
|
||||
$to = $res[$k + 1];
|
||||
|
||||
if (isset($position) and !empty($position))
|
||||
$to['position'] = (int)($position);
|
||||
if (isset($position) && !empty($position))
|
||||
$to['position'] = (int)$position;
|
||||
|
||||
$sql = 'UPDATE `'._DB_PREFIX_.'hook_module`
|
||||
SET `position`= position '.($way ? '-1' : '+1').'
|
||||
WHERE position between '.(int)(min(array($from['position'], $to['position']))) .' AND '.(int)(max(array($from['position'], $to['position']))).'
|
||||
AND `id_hook` = '.(int)$from['id_hook'].' AND `id_shop` = '.$shopID;
|
||||
WHERE position between '.(int)(min(array($from['position'], $to['position']))).' AND '.max(array($from['position'], $to['position'])).'
|
||||
AND `id_hook` = '.(int)$from['id_hook'].' AND `id_shop` = '.$shop_id;
|
||||
if (!Db::getInstance()->execute($sql))
|
||||
return false;
|
||||
|
||||
$sql = 'UPDATE `'._DB_PREFIX_.'hook_module`
|
||||
SET `position`='.(int)($to['position']).'
|
||||
WHERE `'.pSQL($this->identifier).'` = '.(int)($from[$this->identifier]).'
|
||||
AND `id_hook` = '.(int)($to['id_hook']).' AND `id_shop` = '.$shopID;
|
||||
SET `position`='.(int)$to['position'].'
|
||||
WHERE `'.pSQL($this->identifier).'` = '.(int)$from[$this->identifier].'
|
||||
AND `id_hook` = '.(int)$to['id_hook'].' AND `id_shop` = '.$shop_id;
|
||||
if (!Db::getInstance()->execute($sql))
|
||||
return false;
|
||||
}
|
||||
@@ -1311,14 +1301,14 @@ abstract class ModuleCore
|
||||
* Reorder modules position
|
||||
*
|
||||
* @param boolean $id_hook Hook ID
|
||||
* @param array $shopList List of shop
|
||||
* @param array $shop_list List of shop
|
||||
*/
|
||||
public function cleanPositions($id_hook, $shopList = null)
|
||||
public function cleanPositions($id_hook, $shop_list = null)
|
||||
{
|
||||
$sql = 'SELECT `id_module`, `id_shop`
|
||||
FROM `'._DB_PREFIX_.'hook_module`
|
||||
WHERE `id_hook` = '.(int)$id_hook.'
|
||||
'.((!is_null($shopList) && $shopList) ? ' AND `id_shop` IN('.implode(', ', $shopList).')' : '').'
|
||||
'.((!is_null($shop_list) && $shop_list) ? ' AND `id_shop` IN('.implode(', ', $shop_list).')' : '').'
|
||||
ORDER BY `position`';
|
||||
$results = Db::getInstance()->executeS($sql);
|
||||
$position = array();
|
||||
@@ -1363,7 +1353,7 @@ abstract class ModuleCore
|
||||
* @param int $id_hook Hook ID
|
||||
* @return array Exceptions
|
||||
*/
|
||||
protected static $exceptionsCache = NULL;
|
||||
protected static $exceptionsCache = null;
|
||||
public function getExceptions($hookID, $dispatch = false)
|
||||
{
|
||||
if (is_null(self::$exceptionsCache))
|
||||
@@ -1376,7 +1366,7 @@ abstract class ModuleCore
|
||||
{
|
||||
if (!$row['file_name'])
|
||||
continue;
|
||||
$key = $row['id_hook'] . '-' . $row['id_module'];
|
||||
$key = $row['id_hook'].'-'.$row['id_module'];
|
||||
if (!isset(self::$exceptionsCache[$key]))
|
||||
self::$exceptionsCache[$key] = array();
|
||||
if (!isset(self::$exceptionsCache[$key][$row['id_shop']]))
|
||||
@@ -1389,9 +1379,9 @@ abstract class ModuleCore
|
||||
if (!$dispatch)
|
||||
{
|
||||
$files = array();
|
||||
foreach (Context::getContext()->shop->getListOfID() as $shopID)
|
||||
if (isset(self::$exceptionsCache[$key], self::$exceptionsCache[$key][$shopID]))
|
||||
foreach (self::$exceptionsCache[$key][$shopID] as $file)
|
||||
foreach (Context::getContext()->shop->getListOfID() 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;
|
||||
@@ -1399,16 +1389,16 @@ abstract class ModuleCore
|
||||
else
|
||||
{
|
||||
$list = array();
|
||||
foreach (Context::getContext()->shop->getListOfID() as $shopID)
|
||||
if (isset(self::$exceptionsCache[$key], self::$exceptionsCache[$key][$shopID]))
|
||||
$list[$shopID] = self::$exceptionsCache[$key][$shopID];
|
||||
foreach (Context::getContext()->shop->getListOfID() as $shop_id)
|
||||
if (isset(self::$exceptionsCache[$key], self::$exceptionsCache[$key][$shop_id]))
|
||||
$list[$shop_id] = self::$exceptionsCache[$key][$shop_id];
|
||||
return $list;
|
||||
}
|
||||
}
|
||||
|
||||
public static function isInstalled($moduleName)
|
||||
public static function isInstalled($module_name)
|
||||
{
|
||||
Db::getInstance()->executeS('SELECT `id_module` FROM `'._DB_PREFIX_.'module` WHERE `name` = \''.pSQL($moduleName).'\'');
|
||||
Db::getInstance()->executeS('SELECT `id_module` FROM `'._DB_PREFIX_.'module` WHERE `name` = \''.pSQL($module_name).'\'');
|
||||
return (bool)Db::getInstance()->NumRows();
|
||||
}
|
||||
|
||||
@@ -1420,20 +1410,20 @@ abstract class ModuleCore
|
||||
$sql = 'SELECT COUNT(*)
|
||||
FROM `'._DB_PREFIX_.'hook_module` hm
|
||||
LEFT JOIN `'._DB_PREFIX_.'hook` h ON (h.`id_hook` = hm.`id_hook`)
|
||||
WHERE h.`name` = \''.pSQL($hook).'\' AND hm.`id_module` = '.(int)($this->id);
|
||||
WHERE h.`name` = \''.pSQL($hook).'\' AND hm.`id_module` = '.(int)$this->id;
|
||||
return Db::getInstance()->getValue($sql);
|
||||
}
|
||||
|
||||
/*
|
||||
** Template management (display, overload, cache)
|
||||
*/
|
||||
protected static function _isTemplateOverloadedStatic($moduleName, $template)
|
||||
protected static function _isTemplateOverloadedStatic($module_name, $template)
|
||||
{
|
||||
if (Tools::file_exists_cache(_PS_THEME_DIR_.'modules/'.$moduleName.'/'.$template))
|
||||
if (Tools::file_exists_cache(_PS_THEME_DIR_.'modules/'.$module_name.'/'.$template))
|
||||
return true;
|
||||
elseif (Tools::file_exists_cache(_PS_MODULE_DIR_.$moduleName.'/'.$template))
|
||||
elseif (Tools::file_exists_cache(_PS_MODULE_DIR_.$module_name.'/'.$template))
|
||||
return false;
|
||||
return NULL;
|
||||
return null;
|
||||
}
|
||||
|
||||
protected function _isTemplateOverloaded($template)
|
||||
@@ -1444,7 +1434,7 @@ abstract class ModuleCore
|
||||
public function display($file, $template, $cacheId = null, $compileId = null)
|
||||
{
|
||||
if (($overloaded = Module::_isTemplateOverloadedStatic(basename($file, '.php'), $template)) === null)
|
||||
$result = Tools::displayError('No template found for module').' '.basename($file,'.php');
|
||||
$result = Tools::displayError('No template found for module').' '.basename($file, '.php');
|
||||
else
|
||||
{
|
||||
$this->smarty->assign(array(
|
||||
@@ -1484,14 +1474,14 @@ abstract class ModuleCore
|
||||
return $this->_isTemplateOverloaded($template) ? _PS_THEME_DIR_ : _PS_MODULE_DIR_.$this->name.'/';
|
||||
}
|
||||
|
||||
public function isCached($template, $cacheId = NULL, $compileId = NULL)
|
||||
public function isCached($template, $cacheId = null, $compileId = null)
|
||||
{
|
||||
$context = Context::getContext();
|
||||
|
||||
return $context->smarty->isCached($this->_getApplicableTemplateDir($template).$template, $cacheId, $compileId);
|
||||
}
|
||||
|
||||
protected function _clearCache($template, $cacheId = NULL, $compileId = NULL)
|
||||
protected function _clearCache($template, $cacheId = null, $compileId = null)
|
||||
{
|
||||
Tools::clearCache(Context::getContext()->smarty);
|
||||
}
|
||||
@@ -1507,7 +1497,7 @@ abstract class ModuleCore
|
||||
<author><![CDATA['.Tools::htmlentitiesUTF8($this->author).']]></author>
|
||||
<tab><![CDATA['.Tools::htmlentitiesUTF8($this->tab).']]></tab>'.(isset($this->confirmUninstall) ? "\n\t".'<confirmUninstall>'.$this->confirmUninstall.'</confirmUninstall>' : '').'
|
||||
<is_configurable>'.(int)method_exists($this, 'getContent').'</is_configurable>
|
||||
<need_instance>'.(int)$this->need_instance.'</need_instance>'.(isset($this->limited_countries) ? "\n\t".'<limited_countries>'.(sizeof($this->limited_countries) == 1 ? $this->limited_countries[0] : '').'</limited_countries>' : '').'
|
||||
<need_instance>'.(int)$this->need_instance.'</need_instance>'.(isset($this->limited_countries) ? "\n\t".'<limited_countries>'.(count($this->limited_countries) == 1 ? $this->limited_countries[0] : '').'</limited_countries>' : '').'
|
||||
</module>';
|
||||
if (is_writable(_PS_MODULE_DIR_.$this->name.'/'))
|
||||
file_put_contents(_PS_MODULE_DIR_.$this->name.'/config.xml', $xml);
|
||||
@@ -1574,7 +1564,7 @@ abstract class ModuleCore
|
||||
return Db::getInstance()->executeS('
|
||||
SELECT m.`id_module`, m.`name` FROM `'._DB_PREFIX_.'module_group` mg
|
||||
LEFT JOIN `'._DB_PREFIX_.'module` m ON (m.`id_module` = mg.`id_module`)
|
||||
WHERE mg.`id_group` = '.(int) $group_id);
|
||||
WHERE mg.`id_group` = '.(int)$group_id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+35
-33
@@ -36,7 +36,7 @@ abstract class ModuleGraphCore extends Module
|
||||
protected $_legend = array();
|
||||
|
||||
/**@var string graph titles */
|
||||
protected $_titles = array('main' => NULL, 'x' => NULL, 'y' => NULL);
|
||||
protected $_titles = array('main' => null, 'x' => null, 'y' => null);
|
||||
|
||||
/** @var ModuleGraphEngine graph engine */
|
||||
protected $_render;
|
||||
@@ -45,7 +45,7 @@ abstract class ModuleGraphCore extends Module
|
||||
|
||||
public function setEmployee($id_employee)
|
||||
{
|
||||
$this->_employee = new Employee((int)($id_employee));
|
||||
$this->_employee = new Employee($id_employee);
|
||||
}
|
||||
|
||||
public function setLang($id_lang)
|
||||
@@ -56,8 +56,8 @@ abstract class ModuleGraphCore extends Module
|
||||
protected function setDateGraph($layers, $legend = false)
|
||||
{
|
||||
// Get dates in a manageable format
|
||||
$fromArray = getdate(strtotime($this->_employee->stats_date_from));
|
||||
$toArray = getdate(strtotime($this->_employee->stats_date_to));
|
||||
$from_array = getdate(strtotime($this->_employee->stats_date_from));
|
||||
$to_array = getdate(strtotime($this->_employee->stats_date_to));
|
||||
|
||||
// If the granularity is inferior to 1 day
|
||||
if ($this->_employee->stats_date_from == $this->_employee->stats_date_to)
|
||||
@@ -81,15 +81,15 @@ abstract class ModuleGraphCore extends Module
|
||||
if ($legend)
|
||||
{
|
||||
$days = array();
|
||||
if ($fromArray['mon'] == $toArray['mon'])
|
||||
for ($i = $fromArray['mday']; $i <= $toArray['mday']; ++$i)
|
||||
if ($from_array['mon'] == $to_array['mon'])
|
||||
for ($i = $from_array['mday']; $i <= $to_array['mday']; ++$i)
|
||||
$days[] = $i;
|
||||
else
|
||||
{
|
||||
$imax = date('t', mktime(0, 0, 0, $fromArray['mon'], 1, $fromArray['year']));
|
||||
for ($i = $fromArray['mday']; $i <= $imax; ++$i)
|
||||
$imax = date('t', mktime(0, 0, 0, $from_array['mon'], 1, $from_array['year']));
|
||||
for ($i = $from_array['mday']; $i <= $imax; ++$i)
|
||||
$days[] = $i;
|
||||
for ($i = 1; $i <= $toArray['mday']; ++$i)
|
||||
for ($i = 1; $i <= $to_array['mday']; ++$i)
|
||||
$days[] = $i;
|
||||
}
|
||||
foreach ($days as $i)
|
||||
@@ -111,14 +111,14 @@ abstract class ModuleGraphCore extends Module
|
||||
if ($legend)
|
||||
{
|
||||
$months = array();
|
||||
if ($fromArray['year'] == $toArray['year'])
|
||||
for ($i = $fromArray['mon']; $i <= $toArray['mon']; ++$i)
|
||||
if ($from_array['year'] == $to_array['year'])
|
||||
for ($i = $from_array['mon']; $i <= $to_array['mon']; ++$i)
|
||||
$months[] = $i;
|
||||
else
|
||||
{
|
||||
for ($i = $fromArray['mon']; $i <= 12; ++$i)
|
||||
for ($i = $from_array['mon']; $i <= 12; ++$i)
|
||||
$months[] = $i;
|
||||
for ($i = 1; $i <= $toArray['mon']; ++$i)
|
||||
for ($i = 1; $i <= $to_array['mon']; ++$i)
|
||||
$months[] = $i;
|
||||
}
|
||||
foreach ($months as $i)
|
||||
@@ -140,7 +140,7 @@ abstract class ModuleGraphCore extends Module
|
||||
if ($legend)
|
||||
{
|
||||
$years = array();
|
||||
for ($i = $fromArray['year']; $i <= $toArray['year']; ++$i)
|
||||
for ($i = $from_array['year']; $i <= $to_array['year']; ++$i)
|
||||
$years[] = $i;
|
||||
foreach ($years as $i)
|
||||
{
|
||||
@@ -172,9 +172,9 @@ abstract class ModuleGraphCore extends Module
|
||||
// @todo use native CSV PHP functions ?
|
||||
// Generate first line (column titles)
|
||||
if (is_array($this->_titles['main']))
|
||||
for ($i = 0; $i <= sizeof($this->_titles['main']); $i++)
|
||||
for ($i = 0, $total_main = count($this->_titles['main']); $i <= $total_main; $i++)
|
||||
{
|
||||
if($i > 0)
|
||||
if ($i > 0)
|
||||
$this->_csv .= ';';
|
||||
if (isset($this->_titles['main'][$i]))
|
||||
$this->_csv .= $this->_titles['main'][$i];
|
||||
@@ -182,17 +182,17 @@ abstract class ModuleGraphCore extends Module
|
||||
else // If there is only one column title, there is in fast two column (the first without title)
|
||||
$this->_csv .= ';'.$this->_titles['main'];
|
||||
$this->_csv .= "\n";
|
||||
if (sizeof($this->_legend))
|
||||
if (count($this->_legend))
|
||||
{
|
||||
$total = 0;
|
||||
if ($datas['type'] == 'pie')
|
||||
foreach ($this->_legend AS $key => $legend)
|
||||
for ($i = 0; $i < (is_array($this->_titles['main']) ? sizeof($this->_values) : 1); ++$i)
|
||||
foreach ($this->_legend as $key => $legend)
|
||||
for ($i = 0, $total_main = (is_array($this->_titles['main']) ? count($this->_values) : 1); $i < $total_main; ++$i)
|
||||
$total += (is_array($this->_values[$i]) ? $this->_values[$i][$key] : $this->_values[$key]);
|
||||
foreach ($this->_legend AS $key => $legend)
|
||||
foreach ($this->_legend as $key => $legend)
|
||||
{
|
||||
$this->_csv .= $legend.';';
|
||||
for ($i = 0; $i < (is_array($this->_titles['main']) ? sizeof($this->_values) : 1); ++$i)
|
||||
for ($i = 0, $total_main = (is_array($this->_titles['main']) ? count($this->_values) : 1); $i < $total_main; ++$i)
|
||||
{
|
||||
if (!isset($this->_values[$i]) || !is_array($this->_values[$i]))
|
||||
if (isset($this->_values[$key]))
|
||||
@@ -202,7 +202,8 @@ abstract class ModuleGraphCore extends Module
|
||||
$this->_csv .= $this->_values[$key] / (($datas['type'] == 'pie') ? $total : 1);
|
||||
else
|
||||
$this->_csv .= $this->_values[$key];
|
||||
}else
|
||||
}
|
||||
else
|
||||
$this->_csv .= '0';
|
||||
else
|
||||
{
|
||||
@@ -263,8 +264,8 @@ abstract class ModuleGraphCore extends Module
|
||||
if (!file_exists(dirname(__FILE__).'/../modules/'.$render.'/'.$render.'.php'))
|
||||
return Tools::displayError('Graph engine selected is unavailable.');
|
||||
|
||||
$id_employee = (int)($context->employee->id);
|
||||
$id_lang = (int)($context->language->id);
|
||||
$id_employee = (int)$context->employee->id;
|
||||
$id_lang = (int)$context->language->id;
|
||||
|
||||
if (!isset($params['layers']))
|
||||
$params['layers'] = 1;
|
||||
@@ -275,12 +276,12 @@ abstract class ModuleGraphCore extends Module
|
||||
if (!isset($params['height']))
|
||||
$params['height'] = 270;
|
||||
|
||||
$urlParams = $params;
|
||||
$urlParams['render'] = $render;
|
||||
$urlParams['module'] = Tools::getValue('module');
|
||||
$urlParams['id_employee'] = $id_employee;
|
||||
$urlParams['id_lang'] = $id_lang;
|
||||
$drawer = 'drawer.php?' . http_build_query(array_map('Tools::safeOutput', $urlParams));
|
||||
$url_params = $params;
|
||||
$url_params['render'] = $render;
|
||||
$url_params['module'] = Tools::getValue('module');
|
||||
$url_params['id_employee'] = $id_employee;
|
||||
$url_params['id_lang'] = $id_lang;
|
||||
$drawer = 'drawer.php?'.http_build_query(array_map('Tools::safeOutput', $url_params));
|
||||
|
||||
require_once(dirname(__FILE__).'/../modules/'.$render.'/'.$render.'.php');
|
||||
return call_user_func(array($render, 'hookGraphEngine'), $params, $drawer);
|
||||
@@ -293,11 +294,12 @@ abstract class ModuleGraphCore extends Module
|
||||
if (!$employee)
|
||||
$employee = $context->employee;
|
||||
|
||||
if (empty($employee->stats_date_from) OR empty($employee->stats_date_to) OR $employee->stats_date_from == '0000-00-00' OR $employee->stats_date_to == '0000-00-00')
|
||||
if (empty($employee->stats_date_from) || empty($employee->stats_date_to)
|
||||
|| $employee->stats_date_from == '0000-00-00' || $employee->stats_date_to == '0000-00-00')
|
||||
{
|
||||
if (empty($employee->stats_date_from) OR $employee->stats_date_from == '0000-00-00')
|
||||
if (empty($employee->stats_date_from) || $employee->stats_date_from == '0000-00-00')
|
||||
$employee->stats_date_from = date('Y').'-01-01';
|
||||
if (empty($employee->stats_date_to) OR $employee->stats_date_to == '0000-00-00')
|
||||
if (empty($employee->stats_date_to) || $employee->stats_date_to == '0000-00-00')
|
||||
$employee->stats_date_to = date('Y').'-12-31';
|
||||
$employee->update();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2011 PrestaShop
|
||||
* 2007-2011 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
|
||||
+38
-41
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2011 PrestaShop
|
||||
* 2007-2011 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
@@ -28,57 +28,55 @@
|
||||
abstract class ModuleGridCore extends Module
|
||||
{
|
||||
protected $_employee;
|
||||
|
||||
|
||||
/** @var string array graph data */
|
||||
protected $_values = array();
|
||||
|
||||
|
||||
/** @var integer total number of values **/
|
||||
protected $_totalCount = 0;
|
||||
|
||||
|
||||
/**@var string graph titles */
|
||||
protected $_title;
|
||||
|
||||
|
||||
/**@var integer start */
|
||||
protected $_start;
|
||||
|
||||
|
||||
/**@var integer limit */
|
||||
protected $_limit;
|
||||
|
||||
|
||||
/**@var string column name on which to sort */
|
||||
protected $_sort = null;
|
||||
|
||||
|
||||
/**@var string sort direction DESC/ASC */
|
||||
protected $_direction = null;
|
||||
|
||||
/** @var ModuleGridEngine grid engine */
|
||||
protected $_render;
|
||||
|
||||
public function install()
|
||||
{
|
||||
return (parent::install());
|
||||
}
|
||||
|
||||
abstract protected function getData();
|
||||
|
||||
public function setEmployee($id_employee)
|
||||
{
|
||||
$this->_employee = new Employee((int)($id_employee));
|
||||
$this->_employee = new Employee($id_employee);
|
||||
}
|
||||
|
||||
public function setLang($id_lang)
|
||||
{
|
||||
$this->_id_lang = $id_lang;
|
||||
}
|
||||
|
||||
|
||||
public function create($render, $type, $width, $height, $start, $limit, $sort, $dir)
|
||||
{
|
||||
if (!Tools::file_exists_cache($file = dirname(__FILE__).'/../modules/'.$render.'/'.$render.'.php'))
|
||||
die(Tools::displayError());
|
||||
require_once($file);
|
||||
$this->_render = new $render($type);
|
||||
|
||||
|
||||
$this->_start = $start;
|
||||
$this->_limit = $limit;
|
||||
$this->_sort = $sort;
|
||||
$this->_direction = $dir;
|
||||
|
||||
|
||||
$this->getData();
|
||||
|
||||
$this->_render->setTitle($this->_title);
|
||||
@@ -87,32 +85,32 @@ abstract class ModuleGridCore extends Module
|
||||
$this->_render->setTotalCount($this->_totalCount);
|
||||
$this->_render->setLimit($this->_start, $this->_limit);
|
||||
}
|
||||
|
||||
|
||||
public function render()
|
||||
{
|
||||
$this->_render->render();
|
||||
}
|
||||
|
||||
|
||||
public function engine($params)
|
||||
{
|
||||
if (!($render = Configuration::get('PS_STATS_GRID_RENDER')))
|
||||
return Tools::displayError('No grid engine selected');
|
||||
if (!file_exists(dirname(__FILE__).'/../modules/'.$render.'/'.$render.'.php'))
|
||||
return Tools::displayError('Grid engine selected is unavailable.');
|
||||
|
||||
|
||||
$grider = 'grider.php?render='.$render.'&module='.Tools::safeOutput(Tools::getValue('module'));
|
||||
|
||||
|
||||
$context = Context::getContext();
|
||||
$grider .= '&id_employee='.(int)($context->employee->id);
|
||||
$grider .= '&id_lang='.(int)($context->language->id);
|
||||
|
||||
if (!isset($params['width']) OR !Validate::IsUnsignedInt($params['width']))
|
||||
$grider .= '&id_employee='.(int)$context->employee->id;
|
||||
$grider .= '&id_lang='.(int)$context->language->id;
|
||||
|
||||
if (!isset($params['width']) || !Validate::IsUnsignedInt($params['width']))
|
||||
$params['width'] = 600;
|
||||
if (!isset($params['height']) OR !Validate::IsUnsignedInt($params['height']))
|
||||
if (!isset($params['height']) || !Validate::IsUnsignedInt($params['height']))
|
||||
$params['height'] = 920;
|
||||
if (!isset($params['start']) OR !Validate::IsUnsignedInt($params['start']))
|
||||
if (!isset($params['start']) || !Validate::IsUnsignedInt($params['start']))
|
||||
$params['start'] = 0;
|
||||
if (!isset($params['limit']) OR !Validate::IsUnsignedInt($params['limit']))
|
||||
if (!isset($params['limit']) || !Validate::IsUnsignedInt($params['limit']))
|
||||
$params['limit'] = 40;
|
||||
|
||||
$grider .= '&width='.$params['width'];
|
||||
@@ -129,11 +127,11 @@ abstract class ModuleGridCore extends Module
|
||||
$grider .= '&sort='.$params['sort'];
|
||||
if (isset($params['dir']) && Validate::isSortDirection($params['dir']))
|
||||
$grider .= '&dir='.$params['dir'];
|
||||
|
||||
|
||||
require_once(dirname(__FILE__).'/../modules/'.$render.'/'.$render.'.php');
|
||||
return call_user_func(array($render, 'hookGridEngine'), $params, $grider);
|
||||
}
|
||||
|
||||
|
||||
protected function csvExport($datas)
|
||||
{
|
||||
$this->_sort = $datas['defaultSortColumn'];
|
||||
@@ -144,23 +142,23 @@ abstract class ModuleGridCore extends Module
|
||||
|
||||
if (isset($datas['option']))
|
||||
$this->setOption($datas['option'], $layers);
|
||||
|
||||
if (sizeof($datas['columns']))
|
||||
|
||||
if (count($datas['columns']))
|
||||
{
|
||||
foreach ($datas['columns'] AS $column)
|
||||
foreach ($datas['columns'] as $column)
|
||||
$this->_csv .= $column['header'].';';
|
||||
$this->_csv = rtrim($this->_csv, ';')."\n";
|
||||
|
||||
foreach ($this->_values AS $value)
|
||||
|
||||
foreach ($this->_values as $value)
|
||||
{
|
||||
foreach ($datas['columns'] AS $column)
|
||||
foreach ($datas['columns'] as $column)
|
||||
$this->_csv .= $value[$column['dataIndex']].';';
|
||||
$this->_csv = rtrim($this->_csv, ';')."\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->_displayCsv();
|
||||
}
|
||||
|
||||
|
||||
protected function _displayCsv()
|
||||
{
|
||||
ob_end_clean();
|
||||
@@ -169,13 +167,12 @@ abstract class ModuleGridCore extends Module
|
||||
echo $this->_csv;
|
||||
exit;
|
||||
}
|
||||
|
||||
abstract protected function getData();
|
||||
|
||||
|
||||
public function getDate()
|
||||
{
|
||||
return ModuleGraph::getDateBetween($this->_employee);
|
||||
}
|
||||
|
||||
public function getLang()
|
||||
{
|
||||
return $this->_id_lang;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2011 PrestaShop
|
||||
* 2007-2011 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
|
||||
+11
-13
@@ -43,7 +43,7 @@ class NotificationCore
|
||||
public function getLastElements()
|
||||
{
|
||||
global $cookie;
|
||||
|
||||
|
||||
$notifications = array();
|
||||
$employee_infos = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
||||
SELECT id_last_order, id_last_customer_message, id_last_customer
|
||||
@@ -55,7 +55,7 @@ class NotificationCore
|
||||
|
||||
return $notifications;
|
||||
}
|
||||
|
||||
|
||||
public function installDb()
|
||||
{
|
||||
Db::getInstance(_PS_USE_SQL_SLAVE_)->Execute('ALTER TABLE `'._DB_PREFIX_.'employee`
|
||||
@@ -74,7 +74,6 @@ class NotificationCore
|
||||
*/
|
||||
public static function getLastElementsIdsByType($type, $id_last_element)
|
||||
{
|
||||
|
||||
if ($type == 'order' || $type == 'customer_message')
|
||||
$sql = 'SELECT '.(($type == 'order') ? 'id_order, id_customer, total_paid' : 'c.id_customer_message as id_customer_message, ct.id_customer as id_customer, ct.id_customer_thread as id_customer_thread, ct.email as email').'
|
||||
FROM `'._DB_PREFIX_.(($type == 'order') ? bqSQL($type).'s`' : bqSQL($type).'` as c LEFT JOIN `'._DB_PREFIX_.'customer_thread` as ct ON c.id_customer_thread = ct.id_customer_thread').'
|
||||
@@ -90,9 +89,9 @@ class NotificationCore
|
||||
$json = array();
|
||||
foreach (Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql) as $key => $value)
|
||||
{
|
||||
$customer = NULL;
|
||||
$order = NULL;
|
||||
$currency = NULL;
|
||||
$customer = null;
|
||||
$order = null;
|
||||
$currency = null;
|
||||
if (isset($value['id_order']))
|
||||
{
|
||||
$order = new Order(intval($value['id_order']));
|
||||
@@ -100,14 +99,14 @@ class NotificationCore
|
||||
}
|
||||
if (!empty($value['id_customer']))
|
||||
$customer = new Customer(intval($value['id_customer']));
|
||||
|
||||
|
||||
$json[] = array(
|
||||
'id_order' => ((!empty($value['id_order'])) ? (int)$value['id_order'] : 0),
|
||||
'id_customer' => ((!empty($value['id_customer'])) ? (int)$value['id_customer'] : 0),
|
||||
'id_customer_message' => ((!empty($value['id_customer_message'])) ? (int)$value['id_customer_message'] : 0),
|
||||
'id_customer_thread' => ((!empty($value['id_customer_thread'])) ? (int)$value['id_customer_thread'] : 0),
|
||||
'total_paid' => ((!empty($value['total_paid']) && $currency != NULL) ? Tools::displayPrice((float)$value['total_paid'], $currency, false) : 0),
|
||||
'customer_name' => (($customer != NULL) ? $customer->firstname.' '.$customer->lastname : (isset($value['email']) ? $value['email'] : ''))
|
||||
'id_customer_thread' => ((!empty($value['id_customer_thread'])) ? (int)$value['id_customer_thread'] : 0),
|
||||
'total_paid' => ((!empty($value['total_paid']) && $currency != null) ? Tools::displayPrice((float)$value['total_paid'], $currency, false) : 0),
|
||||
'customer_name' => (($customer != null) ? $customer->firstname.' '.$customer->lastname : (isset($value['email']) ? $value['email'] : ''))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -122,9 +121,9 @@ class NotificationCore
|
||||
* @return boolean if type exists or not
|
||||
*/
|
||||
public function updateEmployeeLastElement($type)
|
||||
{
|
||||
{
|
||||
global $cookie;
|
||||
|
||||
|
||||
if (in_array($type, $this->types))
|
||||
// We update the last item viewed
|
||||
return Db::getInstance()->Execute('
|
||||
@@ -136,4 +135,3 @@ class NotificationCore
|
||||
return false;
|
||||
}
|
||||
}
|
||||
?>
|
||||
+131
-121
@@ -52,7 +52,7 @@ abstract class ObjectModelCore
|
||||
|
||||
protected $id_shop = null;
|
||||
|
||||
private $getShopFromContext = true;
|
||||
private $get_shop_from_context = true;
|
||||
|
||||
protected static $fieldsRequiredDatabase = null;
|
||||
|
||||
@@ -124,12 +124,12 @@ abstract class ObjectModelCore
|
||||
/**
|
||||
* Returns object validation rules (fields validity)
|
||||
*
|
||||
* @param string $className Child class name for static use (optional)
|
||||
* @param string $class Child class name for static use (optional)
|
||||
* @return array Validation rules (fields validity)
|
||||
*/
|
||||
public static function getValidationRules($className = __CLASS__)
|
||||
public static function getValidationRules($class = __CLASS__)
|
||||
{
|
||||
$object = new $className();
|
||||
$object = new $class();
|
||||
return array(
|
||||
'required' => $object->fieldsRequired,
|
||||
'size' => $object->fieldsSize,
|
||||
@@ -158,7 +158,7 @@ abstract class ObjectModelCore
|
||||
if ($id_shop && $this->isLangMultishop())
|
||||
{
|
||||
$this->id_shop = (int)$id_shop;
|
||||
$this->getShopFromContext = false;
|
||||
$this->get_shop_from_context = false;
|
||||
}
|
||||
|
||||
if ($this->isLangMultishop() && !$this->id_shop)
|
||||
@@ -201,7 +201,7 @@ abstract class ObjectModelCore
|
||||
$result = Db::getInstance()->executeS($sql);
|
||||
if ($result)
|
||||
foreach ($result as $row)
|
||||
foreach ($row AS $key => $value)
|
||||
foreach ($row as $key => $value)
|
||||
{
|
||||
if (array_key_exists($key, $this) && $key != $this->def['primary'])
|
||||
{
|
||||
@@ -402,7 +402,7 @@ abstract class ObjectModelCore
|
||||
if ($fields && is_array($fields))
|
||||
foreach ($fields as $field)
|
||||
{
|
||||
foreach (array_keys($field) AS $key)
|
||||
foreach (array_keys($field) as $key)
|
||||
if (!Validate::isTableOrIdentifier($key))
|
||||
throw new PrestaShopException('key '.$key.' is not table or identifier, ');
|
||||
$field[$this->def['primary']] = (int)$this->id;
|
||||
@@ -478,8 +478,8 @@ abstract class ObjectModelCore
|
||||
// If this table is linked to multishop system, update / insert for all shops from context
|
||||
if ($this->isLangMultishop())
|
||||
{
|
||||
$listShops = ($this->id_shop && !$this->getShopFromContext) ? array($this->id_shop) : Context::getContext()->shop->getListOfID();
|
||||
foreach ($listShops as $shop)
|
||||
$list_shops = ($this->id_shop && !$this->get_shop_from_context) ? array($this->id_shop) : Context::getContext()->shop->getListOfID();
|
||||
foreach ($list_shops as $shop)
|
||||
{
|
||||
$field['id_shop'] = $shop;
|
||||
$where = pSQL($this->def['primary']).' = '.(int)$this->id
|
||||
@@ -527,21 +527,21 @@ abstract class ObjectModelCore
|
||||
$this->clearCache();
|
||||
|
||||
// Database deletion
|
||||
$result = Db::getInstance()->execute('DELETE FROM `'.pSQL(_DB_PREFIX_.$this->def['table']).'` WHERE `'.pSQL($this->def['primary']).'` = '.(int)$this->id);
|
||||
$result = Db::getInstance()->delete(_DB_PREFIX_.$this->def['table'], '`'.pSQL($this->def['primary']).'` = '.(int)$this->id);
|
||||
if (!$result)
|
||||
return false;
|
||||
|
||||
// Database deletion for multilingual fields related to the object
|
||||
if (isset($this->def['multilang']) && $this->def['multilang'])
|
||||
Db::getInstance()->execute('DELETE FROM `'.pSQL(_DB_PREFIX_.$this->def['table']).'_lang` WHERE `'.pSQL($this->def['primary']).'` = '.(int)$this->id);
|
||||
Db::getInstance()->delete(_DB_PREFIX_.$this->def['table'].'_lang', '`'.pSQL($this->def['primary']).'` = '.(int)$this->id);
|
||||
|
||||
$assos = Shop::getAssoTables();
|
||||
if (isset($assos[$this->def['table']]) && $assos[$this->def['table']]['type'] == 'shop')
|
||||
Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.$this->def['table'].'_shop` WHERE `'.$this->def['primary'].'`='.(int)$this->id);
|
||||
Db::getInstance()->delete(_DB_PREFIX_.$this->def['table'].'_shop', '`'.$this->def['primary'].'`='.(int)$this->id);
|
||||
|
||||
$assos = GroupShop::getAssoTables();
|
||||
if (isset($assos[$this->def['table']]) && $assos[$this->def['table']]['type'] == 'group_shop')
|
||||
Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.$this->def['table'].'_group_shop` WHERE `'.$this->def['primary'].'`='.(int)$this->id);
|
||||
Db::getInstance()->delete('DELETE FROM `'._DB_PREFIX_.$this->def['table'].'_group_shop` WHERE `'.$this->def['primary'].'`='.(int)$this->id);
|
||||
|
||||
// @hook actionObject*DeleteAfter
|
||||
Hook::exec('actionObjectDeleteAfter', array('object' => $this));
|
||||
@@ -562,7 +562,7 @@ abstract class ObjectModelCore
|
||||
foreach ($selection as $id)
|
||||
{
|
||||
$this->id = (int)$id;
|
||||
$result = $result AND $this->delete();
|
||||
$result = $result && $this->delete();
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
@@ -592,15 +592,15 @@ abstract class ObjectModelCore
|
||||
/**
|
||||
* @deprecated 1.5.0 (use getFieldsLang())
|
||||
*/
|
||||
protected function getTranslationsFields($fieldsArray)
|
||||
protected function getTranslationsFields($fields_array)
|
||||
{
|
||||
$fields = array();
|
||||
|
||||
if ($this->id_lang == NULL)
|
||||
if ($this->id_lang == null)
|
||||
foreach (Language::getLanguages(false) as $language)
|
||||
$this->makeTranslationFields($fields, $fieldsArray, $language['id_lang']);
|
||||
$this->makeTranslationFields($fields, $fields_array, $language['id_lang']);
|
||||
else
|
||||
$this->makeTranslationFields($fields, $fieldsArray, $this->id_lang);
|
||||
$this->makeTranslationFields($fields, $fields_array, $this->id_lang);
|
||||
|
||||
return $fields;
|
||||
}
|
||||
@@ -608,34 +608,34 @@ abstract class ObjectModelCore
|
||||
/**
|
||||
* @deprecated 1.5.0
|
||||
*/
|
||||
protected function makeTranslationFields(&$fields, &$fieldsArray, $id_language)
|
||||
protected function makeTranslationFields(&$fields, &$fields_array, $id_language)
|
||||
{
|
||||
$fields[$id_language]['id_lang'] = $id_language;
|
||||
$fields[$id_language][$this->def['primary']] = (int)($this->id);
|
||||
$fields[$id_language][$this->def['primary']] = (int)$this->id;
|
||||
if ($this->id_shop && $this->isLangMultishop())
|
||||
$fields[$id_language]['id_shop'] = (int)$this->id_shop;
|
||||
foreach ($fieldsArray as $k => $field)
|
||||
foreach ($fields_array as $k => $field)
|
||||
{
|
||||
$html = false;
|
||||
$fieldName = $field;
|
||||
$field_name = $field;
|
||||
if (is_array($field))
|
||||
{
|
||||
$fieldName = $k;
|
||||
$field_name = $k;
|
||||
$html = (isset($field['html'])) ? $field['html'] : false;
|
||||
}
|
||||
|
||||
/* Check fields validity */
|
||||
if (!Validate::isTableOrIdentifier($fieldName))
|
||||
throw new PrestaShopException('identifier is not table or identifier : '.$fieldName);
|
||||
if (!Validate::isTableOrIdentifier($field_name))
|
||||
throw new PrestaShopException('identifier is not table or identifier : '.$field_name);
|
||||
|
||||
/* Copy the field, or the default language field if it's both required and empty */
|
||||
if ((!$this->id_lang && isset($this->{$fieldName}[$id_language]) && !empty($this->{$fieldName}[$id_language]))
|
||||
|| ($this->id_lang && isset($this->$fieldName) && !empty($this->$fieldName)))
|
||||
$fields[$id_language][$fieldName] = $this->id_lang ? pSQL($this->$fieldName, $html) : pSQL($this->{$fieldName}[$id_language], $html);
|
||||
else if (in_array($fieldName, $this->fieldsRequiredLang))
|
||||
$fields[$id_language][$fieldName] = $this->id_lang ? pSQL($this->$fieldName, $html) : pSQL($this->{$fieldName}[Configuration::get('PS_LANG_DEFAULT')], $html);
|
||||
// Copy the field, or the default language field if it's both required and empty
|
||||
if ((!$this->id_lang && isset($this->{$field_name}[$id_language]) && !empty($this->{$field_name}[$id_language]))
|
||||
|| ($this->id_lang && isset($this->$field_name) && !empty($this->$field_name)))
|
||||
$fields[$id_language][$field_name] = $this->id_lang ? pSQL($this->$field_name, $html) : pSQL($this->{$field_name}[$id_language], $html);
|
||||
else if (in_array($field_name, $this->fieldsRequiredLang))
|
||||
$fields[$id_language][$field_name] = pSQL($this->id_lang ? $this->$field_name : $this->{$field_name}[Configuration::get('PS_LANG_DEFAULT')], $html);
|
||||
else
|
||||
$fields[$id_language][$fieldName] = '';
|
||||
$fields[$id_language][$field_name] = '';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -754,12 +754,14 @@ abstract class ObjectModelCore
|
||||
return true;
|
||||
}
|
||||
|
||||
static public function displayFieldName($field, $className = __CLASS__, $htmlentities = true, Context $context = null)
|
||||
public static function displayFieldName($field, $class = __CLASS__, $htmlentities = true, Context $context = null)
|
||||
{
|
||||
global $_FIELDS;
|
||||
@include(_PS_TRANSLATIONS_DIR_.Context::getContext()->language->iso_code.'/fields.php');
|
||||
|
||||
$key = $className.'_'.md5($field);
|
||||
if (file_exists(_PS_TRANSLATIONS_DIR_.Context::getContext()->language->iso_code.'/fields.php'))
|
||||
include(_PS_TRANSLATIONS_DIR_.Context::getContext()->language->iso_code.'/fields.php');
|
||||
|
||||
$key = $class.'_'.md5($field);
|
||||
return ((is_array($_FIELDS) && array_key_exists($key, $_FIELDS)) ? ($htmlentities ? htmlentities($_FIELDS[$key], ENT_QUOTES, 'utf-8') : $_FIELDS[$key]) : $field);
|
||||
}
|
||||
|
||||
@@ -778,18 +780,19 @@ abstract class ObjectModelCore
|
||||
$errors = array();
|
||||
foreach ($this->def['fields'] as $field => $data)
|
||||
{
|
||||
/* Checking for required fields */
|
||||
// Checking for required fields
|
||||
if (isset($data['required']) && $data['required'] && ($value = Tools::getValue($field, $this->{$field})) == false && (string)$value != '0')
|
||||
if (!$this->id OR $field != 'passwd')
|
||||
if (!$this->id || $field != 'passwd')
|
||||
$errors[] = '<b>'.self::displayFieldName($field, get_class($this), $htmlentities).'</b> '.Tools::displayError('is required.');
|
||||
|
||||
/* Checking for maximum fields sizes */
|
||||
|
||||
// Checking for maximum fields sizes
|
||||
if (isset($data['size']) && ($value = Tools::getValue($field, $this->{$field})) && Tools::strlen($value) > $data['size'])
|
||||
$errors[] = '<b>'.self::displayFieldName($field, get_class($this), $htmlentities).'</b> '.Tools::displayError('is too long.').' ('.Tools::displayError('Maximum length:').' '.$data['size'].')';
|
||||
|
||||
/* Checking for fields validity */
|
||||
$errors[] = '<b>'.self::displayFieldName($field, get_class($this), $htmlentities).'</b> '.Tools::displayError('is too long.')
|
||||
.' ('.Tools::displayError('Maximum length:').' '.$data['size'].')';
|
||||
|
||||
// Checking for fields validity
|
||||
// Hack for postcode required for country which does not have postcodes
|
||||
if ($value = Tools::getValue($field, $this->{$field}) OR ($field == 'postcode' AND $value == '0'))
|
||||
if ($value = Tools::getValue($field, $this->{$field}) || ($field == 'postcode' && $value == '0'))
|
||||
{
|
||||
if (isset($data['validate']) && !Validate::$data['validate']($value) && (!empty($value) || $data['required']))
|
||||
$errors[] = '<b>'.self::displayFieldName($field, get_class($this), $htmlentities).'</b> '.Tools::displayError('is invalid.');
|
||||
@@ -810,9 +813,9 @@ abstract class ObjectModelCore
|
||||
return $errors;
|
||||
}
|
||||
|
||||
public function getWebserviceParameters($wsParamsAttributeName = null)
|
||||
public function getWebserviceParameters($ws_params_attribute_name = null)
|
||||
{
|
||||
$defaultResourceParameters = array(
|
||||
$default_resource_parameters = array(
|
||||
'objectSqlId' => $this->def['primary'],
|
||||
'retrieveData' => array(
|
||||
'className' => get_class($this),
|
||||
@@ -825,52 +828,50 @@ abstract class ObjectModelCore
|
||||
),
|
||||
);
|
||||
|
||||
if (is_null($wsParamsAttributeName))
|
||||
$wsParamsAttributeName = 'webserviceParameters';
|
||||
if (is_null($ws_params_attribute_name))
|
||||
$ws_params_attribute_name = 'webserviceParameters';
|
||||
|
||||
if (!isset($this->{$ws_params_attribute_name}['objectNodeName']))
|
||||
$default_resource_parameters['objectNodeName'] = $this->def['table'];
|
||||
if (!isset($this->{$ws_params_attribute_name}['objectsNodeName']))
|
||||
$default_resource_parameters['objectsNodeName'] = $this->def['table'].'s';
|
||||
|
||||
if (!isset($this->{$wsParamsAttributeName}['objectNodeName']))
|
||||
$defaultResourceParameters['objectNodeName'] = $this->def['table'];
|
||||
if (!isset($this->{$wsParamsAttributeName}['objectsNodeName']))
|
||||
$defaultResourceParameters['objectsNodeName'] = $this->def['table'].'s';
|
||||
|
||||
if (isset($this->{$wsParamsAttributeName}['associations']))
|
||||
foreach ($this->{$wsParamsAttributeName}['associations'] as $assocName => &$association)
|
||||
if (isset($this->{$ws_params_attribute_name}['associations']))
|
||||
foreach ($this->{$ws_params_attribute_name}['associations'] as $assoc_name => &$association)
|
||||
{
|
||||
if (!array_key_exists('setter', $association) || (isset($association['setter']) && !$association['setter']))
|
||||
$association['setter'] = Tools::toCamelCase('set_ws_'.$assocName);
|
||||
$association['setter'] = Tools::toCamelCase('set_ws_'.$assoc_name);
|
||||
if (!array_key_exists('getter', $association))
|
||||
$association['getter'] = Tools::toCamelCase('get_ws_'.$assocName);
|
||||
$association['getter'] = Tools::toCamelCase('get_ws_'.$assoc_name);
|
||||
}
|
||||
|
||||
if (isset($this->{$ws_params_attribute_name}['retrieveData']) && isset($this->{$ws_params_attribute_name}['retrieveData']['retrieveMethod']))
|
||||
unset($default_resource_parameters['retrieveData']['retrieveMethod']);
|
||||
|
||||
if (isset($this->{$wsParamsAttributeName}['retrieveData']) && isset($this->{$wsParamsAttributeName}['retrieveData']['retrieveMethod']))
|
||||
unset($defaultResourceParameters['retrieveData']['retrieveMethod']);
|
||||
|
||||
$resourceParameters = array_merge_recursive($defaultResourceParameters, $this->{$wsParamsAttributeName});
|
||||
$resource_parameters = array_merge_recursive($default_resource_parameters, $this->{$ws_params_attribute_name});
|
||||
if (isset($this->fieldsSize))
|
||||
foreach ($this->fieldsSize as $fieldName => $maxSize)
|
||||
foreach ($this->fieldsSize as $field_name => $max_size)
|
||||
{
|
||||
if (!isset($resourceParameters['fields'][$fieldName]))
|
||||
$resourceParameters['fields'][$fieldName] = array('required' => false);
|
||||
$resourceParameters['fields'][$fieldName] = array_merge(
|
||||
$resourceParameters['fields'][$fieldName],
|
||||
$resourceParameters['fields'][$fieldName] = array('sqlId' => $fieldName, 'maxSize' => $maxSize, 'i18n' => false)
|
||||
if (!isset($resource_parameters['fields'][$field_name]))
|
||||
$resource_parameters['fields'][$field_name] = array('required' => false);
|
||||
$resource_parameters['fields'][$field_name] = array_merge(
|
||||
$resource_parameters['fields'][$field_name],
|
||||
$resource_parameters['fields'][$field_name] = array('sqlId' => $field_name, 'maxSize' => $max_size, 'i18n' => false)
|
||||
);
|
||||
}
|
||||
if (isset($this->fieldsValidate))
|
||||
foreach ($this->fieldsValidate as $fieldName => $validateMethod)
|
||||
foreach ($this->fieldsValidate as $field_name => $validate_method)
|
||||
{
|
||||
if (!isset($resourceParameters['fields'][$fieldName]))
|
||||
$resourceParameters['fields'][$fieldName] = array('required' => false);
|
||||
$resourceParameters['fields'][$fieldName] = array_merge(
|
||||
$resourceParameters['fields'][$fieldName],
|
||||
$resourceParameters['fields'][$fieldName] = array(
|
||||
'sqlId' => $fieldName,
|
||||
if (!isset($resource_parameters['fields'][$field_name]))
|
||||
$resource_parameters['fields'][$field_name] = array('required' => false);
|
||||
$resource_parameters['fields'][$field_name] = array_merge(
|
||||
$resource_parameters['fields'][$field_name],
|
||||
$resource_parameters['fields'][$field_name] = array(
|
||||
'sqlId' => $field_name,
|
||||
'validateMethod' => (
|
||||
array_key_exists('validateMethod', $resourceParameters['fields'][$fieldName]) ?
|
||||
array_merge($resourceParameters['fields'][$fieldName]['validateMethod'], array($validateMethod)) :
|
||||
array($validateMethod)
|
||||
array_key_exists('validateMethod', $resource_parameters['fields'][$field_name]) ?
|
||||
array_merge($resource_parameters['fields'][$field_name]['validateMethod'], array($validate_method)) :
|
||||
array($validate_method)
|
||||
),
|
||||
'i18n' => false
|
||||
)
|
||||
@@ -878,40 +879,43 @@ abstract class ObjectModelCore
|
||||
}
|
||||
if (isset($this->fieldsRequired))
|
||||
{
|
||||
$fieldsRequired = array_merge($this->fieldsRequired, (isset(self::$fieldsRequiredDatabase[get_class($this)]) ? self::$fieldsRequiredDatabase[get_class($this)] : array()));
|
||||
foreach ($fieldsRequired as $fieldRequired)
|
||||
$fieldsRequired = array_merge(
|
||||
$this->fieldsRequired,
|
||||
(isset(self::$fieldsRequiredDatabase[get_class($this)]) ? self::$fieldsRequiredDatabase[get_class($this)] : array())
|
||||
);
|
||||
foreach ($fieldsRequired as $field_required)
|
||||
{
|
||||
if (!isset($resourceParameters['fields'][$fieldRequired]))
|
||||
$resourceParameters['fields'][$fieldRequired] = array();
|
||||
$resourceParameters['fields'][$fieldRequired] = array_merge(
|
||||
$resourceParameters['fields'][$fieldRequired],
|
||||
$resourceParameters['fields'][$fieldRequired] = array('sqlId' => $fieldRequired, 'required' => true, 'i18n' => false)
|
||||
if (!isset($resource_parameters['fields'][$field_required]))
|
||||
$resource_parameters['fields'][$field_required] = array();
|
||||
$resource_parameters['fields'][$field_required] = array_merge(
|
||||
$resource_parameters['fields'][$field_required],
|
||||
$resource_parameters['fields'][$field_required] = array('sqlId' => $field_required, 'required' => true, 'i18n' => false)
|
||||
);
|
||||
}
|
||||
}
|
||||
if (isset($this->fieldsSizeLang))
|
||||
foreach ($this->fieldsSizeLang as $fieldName => $maxSize)
|
||||
foreach ($this->fieldsSizeLang as $field_name => $max_size)
|
||||
{
|
||||
if (!isset($resourceParameters['fields'][$fieldName]))
|
||||
$resourceParameters['fields'][$fieldName] = array('required' => false);
|
||||
$resourceParameters['fields'][$fieldName] = array_merge(
|
||||
$resourceParameters['fields'][$fieldName],
|
||||
$resourceParameters['fields'][$fieldName] = array('sqlId' => $fieldName, 'maxSize' => $maxSize, 'i18n' => true)
|
||||
if (!isset($resource_parameters['fields'][$field_name]))
|
||||
$resource_parameters['fields'][$field_name] = array('required' => false);
|
||||
$resource_parameters['fields'][$field_name] = array_merge(
|
||||
$resource_parameters['fields'][$field_name],
|
||||
$resource_parameters['fields'][$field_name] = array('sqlId' => $field_name, 'maxSize' => $max_size, 'i18n' => true)
|
||||
);
|
||||
}
|
||||
if (isset($this->fieldsValidateLang))
|
||||
foreach ($this->fieldsValidateLang as $fieldName => $validateMethod)
|
||||
foreach ($this->fieldsValidateLang as $field_name => $validate_method)
|
||||
{
|
||||
if (!isset($resourceParameters['fields'][$fieldName]))
|
||||
$resourceParameters['fields'][$fieldName] = array('required' => false);
|
||||
$resourceParameters['fields'][$fieldName] = array_merge(
|
||||
$resourceParameters['fields'][$fieldName],
|
||||
$resourceParameters['fields'][$fieldName] = array(
|
||||
'sqlId' => $fieldName,
|
||||
if (!isset($resource_parameters['fields'][$field_name]))
|
||||
$resource_parameters['fields'][$field_name] = array('required' => false);
|
||||
$resource_parameters['fields'][$field_name] = array_merge(
|
||||
$resource_parameters['fields'][$field_name],
|
||||
$resource_parameters['fields'][$field_name] = array(
|
||||
'sqlId' => $field_name,
|
||||
'validateMethod' => (
|
||||
array_key_exists('validateMethod', $resourceParameters['fields'][$fieldName]) ?
|
||||
array_merge($resourceParameters['fields'][$fieldName]['validateMethod'], array($validateMethod)) :
|
||||
array($validateMethod)
|
||||
array_key_exists('validateMethod', $resource_parameters['fields'][$field_name]) ?
|
||||
array_merge($resource_parameters['fields'][$field_name]['validateMethod'], array($validate_method)) :
|
||||
array($validate_method)
|
||||
),
|
||||
'i18n' => true
|
||||
)
|
||||
@@ -921,39 +925,41 @@ abstract class ObjectModelCore
|
||||
if (isset($this->fieldsRequiredLang))
|
||||
foreach ($this->fieldsRequiredLang as $field)
|
||||
{
|
||||
if (!isset($resourceParameters['fields'][$field]))
|
||||
$resourceParameters['fields'][$field] = array();
|
||||
$resourceParameters['fields'][$field] = array_merge(
|
||||
$resourceParameters['fields'][$field],
|
||||
$resourceParameters['fields'][$field] = array('sqlId' => $field, 'required' => true, 'i18n' => true)
|
||||
if (!isset($resource_parameters['fields'][$field]))
|
||||
$resource_parameters['fields'][$field] = array();
|
||||
$resource_parameters['fields'][$field] = array_merge(
|
||||
$resource_parameters['fields'][$field],
|
||||
$resource_parameters['fields'][$field] = array('sqlId' => $field, 'required' => true, 'i18n' => true)
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($this->date_add))
|
||||
$resourceParameters['fields']['date_add']['setter'] = false;
|
||||
$resource_parameters['fields']['date_add']['setter'] = false;
|
||||
if (isset($this->date_upd))
|
||||
$resourceParameters['fields']['date_upd']['setter'] = false;
|
||||
$resource_parameters['fields']['date_upd']['setter'] = false;
|
||||
|
||||
foreach ($resourceParameters['fields'] as $key => &$resourceParametersField)
|
||||
if (!isset($resourceParametersField['sqlId']))
|
||||
$resourceParametersField['sqlId'] = $key;
|
||||
return $resourceParameters;
|
||||
foreach ($resource_parameters['fields'] as $key => &$resource_parameters_field)
|
||||
if (!isset($resource_parameters_field['sqlId']))
|
||||
$resource_parameters['sqlId'] = $key;
|
||||
return $resource_parameters;
|
||||
}
|
||||
|
||||
public function getWebserviceObjectList($sql_join, $sql_filter, $sql_sort, $sql_limit)
|
||||
{
|
||||
$assoc = Shop::getAssoTables();
|
||||
|
||||
if (array_key_exists($this->def['table'] ,$assoc))
|
||||
if (array_key_exists($this->def['table'], $assoc))
|
||||
{
|
||||
$multi_shop_join = ' LEFT JOIN `'._DB_PREFIX_.bqSQL($this->def['table']).'_'.bqSQL($assoc[$this->def['table']]['type']).'` AS multi_shop_'.bqSQL($this->def['table']).' ON (main.'.bqSQL($this->def['primary']).' = '.'multi_shop_'.bqSQL($this->def['table']).'.'.bqSQL($this->def['primary']).')';
|
||||
$multi_shop_join = ' LEFT JOIN `'._DB_PREFIX_.bqSQL($this->def['table']).'_'.bqSQL($assoc[$this->def['table']]['type']).'`
|
||||
AS multi_shop_'.bqSQL($this->def['table']).'
|
||||
ON (main.'.bqSQL($this->def['primary']).' = multi_shop_'.bqSQL($this->def['table']).'.'.bqSQL($this->def['primary']).')';
|
||||
$class_name = WebserviceRequest::$ws_current_classname;
|
||||
$vars = get_class_vars($class_name);
|
||||
foreach ($vars['shopIDs'] as $id_shop)
|
||||
$OR[] = ' multi_shop_'.bqSQL($this->def['table']).'.id_shop = '.(int)$id_shop.' ';
|
||||
$multi_shop_filter = ' AND ('.implode('OR', $OR).') ';
|
||||
$or[] = ' multi_shop_'.bqSQL($this->def['table']).'.id_shop = '.(int)$id_shop.' ';
|
||||
$multi_shop_filter = ' AND ('.implode('OR', $or).') ';
|
||||
$sql_filter = $multi_shop_filter.' '.$sql_filter;
|
||||
$sql_join = $multi_shop_join .' '. $sql_join;
|
||||
$sql_join = $multi_shop_join.' '.$sql_join;
|
||||
}
|
||||
$query = '
|
||||
SELECT DISTINCT main.`'.bqSQL($this->def['primary']).'` FROM `'._DB_PREFIX_.bqSQL($this->def['table']).'` AS main
|
||||
@@ -980,7 +986,7 @@ abstract class ObjectModelCore
|
||||
if (!Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'required_field WHERE object_name = \''.get_class($this).'\''))
|
||||
return false;
|
||||
|
||||
foreach ($fields AS $field)
|
||||
foreach ($fields as $field)
|
||||
if (!Db::getInstance()->insert('required_field', array('object_name' => get_class($this), 'field_name' => pSQL($field))))
|
||||
return false;
|
||||
return true;
|
||||
@@ -1024,18 +1030,22 @@ abstract class ObjectModelCore
|
||||
{
|
||||
if (!$this->id)
|
||||
return;
|
||||
$sql = '';
|
||||
|
||||
if (!is_array($id_shops))
|
||||
$id_shops = array($id_shops);
|
||||
|
||||
$data = array();
|
||||
foreach ($id_shops as $id_shop)
|
||||
{
|
||||
if (($type == 'shop' && !$this->isAssociatedToShop($id_shop)) || ($type == 'group_shop' && !$this->isAssociatedToGroupShop($id_shop)))
|
||||
$sql .= '('.(int)$this->id.','.(int)$id_shop.'),';
|
||||
$data[] = array(
|
||||
$this->def['primary'] => (int)$this->id,
|
||||
'id_'.$type => (int)$id_shop,
|
||||
);
|
||||
}
|
||||
|
||||
if (!empty($sql))
|
||||
return (bool)Db::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.$this->def['table'].'_'.$type.'` (`'.$this->def['primary'].'`, `id_'.$type.'`) VALUES '.rtrim($sql,','));
|
||||
if ($data)
|
||||
return Db::getInstance()->insert($this->def['table'].'_'.$type, $data);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1110,7 +1120,7 @@ abstract class ObjectModelCore
|
||||
return false;
|
||||
|
||||
$types = ImageType::getImagesTypes();
|
||||
foreach ($types AS $image_type)
|
||||
foreach ($types as $image_type)
|
||||
if (file_exists($this->image_dir.$this->id.'-'.stripslashes($image_type['name']).'.'.$this->image_format)
|
||||
&& !unlink($this->image_dir.$this->id.'-'.stripslashes($image_type['name']).'.'.$this->image_format))
|
||||
return false;
|
||||
|
||||
+26
-21
@@ -38,7 +38,7 @@ class PackCore extends Product
|
||||
|
||||
if (!array_key_exists($id_product, self::$cacheIsPack))
|
||||
{
|
||||
$result = Db::getInstance()->getValue('SELECT COUNT(*) FROM '._DB_PREFIX_.'pack WHERE id_product_pack = '.(int)($id_product));
|
||||
$result = Db::getInstance()->getValue('SELECT COUNT(*) FROM '._DB_PREFIX_.'pack WHERE id_product_pack = '.(int)$id_product);
|
||||
self::$cacheIsPack[$id_product] = ($result > 0);
|
||||
}
|
||||
return self::$cacheIsPack[$id_product];
|
||||
@@ -51,7 +51,7 @@ class PackCore extends Product
|
||||
|
||||
if (!array_key_exists($id_product, self::$cacheIsPacked))
|
||||
{
|
||||
$result = Db::getInstance()->getValue('SELECT COUNT(*) FROM '._DB_PREFIX_.'pack WHERE id_product_item = '.(int)($id_product));
|
||||
$result = Db::getInstance()->getValue('SELECT COUNT(*) FROM '._DB_PREFIX_.'pack WHERE id_product_item = '.(int)$id_product);
|
||||
self::$cacheIsPacked[$id_product] = ($result > 0);
|
||||
}
|
||||
return self::$cacheIsPacked[$id_product];
|
||||
@@ -74,16 +74,16 @@ class PackCore extends Product
|
||||
|
||||
if (array_key_exists($id_product, self::$cachePackItems))
|
||||
return self::$cachePackItems[$id_product];
|
||||
$result = Db::getInstance()->executeS('SELECT id_product_item, quantity FROM '._DB_PREFIX_.'pack where id_product_pack = '.(int)($id_product));
|
||||
$arrayResult = array();
|
||||
foreach ($result AS $row)
|
||||
$result = Db::getInstance()->executeS('SELECT id_product_item, quantity FROM '._DB_PREFIX_.'pack where id_product_pack = '.(int)$id_product);
|
||||
$array_result = array();
|
||||
foreach ($result as $row)
|
||||
{
|
||||
$p = new Product($row['id_product_item'], false, $id_lang);
|
||||
$p->loadStockData();
|
||||
$p->pack_quantity = $row['quantity'];
|
||||
$arrayResult[] = $p;
|
||||
$array_result[] = $p;
|
||||
}
|
||||
self::$cachePackItems[$id_product] = $arrayResult;
|
||||
self::$cachePackItems[$id_product] = $array_result;
|
||||
return self::$cachePackItems[$id_product];
|
||||
}
|
||||
|
||||
@@ -97,7 +97,8 @@ class PackCore extends Product
|
||||
foreach ($items as $item)
|
||||
{
|
||||
// Updated for 1.5.0
|
||||
if (Product::getQuantity($item->id) < $item->pack_quantity || (Product::getQuantity($item->id) < $item->pack_quantity && !$item->isAvailableWhenOutOfStock((int)$item->out_of_stock)))
|
||||
if (Product::getQuantity($item->id) < $item->pack_quantity
|
||||
|| (Product::getQuantity($item->id) < $item->pack_quantity && !$item->isAvailableWhenOutOfStock((int)$item->out_of_stock)))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -111,10 +112,14 @@ class PackCore extends Product
|
||||
$sql = 'SELECT p.*, pl.*, i.`id_image`, il.`legend`, t.`rate`, cl.`name` AS category_default, a.quantity AS pack_quantity
|
||||
FROM `'._DB_PREFIX_.'pack` a
|
||||
LEFT JOIN `'._DB_PREFIX_.'product` p ON p.id_product = a.id_product_item
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.id_product = pl.id_product AND pl.`id_lang` = '.(int)$id_lang.Context::getContext()->shop->addSqlRestrictionOnLang('pl').')
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl
|
||||
ON p.id_product = pl.id_product
|
||||
AND pl.`id_lang` = '.(int)$id_lang.Context::getContext()->shop->addSqlRestrictionOnLang('pl').'
|
||||
LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)
|
||||
LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (p.`id_category_default` = cl.`id_category` AND cl.`id_lang` = '.(int)$id_lang.Context::getContext()->shop->addSqlRestrictionOnLang('cl').')
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl
|
||||
ON p.`id_category_default` = cl.`id_category`
|
||||
AND cl.`id_lang` = '.(int)$id_lang.Context::getContext()->shop->addSqlRestrictionOnLang('cl').'
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (p.`id_tax_rules_group` = tr.`id_tax_rules_group`
|
||||
AND tr.`id_country` = '.(int)Context::getContext()->country->id.'
|
||||
AND tr.`id_state` = 0)
|
||||
@@ -125,11 +130,11 @@ class PackCore extends Product
|
||||
if (!$full)
|
||||
return $result;
|
||||
|
||||
$arrayResult = array();
|
||||
$array_result = array();
|
||||
foreach ($result as $row)
|
||||
if (!Pack::isPack($row['id_product']))
|
||||
$arrayResult[] = Product::getProductProperties($id_lang, $row);
|
||||
return $arrayResult;
|
||||
$array_result[] = Product::getProductProperties($id_lang, $row);
|
||||
return $array_result;
|
||||
}
|
||||
|
||||
public static function getPacksTable($id_product, $id_lang, $full = false, $limit = null)
|
||||
@@ -165,17 +170,17 @@ class PackCore extends Product
|
||||
if (!$full)
|
||||
return $result;
|
||||
|
||||
$arrayResult = array();
|
||||
$array_result = array();
|
||||
foreach ($result as $row)
|
||||
if (!Pack::isPacked($row['id_product']))
|
||||
$arrayResult[] = Product::getProductProperties($id_lang, $row);
|
||||
return $arrayResult;
|
||||
$array_result[] = Product::getProductProperties($id_lang, $row);
|
||||
return $array_result;
|
||||
}
|
||||
|
||||
public static function deleteItems($id_product)
|
||||
{
|
||||
return Db::getInstance()->execute('UPDATE '._DB_PREFIX_.'product SET cache_is_pack = 0 WHERE id_product = '.(int)($id_product).' LIMIT 1') &&
|
||||
Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'pack` WHERE `id_product_pack` = '.(int)($id_product)) &&
|
||||
return Db::getInstance()->execute('UPDATE '._DB_PREFIX_.'product SET cache_is_pack = 0 WHERE id_product = '.(int)$id_product.' LIMIT 1') &&
|
||||
Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'pack` WHERE `id_product_pack` = '.(int)$id_product) &&
|
||||
Configuration::updateGlobalValue('PS_PACK_FEATURE_ACTIVE', Pack::isCurrentlyUsed());
|
||||
}
|
||||
|
||||
@@ -189,7 +194,7 @@ class PackCore extends Product
|
||||
*/
|
||||
public static function addItem($id_product, $id_item, $qty)
|
||||
{
|
||||
return Db::getInstance()->execute('UPDATE '._DB_PREFIX_.'product SET cache_is_pack = 1 WHERE id_product = '.(int)($id_product).' LIMIT 1') &&
|
||||
return Db::getInstance()->execute('UPDATE '._DB_PREFIX_.'product SET cache_is_pack = 1 WHERE id_product = '.(int)$id_product.' LIMIT 1') &&
|
||||
Db::getInstance()->insert('pack', array('id_product_pack' => (int)$id_product, 'id_product_item' => (int)$id_item, 'quantity' => (int)$qty)) &&
|
||||
Configuration::updateGlobalValue('PS_PACK_FEATURE_ACTIVE', '1');
|
||||
}
|
||||
@@ -197,7 +202,7 @@ class PackCore extends Product
|
||||
public static function duplicate($id_product_old, $id_product_new)
|
||||
{
|
||||
Db::getInstance()->execute('INSERT INTO '._DB_PREFIX_.'pack (id_product_pack, id_product_item, quantity)
|
||||
(SELECT '.(int)($id_product_new).', id_product_item, quantity FROM '._DB_PREFIX_.'pack WHERE id_product_pack = '.(int)($id_product_old).')');
|
||||
(SELECT '.(int)$id_product_new.', id_product_item, quantity FROM '._DB_PREFIX_.'pack WHERE id_product_pack = '.(int)$id_product_old.')');
|
||||
|
||||
// If return query result, a non-pack product will return false
|
||||
return true;
|
||||
@@ -215,7 +220,7 @@ class PackCore extends Product
|
||||
|
||||
/**
|
||||
* This method is allow to know if a Pack entity is currently used
|
||||
* @since 1.5.0.1
|
||||
* @since 1.5.0
|
||||
* @param $table
|
||||
* @param $has_active_column
|
||||
* @return bool
|
||||
|
||||
+10
-10
@@ -50,11 +50,11 @@ class PageCore extends ObjectModel
|
||||
public static function getCurrentId()
|
||||
{
|
||||
$controller = Dispatcher::getInstance()->getController();
|
||||
$pageTypeID = Page::getPageTypeByName($controller);
|
||||
$page_type_id = Page::getPageTypeByName($controller);
|
||||
|
||||
// Some pages must be distinguished in order to record exactly what is being seen
|
||||
// @todo dispatcher module
|
||||
$specialArray = array(
|
||||
$special_array = array(
|
||||
'product' => 'id_product',
|
||||
'category' => 'id_category',
|
||||
'order' => 'step',
|
||||
@@ -62,25 +62,25 @@ class PageCore extends ObjectModel
|
||||
);
|
||||
|
||||
$where = '';
|
||||
$insertData = array(
|
||||
'id_page_type' => $pageTypeID,
|
||||
$insert_data = array(
|
||||
'id_page_type' => $page_type_id,
|
||||
);
|
||||
|
||||
if (array_key_exists($controller, $specialArray))
|
||||
if (array_key_exists($controller, $special_array))
|
||||
{
|
||||
$objectID = Tools::getValue($specialArray[$controller], null);
|
||||
$where = ' AND `id_object` = '.(int)$objectID;
|
||||
$insertData['id_object'] = (int)$objectID;
|
||||
$object_id = Tools::getValue($special_array[$controller], null);
|
||||
$where = ' AND `id_object` = '.(int)$object_id;
|
||||
$insert_data['id_object'] = (int)$object_id;
|
||||
}
|
||||
|
||||
$sql = 'SELECT `id_page`
|
||||
FROM `'._DB_PREFIX_.'page`
|
||||
WHERE `id_page_type` = '.(int)$pageTypeID.$where;
|
||||
WHERE `id_page_type` = '.(int)$page_type_id.$where;
|
||||
$result = Db::getInstance()->getRow($sql);
|
||||
if ($result['id_page'])
|
||||
return $result['id_page'];
|
||||
|
||||
Db::getInstance()->insert('page', $insertData, true);
|
||||
Db::getInstance()->insert('page', $insert_data, true);
|
||||
return Db::getInstance()->Insert_ID();
|
||||
}
|
||||
|
||||
|
||||
+130
-121
@@ -42,14 +42,14 @@ abstract class PaymentModuleCore extends Module
|
||||
{
|
||||
if (!Db::getInstance()->execute('
|
||||
INSERT INTO `'._DB_PREFIX_.'module_currency` (id_module, id_currency)
|
||||
SELECT '.(int)($this->id).', id_currency FROM `'._DB_PREFIX_.'currency` WHERE deleted = 0'))
|
||||
SELECT '.(int)$this->id.', id_currency FROM `'._DB_PREFIX_.'currency` WHERE deleted = 0'))
|
||||
return false;
|
||||
}
|
||||
elseif ($this->currencies_mode == 'radio')
|
||||
{
|
||||
if (!Db::getInstance()->execute('
|
||||
INSERT INTO `'._DB_PREFIX_.'module_currency` (id_module, id_currency)
|
||||
VALUES ('.(int)($this->id).', -2)'))
|
||||
VALUES ('.(int)$this->id.', -2)'))
|
||||
return false;
|
||||
}
|
||||
else
|
||||
@@ -58,16 +58,16 @@ abstract class PaymentModuleCore extends Module
|
||||
// Insert countries availability
|
||||
$return = Db::getInstance()->execute('
|
||||
INSERT INTO `'._DB_PREFIX_.'module_country` (id_module, id_country)
|
||||
SELECT '.(int)($this->id).', id_country FROM `'._DB_PREFIX_.'country` WHERE active = 1');
|
||||
SELECT '.(int)$this->id.', id_country FROM `'._DB_PREFIX_.'country` WHERE active = 1');
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
public function uninstall()
|
||||
{
|
||||
if (!Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'module_country` WHERE id_module = '.(int)($this->id))
|
||||
OR !Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'module_currency` WHERE id_module = '.(int)($this->id))
|
||||
OR !Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'module_group` WHERE id_module = '.(int)($this->id)))
|
||||
if (!Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'module_country` WHERE id_module = '.(int)$this->id)
|
||||
|| !Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'module_currency` WHERE id_module = '.(int)$this->id)
|
||||
|| !Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'module_group` WHERE id_module = '.(int)$this->id))
|
||||
return false;
|
||||
return parent::uninstall();
|
||||
}
|
||||
@@ -78,22 +78,22 @@ abstract class PaymentModuleCore extends Module
|
||||
*
|
||||
* @param integer $id_cart Value
|
||||
* @param integer $id_order_state Value
|
||||
* @param float $amountPaid Amount really paid by customer (in the default currency)
|
||||
* @param string $paymentMethod Payment method (eg. 'Credit card')
|
||||
* @param float $amount_paid Amount really paid by customer (in the default currency)
|
||||
* @param string $payment_method Payment method (eg. 'Credit card')
|
||||
* @param string $message Message to attach to order
|
||||
*/
|
||||
public function validateOrder($id_cart, $id_order_state, $amountPaid, $paymentMethod = 'Unknown',
|
||||
$message = NULL, $extraVars = array(), $currency_special = NULL, $dont_touch_amount = false,
|
||||
public function validateOrder($id_cart, $id_order_state, $amount_paid, $payment_method = 'Unknown',
|
||||
$message = null, $extra_vars = array(), $currency_special = null, $dont_touch_amount = false,
|
||||
$secure_key = false, Shop $shop = null)
|
||||
{
|
||||
$cart = new Cart((int)($id_cart));
|
||||
$cart = new Cart($id_cart);
|
||||
|
||||
if (!$shop)
|
||||
$shop = Context::getContext()->shop;
|
||||
// Does order already exists ?
|
||||
if (Validate::isLoadedObject($cart) AND $cart->OrderExists() == false)
|
||||
if (Validate::isLoadedObject($cart) && $cart->OrderExists() == false)
|
||||
{
|
||||
if ($secure_key !== false AND $secure_key != $cart->secure_key)
|
||||
if ($secure_key !== false && $secure_key != $cart->secure_key)
|
||||
die(Tools::displayError());
|
||||
|
||||
// For each package, generate an order
|
||||
@@ -115,19 +115,19 @@ abstract class PaymentModuleCore extends Module
|
||||
$reference = Order::generateReference();
|
||||
$this->currentOrderReference = $reference;
|
||||
|
||||
$id_currency = $currency_special ? (int)($currency_special) : (int)($cart->id_currency);
|
||||
$id_currency = $currency_special ? (int)$currency_special : (int)$cart->id_currency;
|
||||
$currency = new Currency($id_currency);
|
||||
|
||||
$cart->order_reference = $reference;
|
||||
|
||||
$orderCreationFailed = false;
|
||||
$cart_total_paid = (float)Tools::ps_round((float)($cart->getOrderTotal(true, Cart::BOTH)), 2);
|
||||
$order_creation_failed = false;
|
||||
$cart_total_paid = (float)Tools::ps_round((float)$cart->getOrderTotal(true, Cart::BOTH), 2);
|
||||
|
||||
if ($cart->orderExists())
|
||||
{
|
||||
$errorMessage = Tools::displayError('An order has already been placed using this cart.');
|
||||
Logger::addLog($errorMessage, 4, '0000001', 'Cart', intval($cart->id));
|
||||
die($errorMessage);
|
||||
$error = Tools::displayError('An order has already been placed using this cart.');
|
||||
Logger::addLog($error, 4, '0000001', 'Cart', intval($cart->id));
|
||||
die($error);
|
||||
}
|
||||
|
||||
$order_status = new OrderState((int)$id_order_state, (int)$cart->id_lang);
|
||||
@@ -142,28 +142,28 @@ abstract class PaymentModuleCore extends Module
|
||||
$carrier = new Carrier($id_carrier, $cart->id_lang);
|
||||
$order = new Order();
|
||||
$order->id_carrier = (int)$carrier->id;
|
||||
$order->id_customer = (int)($cart->id_customer);
|
||||
$order->id_address_invoice = (int)($cart->id_address_invoice);
|
||||
$order->id_customer = (int)$cart->id_customer;
|
||||
$order->id_address_invoice = (int)$cart->id_address_invoice;
|
||||
$order->id_address_delivery = (int)$id_address;
|
||||
$order->id_currency = $id_currency;
|
||||
$order->id_lang = (int)($cart->id_lang);
|
||||
$order->id_cart = (int)($cart->id);
|
||||
$order->id_lang = (int)$cart->id_lang;
|
||||
$order->id_cart = (int)$cart->id;
|
||||
$order->reference = $reference;
|
||||
|
||||
$order->id_shop = (int)($shop->getID() ? $shop->getID() : $cart->id_shop);
|
||||
$order->id_group_shop = (int)($shop->getID() ? $shop->getGroupID() : $cart->id_group_shop);
|
||||
|
||||
$customer = new Customer((int)($order->id_customer));
|
||||
$customer = new Customer($order->id_customer);
|
||||
$order->secure_key = ($secure_key ? pSQL($secure_key) : pSQL($customer->secure_key));
|
||||
$order->payment = $paymentMethod;
|
||||
$order->payment = $payment_method;
|
||||
if (isset($this->name))
|
||||
$order->module = $this->name;
|
||||
$order->recyclable = $cart->recyclable;
|
||||
$order->gift = (int)($cart->gift);
|
||||
$order->gift = (int)$cart->gift;
|
||||
$order->gift_message = $cart->gift_message;
|
||||
$order->conversion_rate = $currency->conversion_rate;
|
||||
$amountPaid = !$dont_touch_amount ? Tools::ps_round((float)($amountPaid), 2) : $amountPaid;
|
||||
$order->total_paid_real = $amountPaid;
|
||||
$amount_paid = !$dont_touch_amount ? Tools::ps_round((float)$amount_paid, 2) : $amount_paid;
|
||||
$order->total_paid_real = $amount_paid;
|
||||
$order->total_products = (float)$cart->getOrderTotal(false, Cart::ONLY_PRODUCTS, $product_list, $id_carrier);
|
||||
$order->total_products_wt = (float)$cart->getOrderTotal(true, Cart::ONLY_PRODUCTS, $product_list, $id_carrier);
|
||||
|
||||
@@ -182,9 +182,9 @@ abstract class PaymentModuleCore extends Module
|
||||
$order->total_wrapping_tax_excl = (float)abs($cart->getOrderTotal(false, Cart::ONLY_WRAPPING, $product_list, $id_carrier));
|
||||
$order->total_wrapping_tax_incl = (float)abs($cart->getOrderTotal(true, Cart::ONLY_WRAPPING, $product_list, $id_carrier));
|
||||
|
||||
$order->total_paid = (float)Tools::ps_round((float)($cart->getOrderTotal(true, Cart::BOTH, $product_list, $id_carrier)), 2);
|
||||
$order->total_paid_tax_excl = (float)Tools::ps_round((float)($cart->getOrderTotal(false, Cart::BOTH, $product_list, $id_carrier)), 2);
|
||||
$order->total_paid_tax_incl = (float)Tools::ps_round((float)($cart->getOrderTotal(true, Cart::BOTH, $product_list, $id_carrier)), 2);
|
||||
$order->total_paid = (float)Tools::ps_round((float)$cart->getOrderTotal(true, Cart::BOTH, $product_list, $id_carrier), 2);
|
||||
$order->total_paid_tax_excl = (float)Tools::ps_round((float)$cart->getOrderTotal(false, Cart::BOTH, $product_list, $id_carrier), 2);
|
||||
$order->total_paid_tax_incl = (float)Tools::ps_round((float)$cart->getOrderTotal(true, Cart::BOTH, $product_list, $id_carrier), 2);
|
||||
|
||||
$order->invoice_date = '0000-00-00 00:00:00';
|
||||
$order->delivery_date = '0000-00-00 00:00:00';
|
||||
@@ -201,7 +201,7 @@ abstract class PaymentModuleCore extends Module
|
||||
// Register Payment only if the order status validate the order
|
||||
if ($result && $order_status->logable)
|
||||
{
|
||||
if (!$order->addOrderPayment($amountPaid))
|
||||
if (!$order->addOrderPayment($amount_paid))
|
||||
throw new PrestaShopException('Can\'t save Order Payment');
|
||||
}
|
||||
|
||||
@@ -226,12 +226,12 @@ abstract class PaymentModuleCore extends Module
|
||||
foreach ($order_detail_list as $key => $order_detail)
|
||||
{
|
||||
$order = $order_list[$key];
|
||||
if (!$orderCreationFailed AND isset($order->id))
|
||||
if (!$order_creation_failed & isset($order->id))
|
||||
{
|
||||
if (!$secure_key)
|
||||
$message .= Tools::displayError('Warning : the secure key is empty, check your payment account before validation');
|
||||
// Optional message to attach to this order
|
||||
if (isset($message) AND !empty($message))
|
||||
if (isset($message) & !empty($message))
|
||||
{
|
||||
$msg = new Message();
|
||||
$message = strip_tags($message, '<br>');
|
||||
@@ -249,74 +249,74 @@ abstract class PaymentModuleCore extends Module
|
||||
//$orderDetail->createList($order, $cart, $id_order_state);
|
||||
|
||||
// Construct order detail table for the email
|
||||
$productsList = '';
|
||||
$products_list = '';
|
||||
$products = $cart->getProducts();
|
||||
foreach ($products AS $key => $product)
|
||||
foreach ($products as $key => $product)
|
||||
{
|
||||
$price = Product::getPriceStatic((int)($product['id_product']), false, ($product['id_product_attribute'] ? (int)($product['id_product_attribute']) : NULL), 6, NULL, false, true, $product['cart_quantity'], false, (int)($order->id_customer), (int)($order->id_cart), (int)($order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}));
|
||||
$price_wt = Product::getPriceStatic((int)($product['id_product']), true, ($product['id_product_attribute'] ? (int)($product['id_product_attribute']) : NULL), 2, NULL, false, true, $product['cart_quantity'], false, (int)($order->id_customer), (int)($order->id_cart), (int)($order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}));
|
||||
$price = Product::getPriceStatic((int)$product['id_product'], false, ($product['id_product_attribute'] ? (int)$product['id_product_attribute'] : null), 6, null, false, true, $product['cart_quantity'], false, (int)$order->id_customer, (int)$order->id_cart, (int)$order->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
|
||||
$price_wt = Product::getPriceStatic((int)$product['id_product'], true, ($product['id_product_attribute'] ? (int)$product['id_product_attribute'] : null), 2, null, false, true, $product['cart_quantity'], false, (int)$order->id_customer, (int)$order->id_cart, (int)$order->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
|
||||
|
||||
$customizationQuantity = 0;
|
||||
if (isset($customizedDatas[$product['id_product']][$product['id_product_attribute']]))
|
||||
$customization_quantity = 0;
|
||||
if (isset($customized_datas[$product['id_product']][$product['id_product_attribute']]))
|
||||
{
|
||||
$customizationText = '';
|
||||
foreach ($customizedDatas[$product['id_product']][$product['id_product_attribute']] AS $customization)
|
||||
$customization_text = '';
|
||||
foreach ($customized_datas[$product['id_product']][$product['id_product_attribute']] as $customization)
|
||||
{
|
||||
if (isset($customization['datas'][Product::CUSTOMIZE_TEXTFIELD]))
|
||||
foreach ($customization['datas'][Product::CUSTOMIZE_TEXTFIELD] AS $text)
|
||||
$customizationText .= $text['name'].':'.' '.$text['value'].'<br />';
|
||||
foreach ($customization['datas'][Product::CUSTOMIZE_TEXTFIELD] as $text)
|
||||
$customization_text .= $text['name'].': '.$text['value'].'<br />';
|
||||
|
||||
if (isset($customization['datas'][Product::CUSTOMIZE_FILE]))
|
||||
$customizationText .= sizeof($customization['datas'][Product::CUSTOMIZE_FILE]) .' '. Tools::displayError('image(s)').'<br />';
|
||||
$customization_text .= count($customization['datas'][Product::CUSTOMIZE_FILE]).' '.Tools::displayError('image(s)').'<br />';
|
||||
|
||||
$customizationText .= '---<br />';
|
||||
$customization_text .= '---<br />';
|
||||
}
|
||||
|
||||
$customizationText = rtrim($customizationText, '---<br />');
|
||||
$customization_text = rtrim($customization_text, '---<br />');
|
||||
|
||||
$customizationQuantity = (int)($product['customizationQuantityTotal']);
|
||||
$productsList .=
|
||||
$customization_quantity = (int)$product['customizationQuantityTotal'];
|
||||
$products_list .=
|
||||
'<tr style="background-color: '.($key % 2 ? '#DDE2E6' : '#EBECEE').';">
|
||||
<td style="padding: 0.6em 0.4em;">'.$product['reference'].'</td>
|
||||
<td style="padding: 0.6em 0.4em;"><strong>'.$product['name'].(isset($product['attributes']) ? ' - '.$product['attributes'] : '').' - '.$this->l('Customized').(!empty($customizationText) ? ' - '.$customizationText : '').'</strong></td>
|
||||
<td style="padding: 0.6em 0.4em;"><strong>'.$product['name'].(isset($product['attributes']) ? ' - '.$product['attributes'] : '').' - '.$this->l('Customized').(!empty($customization_text) ? ' - '.$customization_text : '').'</strong></td>
|
||||
<td style="padding: 0.6em 0.4em; text-align: right;">'.Tools::displayPrice(Product::getTaxCalculationMethod() == PS_TAX_EXC ? $price : $price_wt, $currency, false).'</td>
|
||||
<td style="padding: 0.6em 0.4em; text-align: center;">'.$customizationQuantity.'</td>
|
||||
<td style="padding: 0.6em 0.4em; text-align: right;">'.Tools::displayPrice($customizationQuantity * (Product::getTaxCalculationMethod() == PS_TAX_EXC ? $price : $price_wt), $currency, false).'</td>
|
||||
<td style="padding: 0.6em 0.4em; text-align: center;">'.$customization_quantity.'</td>
|
||||
<td style="padding: 0.6em 0.4em; text-align: right;">'.Tools::displayPrice($customization_quantity * (Product::getTaxCalculationMethod() == PS_TAX_EXC ? $price : $price_wt), $currency, false).'</td>
|
||||
</tr>';
|
||||
}
|
||||
|
||||
if (!$customizationQuantity OR (int)$product['cart_quantity'] > $customizationQuantity)
|
||||
$productsList .=
|
||||
if (!$customization_quantity || (int)$product['cart_quantity'] > $customization_quantity)
|
||||
$products_list .=
|
||||
'<tr style="background-color: '.($key % 2 ? '#DDE2E6' : '#EBECEE').';">
|
||||
<td style="padding: 0.6em 0.4em;">'.$product['reference'].'</td>
|
||||
<td style="padding: 0.6em 0.4em;"><strong>'.$product['name'].(isset($product['attributes']) ? ' - '.$product['attributes'] : '').'</strong></td>
|
||||
<td style="padding: 0.6em 0.4em; text-align: right;">'.Tools::displayPrice(Product::getTaxCalculationMethod() == PS_TAX_EXC ? $price : $price_wt, $currency, false).'</td>
|
||||
<td style="padding: 0.6em 0.4em; text-align: center;">'.((int)($product['cart_quantity']) - $customizationQuantity).'</td>
|
||||
<td style="padding: 0.6em 0.4em; text-align: right;">'.Tools::displayPrice(((int)($product['cart_quantity']) - $customizationQuantity) * (Product::getTaxCalculationMethod() == PS_TAX_EXC ? $price : $price_wt), $currency, false).'</td>
|
||||
<td style="padding: 0.6em 0.4em; text-align: center;">'.((int)$product['cart_quantity'] - $customization_quantity).'</td>
|
||||
<td style="padding: 0.6em 0.4em; text-align: right;">'.Tools::displayPrice(((int)$product['cart_quantity'] - $customization_quantity) * (Product::getTaxCalculationMethod() == PS_TAX_EXC ? $price : $price_wt), $currency, false).'</td>
|
||||
</tr>';
|
||||
} // end foreach ($products)
|
||||
|
||||
$cartRulesList = '';
|
||||
$cart_rules_list = '';
|
||||
$result = $cart->getCartRules();
|
||||
foreach ($result as $cart_rule)
|
||||
{
|
||||
$cartRule = $cart_rule['obj'];
|
||||
$cart_rule_obj = $cart_rule['obj'];
|
||||
$values = array(
|
||||
'tax_incl' => $cartRule->getContextualValue(true),
|
||||
'tax_excl' => $cartRule->getContextualValue(false)
|
||||
'tax_incl' => $cart_rule_obj->getContextualValue(true),
|
||||
'tax_excl' => $cart_rule_obj->getContextualValue(false)
|
||||
);
|
||||
// Todo : has not been tested because order processing wasn't functionnal
|
||||
if ($values['tax_incl'] > $order->total_products_wt && $cartRule->partial_use == 1 && $cartRule->reduction_amount > 0)
|
||||
// @Todo : has not been tested because order processing wasn't functionnal
|
||||
if ($values['tax_incl'] > $order->total_products_wt && $cart_rule_obj->partial_use == 1 && $cart_rule_obj->reduction_amount > 0)
|
||||
{
|
||||
$voucher = clone $cartRule;
|
||||
$voucher = clone $cart_rule_obj;
|
||||
unset($voucher->id);
|
||||
$voucher->code = empty($voucher->code) ? substr(md5($order->id.'-'.$order->id_customer.'-'.$cartRule->id), 0, 16) : $voucher->code.'-2';
|
||||
$voucher->code = empty($voucher->code) ? substr(md5($order->id.'-'.$order->id_customer.'-'.$cart_rule_obj->id), 0, 16) : $voucher->code.'-2';
|
||||
$voucher->reduction_amount = $values['tax_incl'] - $order->total_products_wt;
|
||||
$voucher->id_customer = $order->id_customer;
|
||||
$voucher->quantity = 1;
|
||||
if ($voucher->add())
|
||||
{
|
||||
CartRule::copyConditions($cartRule->id, $voucher->id);
|
||||
CartRule::copyConditions($cart_rule_obj->id, $voucher->id);
|
||||
$params['{voucher_amount}'] = Tools::displayPrice($voucher->reduction_amount, $currency, false);
|
||||
$params['{voucher_num}'] = $voucher->code;
|
||||
$params['{firstname}'] = $customer->firstname;
|
||||
@@ -326,28 +326,28 @@ abstract class PaymentModuleCore extends Module
|
||||
}
|
||||
}
|
||||
|
||||
$order->addCartRule($cartRule->id, $cartRule->name, $values);
|
||||
$order->addCartRule($cart_rule_obj->id, $cart_rule_obj->name, $values);
|
||||
|
||||
if ($id_order_state != Configuration::get('PS_OS_ERROR') AND $id_order_state != Configuration::get('PS_OS_CANCELED'))
|
||||
if ($id_order_state != Configuration::get('PS_OS_ERROR') && $id_order_state != Configuration::get('PS_OS_CANCELED'))
|
||||
{
|
||||
// Create a new instance of Cart Rule without id_lang, in order to update it quantity
|
||||
$cart_rule_to_update = new CartRule($cartRule->id);
|
||||
$cart_rule_to_update = new CartRule($cart_rule_obj->id);
|
||||
$cart_rule_to_update->quantity = $cart_rule_to_update->quantity - 1;
|
||||
$cart_rule_to_update->update();
|
||||
}
|
||||
|
||||
$cartRulesList .= '
|
||||
$cart_rules_list .= '
|
||||
<tr style="background-color:#EBECEE;">
|
||||
<td colspan="4" style="padding:0.6em 0.4em;text-align:right">'.$this->l('Voucher name:').' '.$cartRule->name.'</td>
|
||||
<td colspan="4" style="padding:0.6em 0.4em;text-align:right">'.$this->l('Voucher name:').' '.$cart_rule_obj->name.'</td>
|
||||
<td style="padding:0.6em 0.4em;text-align:right">'.($values['tax_incl'] != 0.00 ? '-' : '').Tools::displayPrice($values['tax_incl'], $currency, false).'</td>
|
||||
</tr>';
|
||||
}
|
||||
|
||||
// Specify order id for message
|
||||
$oldMessage = Message::getMessageByCartId((int)($cart->id));
|
||||
if ($oldMessage)
|
||||
$old_message = Message::getMessageByCartId((int)$cart->id);
|
||||
if ($old_message)
|
||||
{
|
||||
$message = new Message((int)$oldMessage['id_message']);
|
||||
$message = new Message((int)$old_message['id_message']);
|
||||
$message->id_order = (int)$order->id;
|
||||
$message->update();
|
||||
}
|
||||
@@ -361,7 +361,7 @@ abstract class PaymentModuleCore extends Module
|
||||
'orderStatus' => $order_status
|
||||
));
|
||||
|
||||
foreach ($cart->getProducts() AS $product)
|
||||
foreach ($cart->getProducts() as $product)
|
||||
if ($order_status->logable)
|
||||
ProductSale::addProductSale((int)$product['id_product'], (int)$product['cart_quantity']);
|
||||
|
||||
@@ -378,7 +378,7 @@ abstract class PaymentModuleCore extends Module
|
||||
$new_history = new OrderHistory();
|
||||
$new_history->id_order = (int)$order->id;
|
||||
$new_history->changeIdOrderState((int)$id_order_state, (int)$order->id);
|
||||
$new_history->addWithemail(true, $extraVars);
|
||||
$new_history->addWithemail(true, $extra_vars);
|
||||
|
||||
unset($order_detail);
|
||||
|
||||
@@ -386,12 +386,12 @@ abstract class PaymentModuleCore extends Module
|
||||
$order = new Order($order->id);
|
||||
|
||||
// Send an e-mail to customer (one order = one email)
|
||||
if ($id_order_state != Configuration::get('PS_OS_ERROR') AND $id_order_state != Configuration::get('PS_OS_CANCELED') AND $customer->id)
|
||||
if ($id_order_state != Configuration::get('PS_OS_ERROR') && $id_order_state != Configuration::get('PS_OS_CANCELED') && $customer->id)
|
||||
{
|
||||
$invoice = new Address((int)($order->id_address_invoice));
|
||||
$delivery = new Address((int)($order->id_address_delivery));
|
||||
$delivery_state = $delivery->id_state ? new State((int)($delivery->id_state)) : false;
|
||||
$invoice_state = $invoice->id_state ? new State((int)($invoice->id_state)) : false;
|
||||
$invoice = new Address($order->id_address_invoice);
|
||||
$delivery = new Address($order->id_address_delivery);
|
||||
$delivery_state = $delivery->id_state ? new State($delivery->id_state) : false;
|
||||
$invoice_state = $invoice->id_state ? new State($invoice->id_state) : false;
|
||||
|
||||
$data = array(
|
||||
'{firstname}' => $customer->firstname,
|
||||
@@ -399,14 +399,14 @@ abstract class PaymentModuleCore extends Module
|
||||
'{email}' => $customer->email,
|
||||
'{delivery_block_txt}' => $this->_getFormatedAddress($delivery, "\n"),
|
||||
'{invoice_block_txt}' => $this->_getFormatedAddress($invoice, "\n"),
|
||||
'{delivery_block_html}' => $this->_getFormatedAddress($delivery, "<br />",
|
||||
array(
|
||||
'{delivery_block_html}' => $this->_getFormatedAddress($delivery, '<br />', array(
|
||||
'firstname' => '<span style="color:#DB3484; font-weight:bold;">%s</span>',
|
||||
'lastname' => '<span style="color:#DB3484; font-weight:bold;">%s</span>'
|
||||
)),
|
||||
'{invoice_block_html}' => $this->_getFormatedAddress($invoice, '<br />', array(
|
||||
'firstname' => '<span style="color:#DB3484; font-weight:bold;">%s</span>',
|
||||
'lastname' => '<span style="color:#DB3484; font-weight:bold;">%s</span>')),
|
||||
'{invoice_block_html}' => $this->_getFormatedAddress($invoice, "<br />",
|
||||
array(
|
||||
'firstname' => '<span style="color:#DB3484; font-weight:bold;">%s</span>',
|
||||
'lastname' => '<span style="color:#DB3484; font-weight:bold;">%s</span>')),
|
||||
'lastname' => '<span style="color:#DB3484; font-weight:bold;">%s</span>'
|
||||
)),
|
||||
'{delivery_company}' => $delivery->company,
|
||||
'{delivery_firstname}' => $delivery->firstname,
|
||||
'{delivery_lastname}' => $delivery->lastname,
|
||||
@@ -430,41 +430,51 @@ abstract class PaymentModuleCore extends Module
|
||||
'{invoice_state}' => $invoice->id_state ? $invoice_state->name : '',
|
||||
'{invoice_phone}' => ($invoice->phone) ? $invoice->phone : $invoice->phone_mobile,
|
||||
'{invoice_other}' => $invoice->other,
|
||||
'{order_name}' => sprintf("#%06d", (int)($order->id)),
|
||||
'{date}' => Tools::displayDate(date('Y-m-d H:i:s'), (int)($order->id_lang), 1),
|
||||
'{order_name}' => sprintf('#%06d', (int)$order->id),
|
||||
'{date}' => Tools::displayDate(date('Y-m-d H:i:s'), (int)$order->id_lang, 1),
|
||||
'{carrier}' => $carrier->name,
|
||||
'{payment}' => Tools::substr($order->payment, 0, 32),
|
||||
'{products}' => $productsList,
|
||||
'{discounts}' => $cartRulesList,
|
||||
'{products}' => $products_list,
|
||||
'{discounts}' => $cart_rules_list,
|
||||
'{total_paid}' => Tools::displayPrice($order->total_paid, $currency, false),
|
||||
'{total_products}' => Tools::displayPrice($order->total_paid - $order->total_shipping - $order->total_wrapping + $order->total_discounts, $currency, false),
|
||||
'{total_discounts}' => Tools::displayPrice($order->total_discounts, $currency, false),
|
||||
'{total_shipping}' => Tools::displayPrice($order->total_shipping, $currency, false),
|
||||
'{total_wrapping}' => Tools::displayPrice($order->total_wrapping, $currency, false));
|
||||
|
||||
if (is_array($extraVars))
|
||||
$data = array_merge($data, $extraVars);
|
||||
if (is_array($extra_vars))
|
||||
$data = array_merge($data, $extra_vars);
|
||||
|
||||
// Join PDF invoice
|
||||
if ((int)(Configuration::get('PS_INVOICE')) && $order_status->invoice && $order->invoice_number)
|
||||
if ((int)Configuration::get('PS_INVOICE') && $order_status->invoice && $order->invoice_number)
|
||||
{
|
||||
$pdf = new PDF($order->getInvoicesCollection(), PDF::TEMPLATE_INVOICE, $this->context->smarty);
|
||||
$fileAttachment['content'] = $pdf->render(false);
|
||||
$fileAttachment['name'] = Configuration::get('PS_INVOICE_PREFIX', (int)($order->id_lang)).sprintf('%06d', $order->invoice_number).'.pdf';
|
||||
$fileAttachment['mime'] = 'application/pdf';
|
||||
$file_attachement['content'] = $pdf->render(false);
|
||||
$file_attachement['name'] = Configuration::get('PS_INVOICE_PREFIX', (int)$order->id_lang).sprintf('%06d', $order->invoice_number).'.pdf';
|
||||
$file_attachement['mime'] = 'application/pdf';
|
||||
}
|
||||
else
|
||||
$fileAttachment = NULL;
|
||||
$file_attachement = null;
|
||||
|
||||
if (Validate::isEmail($customer->email))
|
||||
Mail::Send((int)$order->id_lang, 'order_conf', Mail::l('Order confirmation', (int)$order->id_lang), $data, $customer->email, $customer->firstname.' '.$customer->lastname, NULL, NULL, $fileAttachment);
|
||||
Mail::Send(
|
||||
(int)$order->id_lang,
|
||||
'order_conf',
|
||||
Mail::l('Order confirmation', (int)$order->id_lang),
|
||||
$data,
|
||||
$customer->email,
|
||||
$customer->firstname.' '.$customer->lastname,
|
||||
null,
|
||||
null,
|
||||
$file_attachement
|
||||
);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$errorMessage = Tools::displayError('Order creation failed');
|
||||
Logger::addLog($errorMessage, 4, '0000002', 'Cart', intval($order->id_cart));
|
||||
die($errorMessage);
|
||||
$error = Tools::displayError('Order creation failed');
|
||||
Logger::addLog($error, 4, '0000002', 'Cart', intval($order->id_cart));
|
||||
die($error);
|
||||
}
|
||||
}
|
||||
// Use the last order as currentOrder
|
||||
@@ -473,9 +483,9 @@ abstract class PaymentModuleCore extends Module
|
||||
}
|
||||
else
|
||||
{
|
||||
$errorMessage = Tools::displayError('Cart can\'t be loaded or an order has already been placed using this cart');
|
||||
Logger::addLog($errorMessage, 4, '0000001', 'Cart', intval($cart->id));
|
||||
die($errorMessage);
|
||||
$error = Tools::displayError('Cart can\'t be loaded or an order has already been placed using this cart');
|
||||
Logger::addLog($error, 4, '0000001', 'Cart', intval($cart->id));
|
||||
die($error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -485,10 +495,9 @@ abstract class PaymentModuleCore extends Module
|
||||
*/
|
||||
protected function _getTxtFormatedAddress($the_address)
|
||||
{
|
||||
$out = '';
|
||||
$adr_fields = AddressFormat::getOrderedAddressFields($the_address->id_country, false, true);
|
||||
$r_values = array();
|
||||
foreach($adr_fields as $fields_line)
|
||||
foreach ($adr_fields as $fields_line)
|
||||
{
|
||||
$tmp_values = array();
|
||||
foreach (explode(' ', $fields_line) as $field_item)
|
||||
@@ -536,11 +545,11 @@ abstract class PaymentModuleCore extends Module
|
||||
if ($currency == -1)
|
||||
$id_currency = (int)$current_id_currency;
|
||||
elseif ($currency == -2)
|
||||
$id_currency = (int)(Configuration::get('PS_CURRENCY_DEFAULT'));
|
||||
$id_currency = (int)Configuration::get('PS_CURRENCY_DEFAULT');
|
||||
else
|
||||
$id_currency = $currency;
|
||||
}
|
||||
if (!isset($id_currency) OR empty($id_currency))
|
||||
if (!isset($id_currency) || empty($id_currency))
|
||||
return false;
|
||||
return (new Currency($id_currency));
|
||||
}
|
||||
@@ -587,28 +596,28 @@ abstract class PaymentModuleCore extends Module
|
||||
*/
|
||||
public static function getInstalledPaymentModules()
|
||||
{
|
||||
$hookPayment = 'Payment';
|
||||
$hook_payment = 'Payment';
|
||||
if (Db::getInstance()->getValue('SELECT `id_hook` FROM `'._DB_PREFIX_.'hook` WHERE `name` = \'displayPayment\''))
|
||||
$hookPayment = 'displayPayment';
|
||||
$hook_payment = 'displayPayment';
|
||||
|
||||
return Db::getInstance()->executeS('
|
||||
SELECT DISTINCT m.`id_module`, h.`id_hook`, m.`name`, hm.`position`
|
||||
FROM `'._DB_PREFIX_.'module` m
|
||||
LEFT JOIN `'._DB_PREFIX_.'hook_module` hm ON hm.`id_module` = m.`id_module`
|
||||
LEFT JOIN `'._DB_PREFIX_.'hook` h ON hm.`id_hook` = h.`id_hook`
|
||||
WHERE h.`name` = \''.pSQL($hookPayment).'\'
|
||||
AND m.`active` = 1
|
||||
SELECT DISTINCT m.`id_module`, h.`id_hook`, m.`name`, hm.`position`
|
||||
FROM `'._DB_PREFIX_.'module` m
|
||||
LEFT JOIN `'._DB_PREFIX_.'hook_module` hm ON hm.`id_module` = m.`id_module`
|
||||
LEFT JOIN `'._DB_PREFIX_.'hook` h ON hm.`id_hook` = h.`id_hook`
|
||||
WHERE h.`name` = \''.pSQL($hook_payment).'\'
|
||||
AND m.`active` = 1
|
||||
');
|
||||
}
|
||||
|
||||
|
||||
public static function preCall($moduleName)
|
||||
public static function preCall($module_name)
|
||||
{
|
||||
if (!parent::preCall($moduleName))
|
||||
if (!parent::preCall($module_name))
|
||||
return false;
|
||||
|
||||
if (($moduleInstance = Module::getInstanceByName($moduleName)))
|
||||
if (!$moduleInstance->currencies OR ($moduleInstance->currencies AND sizeof(Currency::checkPaymentCurrencies($moduleInstance->id))))
|
||||
if (($module_instance = Module::getInstanceByName($module_name)))
|
||||
if (!$module_instance->currencies || ($module_instance->currencies && count(Currency::checkPaymentCurrencies($module_instance->id))))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
||||
@@ -257,7 +257,6 @@ abstract class DbCore
|
||||
*/
|
||||
public function autoExecute($table, $data, $type, $where = '', $limit = 0, $use_cache = true, $use_null = false)
|
||||
{
|
||||
Tools::displayAsDeprecated();
|
||||
$type = strtoupper($type);
|
||||
switch ($type)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user