// MERGE with 1.4 r7770
This commit is contained in:
+3
-3
@@ -276,7 +276,7 @@ class AddressCore extends ObjectModel
|
||||
return isset($result['used']) ? $result['used'] : false;
|
||||
}
|
||||
|
||||
static public function getCountryAndState($id_address)
|
||||
public static function getCountryAndState($id_address)
|
||||
{
|
||||
if (isset(self::$_idCountries[$id_address]))
|
||||
return self::$_idCountries[$id_address];
|
||||
@@ -293,7 +293,7 @@ class AddressCore extends ObjectModel
|
||||
* @param $id_address Address id
|
||||
* @return boolean
|
||||
*/
|
||||
static public function addressExists($id_address)
|
||||
public static function addressExists($id_address)
|
||||
{
|
||||
$row = Db::getInstance()->getRow('
|
||||
SELECT `id_address`
|
||||
@@ -303,7 +303,7 @@ class AddressCore extends ObjectModel
|
||||
return isset($row['id_address']);
|
||||
}
|
||||
|
||||
static public function getFirstCustomerAddressId($id_customer, $active = true)
|
||||
public static function getFirstCustomerAddressId($id_customer, $active = true)
|
||||
{
|
||||
return Db::getInstance()->getValue('
|
||||
SELECT `id_address`
|
||||
|
||||
+110
-33
@@ -45,7 +45,7 @@ class AddressFormatCore extends ObjectModel
|
||||
protected $table = 'address_format';
|
||||
protected $identifier = 'id_country';
|
||||
|
||||
static public $requireFormFieldsList = array(
|
||||
public static $requireFormFieldsList = array(
|
||||
'firstname',
|
||||
'name',
|
||||
'address1',
|
||||
@@ -54,7 +54,7 @@ class AddressFormatCore extends ObjectModel
|
||||
'Country:name',
|
||||
'State:name');
|
||||
|
||||
static public $forbiddenProperyList = array(
|
||||
public static $forbiddenPropertyList = array(
|
||||
'deleted',
|
||||
'date_add',
|
||||
'other',
|
||||
@@ -85,10 +85,12 @@ class AddressFormatCore extends ObjectModel
|
||||
'call_prefixes',
|
||||
'call_prefix');
|
||||
|
||||
static public $forbiddenClassList = array(
|
||||
public static $forbiddenClassList = array(
|
||||
'Manufacturer',
|
||||
'Supplier');
|
||||
|
||||
const _CLEANING_REGEX_ = '#([^\w:_]+)#i';
|
||||
|
||||
public function getFields()
|
||||
{
|
||||
parent::validateFields();
|
||||
@@ -124,7 +126,7 @@ class AddressFormatCore extends ObjectModel
|
||||
{
|
||||
$propertyName = $property->getName();
|
||||
if (($propertyName == $fieldName) && ($isIdField ||
|
||||
(!preg_match('#id|id_\w#', $propertyName, $match))))
|
||||
(!preg_match('#id|id_\w#', $propertyName))))
|
||||
$isValide = true;
|
||||
}
|
||||
|
||||
@@ -148,7 +150,6 @@ class AddressFormatCore extends ObjectModel
|
||||
private function _checkLiableAssociation($patternName, $fieldsValidate)
|
||||
{
|
||||
$patternName = trim($patternName);
|
||||
$cleanedLine = '';
|
||||
|
||||
if ($associationName = explode(':', $patternName))
|
||||
{
|
||||
@@ -158,8 +159,7 @@ class AddressFormatCore extends ObjectModel
|
||||
else if ($totalNameUsed == 1)
|
||||
{
|
||||
$associationName[0] = strtolower($associationName[0]);
|
||||
$cleanedLine = $associationName[0];
|
||||
if (in_array($associationName[0], self::$forbiddenProperyList) ||
|
||||
if (in_array($associationName[0], self::$forbiddenPropertyList) ||
|
||||
!$this->_checkValidateClassField('Address', $associationName[0], false))
|
||||
$this->_errorFormatList[] = Tools::displayError('This name isn\'t allowed').': '.
|
||||
$associationName[0];
|
||||
@@ -183,12 +183,10 @@ class AddressFormatCore extends ObjectModel
|
||||
|
||||
// Check if the field name exist in the class write by the user
|
||||
$this->_checkValidateClassField($associationName[0], $associationName[1], false);
|
||||
$cleanedLine = $associationName[0].':'.$associationName[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return (strlen($cleanedLine)) ? $cleanedLine.' ' : '';
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -196,27 +194,30 @@ class AddressFormatCore extends ObjectModel
|
||||
*/
|
||||
public function checkFormatFields()
|
||||
{
|
||||
$cleanedContent = '';
|
||||
$this->_errorFormatList = array();
|
||||
$fieldsValidate = Address::getFieldsValidate();
|
||||
$usedKeyList = array();
|
||||
|
||||
$multipleLineFields = explode("\n", $this->format);
|
||||
if ($multipleLineFields && is_array($multipleLineFields))
|
||||
foreach($multipleLineFields as $lineField)
|
||||
{
|
||||
$lineField = str_replace(array("\n", "\t", "\r\n", "\r"), '', $lineField);
|
||||
if (strlen($lineField))
|
||||
if (($patternsName = preg_split(self::_CLEANING_REGEX_, $lineField, -1, PREG_SPLIT_NO_EMPTY)))
|
||||
if (is_array($patternsName))
|
||||
{
|
||||
$patternsName = explode(' ', trim($lineField));
|
||||
if ($patternsName && is_array($patternsName))
|
||||
{
|
||||
foreach($patternsName as $patternName)
|
||||
$cleanedContent .= $this->_checkLiableAssociation($patternName, $fieldsValidate);
|
||||
$cleanedContent = trim($cleanedContent)."\r\n";
|
||||
{
|
||||
if (!in_array($patternName, $usedKeyList))
|
||||
{
|
||||
$this->_checkLiableAssociation($patternName, $fieldsValidate);
|
||||
$usedKeyList[] = $patternName;
|
||||
}
|
||||
else
|
||||
$this->_errorFormatList[] = Tools::displayError('This key is used too many times (once allowed').
|
||||
': '.$patternName;
|
||||
}
|
||||
}
|
||||
$this->format = $cleanedContent;
|
||||
}
|
||||
return (count($this->_errorFormatList)) ? false : true;
|
||||
}
|
||||
|
||||
@@ -228,6 +229,61 @@ class AddressFormatCore extends ObjectModel
|
||||
return $this->_errorFormatList;
|
||||
}
|
||||
|
||||
/*
|
||||
** Set the layout key with the liable value
|
||||
** example : (firstname) => 'Presta' will result (Presta)
|
||||
** : (firstname-lastname) => 'Presta' and 'Shop' result '(Presta-Shop)'
|
||||
*/
|
||||
private static function _setOriginalDisplayFormat(&$formattedValueList, $currentLine, $currentKeyList)
|
||||
{
|
||||
if ($currentKeyList && is_array($currentKeyList))
|
||||
if ($originalFormattedPatternList = explode(' ', $currentLine))
|
||||
// Foreach the available pattern
|
||||
foreach($originalFormattedPatternList as $patternNum => $pattern)
|
||||
{
|
||||
// Var allows to modify the good formatted key value when multiple key exist into the same pattern
|
||||
$mainFormattedKey = '';
|
||||
|
||||
// Multiple key can be found in the same pattern
|
||||
foreach($currentKeyList as $key)
|
||||
{
|
||||
// Check if we need to use an older modified pattern if a key has already be matched before
|
||||
$replacedValue = empty($mainFormattedKey) ? $pattern : $formattedValueList[$mainFormattedKey];
|
||||
if (($formattedValue = preg_replace('/'.$key.'/', $formattedValueList[$key], $replacedValue, -1, $count)))
|
||||
if ($count)
|
||||
{
|
||||
// Allow to check multiple key in the same pattern,
|
||||
if (empty($mainFormattedKey))
|
||||
$mainFormattedKey = $key;
|
||||
// Set the pattern value to an empty string if an older key has already been matched before
|
||||
if ($mainFormattedKey != $key)
|
||||
$formattedValueList[$key] = '';
|
||||
// Store the new pattern value
|
||||
$formattedValueList[$mainFormattedKey] = $formattedValue;
|
||||
unset($originalFormattedPatternList[$patternNum]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Cleaned the layout set by the user
|
||||
*/
|
||||
public static function cleanOrderedAddress(&$orderedAddressField)
|
||||
{
|
||||
foreach($orderedAddressField as &$line)
|
||||
{
|
||||
$cleanedLine = '';
|
||||
if (($keyList = preg_split(self::_CLEANING_REGEX_, $line, -1, PREG_SPLIT_NO_EMPTY)))
|
||||
{
|
||||
foreach($keyList as $key)
|
||||
$cleanedLine .= $key.' ';
|
||||
$cleanedLine = trim($cleanedLine);
|
||||
$line = $cleanedLine;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the formatted fields with associated values
|
||||
*
|
||||
@@ -244,9 +300,10 @@ class AddressFormatCore extends ObjectModel
|
||||
|
||||
// Check if $address exist and it's an instanciate object of Address
|
||||
if ($address && ($address instanceof Address))
|
||||
foreach($addressFormat as $lineNum => $line)
|
||||
foreach($addressFormat as $line)
|
||||
{
|
||||
if (($keyList = explode(' ', $line)) && is_array($keyList))
|
||||
if (($keyList = preg_split(self::_CLEANING_REGEX_, $line, -1, PREG_SPLIT_NO_EMPTY)) && is_array($keyList))
|
||||
{
|
||||
foreach($keyList as $pattern)
|
||||
if ($associateName = explode(':', $pattern))
|
||||
{
|
||||
@@ -274,9 +331,12 @@ class AddressFormatCore extends ObjectModel
|
||||
}
|
||||
}
|
||||
}
|
||||
self::_setOriginalDisplayFormat($tab, $line, $keyList);
|
||||
}
|
||||
}
|
||||
self::cleanOrderedAddress($addressFormat);
|
||||
// Free the instanciate objects
|
||||
foreach($temporyObject as $objectName => &$object)
|
||||
foreach($temporyObject as &$object)
|
||||
unset($object);
|
||||
return $tab;
|
||||
}
|
||||
@@ -295,7 +355,7 @@ class AddressFormatCore extends ObjectModel
|
||||
|
||||
$addressText = '';
|
||||
foreach ($addressFields as $line)
|
||||
if (($patternsList = explode(' ', $line)))
|
||||
if (($patternsList = preg_split(self::_CLEANING_REGEX_, $line, -1, PREG_SPLIT_NO_EMPTY)))
|
||||
{
|
||||
$tmpText = '';
|
||||
foreach($patternsList as $pattern)
|
||||
@@ -328,8 +388,8 @@ class AddressFormatCore extends ObjectModel
|
||||
foreach($publicProperties as $property)
|
||||
{
|
||||
$propertyName = $property->getName();
|
||||
if ((!in_array($propertyName, AddressFormat::$forbiddenProperyList)) &&
|
||||
(!preg_match('#id|id_\w#', $propertyName, $match)))
|
||||
if ((!in_array($propertyName, AddressFormat::$forbiddenPropertyList)) &&
|
||||
(!preg_match('#id|id_\w#', $propertyName)))
|
||||
$propertyList[] = $propertyName;
|
||||
}
|
||||
unset($object);
|
||||
@@ -355,7 +415,7 @@ class AddressFormatCore extends ObjectModel
|
||||
foreach($publicProperties as $property)
|
||||
{
|
||||
$propertyName = $property->getName();
|
||||
if (preg_match('#id_\w#', $propertyName, $match) && strlen($propertyName) > 3)
|
||||
if (preg_match('#id_\w#', $propertyName) && strlen($propertyName) > 3)
|
||||
{
|
||||
$nameObject = ucfirst(substr($propertyName, 3));
|
||||
if (!in_array($nameObject, self::$forbiddenClassList) &&
|
||||
@@ -375,19 +435,41 @@ class AddressFormatCore extends ObjectModel
|
||||
* @param Integer PS_COUNTRY.id if null using default country
|
||||
* @return Array String field address format
|
||||
*/
|
||||
public static function getOrderedAddressFields($id_country = 0, $split_all = false)
|
||||
public static function getOrderedAddressFields($id_country = 0, $split_all = false, $cleaned = false)
|
||||
{
|
||||
$out = array();
|
||||
$field_set = explode("\n", self::getAddressCountryFormat($id_country));
|
||||
foreach ($field_set as $field_item)
|
||||
if ($split_all)
|
||||
foreach(explode(' ',$field_item) as $word_item)
|
||||
{
|
||||
if ($cleaned)
|
||||
$keyList = ($cleaned) ? preg_split(self::_CLEANING_REGEX_, $field_item, -1, PREG_SPLIT_NO_EMPTY) :
|
||||
explode(' ', $field_item);
|
||||
foreach($keyList as $word_item)
|
||||
$out[] = trim($word_item);
|
||||
}
|
||||
else
|
||||
$out[] = trim($field_item);
|
||||
$out[] = ($cleaned) ? implode(' ', preg_split(self::_CLEANING_REGEX_, trim($field_item), -1, PREG_SPLIT_NO_EMPTY))
|
||||
: trim($field_item);
|
||||
return $out;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return a data array containing ordered, formatedValue and object fields
|
||||
*/
|
||||
public static function getFormattedLayoutData($address)
|
||||
{
|
||||
$layoutData = array();
|
||||
|
||||
if ($address && $address instanceof Address)
|
||||
{
|
||||
$layoutData['ordered'] = AddressFormat::getOrderedAddressFields((int)$address->id_country);
|
||||
$layoutData['formated'] = AddressFormat::getFormattedAddressFieldsValues($address, $layoutData['ordered']);
|
||||
$layoutData['object'] = get_object_vars($address);
|
||||
}
|
||||
return $layoutData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns address format by country if not defined using default country
|
||||
*
|
||||
@@ -399,11 +481,6 @@ class AddressFormatCore extends ObjectModel
|
||||
$out = '';
|
||||
$id_country = (int) $id_country;
|
||||
|
||||
if ($id_country <= 0)
|
||||
{
|
||||
$selectedCountry = (int)(Configuration::get('PS_COUNTRY_DEFAULT'));
|
||||
}
|
||||
|
||||
$tmp_obj = new AddressFormat();
|
||||
$tmp_obj->id_country = $id_country;
|
||||
$out = $tmp_obj->getFormat($tmp_obj->id_country);
|
||||
|
||||
+40
-9
@@ -159,10 +159,11 @@ abstract class AdminTabCore
|
||||
protected $_includeVars = false;
|
||||
protected $_includeContainer = true;
|
||||
|
||||
public $ajax = false;
|
||||
|
||||
public static $tabParenting = array(
|
||||
'AdminProducts' => 'AdminCatalog',
|
||||
'AdminCategories' => 'AdminCatalog',
|
||||
'AdminImageResize' => 'AdminImages',
|
||||
'AdminCMS' => 'AdminCMSContent',
|
||||
'AdminCMSCategories' => 'AdminCMSContent',
|
||||
'AdminOrdersStates' => 'AdminStatuses',
|
||||
@@ -233,6 +234,14 @@ abstract class AdminTabCore
|
||||
return str_replace('"', '"', ($addslashes ? addslashes($str) : stripslashes($str)));
|
||||
}
|
||||
|
||||
/**
|
||||
* ajaxDisplay is the default ajax return sytem
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function displayAjax()
|
||||
{
|
||||
}
|
||||
/**
|
||||
* Manage page display (form, list...)
|
||||
*/
|
||||
@@ -433,7 +442,7 @@ abstract class AdminTabCore
|
||||
|
||||
/* Checking for multilingual required fields */
|
||||
foreach ($rules['requiredLang'] AS $fieldLang)
|
||||
if (($empty = Tools::getValue($fieldLang.'_'.$defaultLanguage->id)) === false OR empty($empty))
|
||||
if (($empty = Tools::getValue($fieldLang.'_'.$defaultLanguage->id)) === false OR $empty !== '0' AND empty($empty))
|
||||
$this->_errors[] = $this->l('the field').' <b>'.call_user_func(array($className, 'displayFieldName'), $fieldLang, $className).'</b> '.$this->l('is required at least in').' '.$defaultLanguage->name;
|
||||
|
||||
/* Checking for maximum fields sizes */
|
||||
@@ -506,6 +515,24 @@ abstract class AdminTabCore
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* ajaxPreProcess is a method called in ajax-tab.php before displayConf().
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function ajaxPreProcess()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* ajaxProcess is the default handle method for request with ajax-tab.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function ajaxProcess()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage page processing
|
||||
*/
|
||||
@@ -1013,7 +1040,7 @@ abstract class AdminTabCore
|
||||
{
|
||||
$languages = Language::getLanguages(false);
|
||||
foreach ($languages AS $language)
|
||||
foreach ($rules['validateLang'] AS $field => $validation)
|
||||
foreach (array_keys($rules['validateLang']) AS $field)
|
||||
if (isset($_POST[$field.'_'.(int)($language['id_lang'])]))
|
||||
$object->{$field}[(int)($language['id_lang'])] = $_POST[$field.'_'.(int)($language['id_lang'])];
|
||||
}
|
||||
@@ -1107,9 +1134,9 @@ abstract class AdminTabCore
|
||||
public function displayConf()
|
||||
{
|
||||
if ($conf = Tools::getValue('conf'))
|
||||
echo '<div class="conf">
|
||||
<img src="../img/admin/ok2.png" />
|
||||
'.$this->_conf[(int)($conf)].'
|
||||
echo '
|
||||
<div class="conf">
|
||||
<img src="../img/admin/ok2.png" alt="" /> '.$this->_conf[(int)($conf)].'
|
||||
</div>';
|
||||
}
|
||||
|
||||
@@ -1259,6 +1286,7 @@ abstract class AdminTabCore
|
||||
echo '<form method="post" action="'.self::$currentIndex;
|
||||
if(Tools::getIsset($this->identifier))
|
||||
echo '&'.$this->identifier.'='.(int)(Tools::getValue($this->identifier));
|
||||
echo '&token='.$token;
|
||||
if (Tools::getIsset($this->table.'Orderby'))
|
||||
echo '&'.$this->table.'Orderby='.urlencode($this->_orderBy).'&'.$this->table.'Orderway='.urlencode(strtolower($this->_orderWay));
|
||||
echo '#'.$this->table.'" class="form">
|
||||
@@ -1313,7 +1341,7 @@ abstract class AdminTabCore
|
||||
<script type="text/javascript" src="../js/admin-dnd.js"></script>
|
||||
';
|
||||
}
|
||||
echo '<table'.(array_key_exists($this->identifier,$this->identifiersDnd) ? ' id="'.(($id_category = (int)(Tools::getValue($this->identifiersDnd[$this->identifier], 1))) ? substr($this->identifier,3,strlen($this->identifier)) : '').'"' : '' ).' class="table'.((array_key_exists($this->identifier,$this->identifiersDnd) AND ($this->_orderBy != 'position 'AND $this->_orderWay != 'DESC')) ? ' tableDnD' : '' ).'" cellpadding="0" cellspacing="0">
|
||||
echo '<table'.(array_key_exists($this->identifier,$this->identifiersDnd) ? ' id="'.(((int)(Tools::getValue($this->identifiersDnd[$this->identifier], 1))) ? substr($this->identifier,3,strlen($this->identifier)) : '').'"' : '' ).' class="table'.((array_key_exists($this->identifier,$this->identifiersDnd) AND ($this->_orderBy != 'position 'AND $this->_orderWay != 'DESC')) ? ' tableDnD' : '' ).'" cellpadding="0" cellspacing="0">
|
||||
<thead>
|
||||
<tr class="nodrag nodrop">
|
||||
<th>';
|
||||
@@ -1485,7 +1513,7 @@ abstract class AdminTabCore
|
||||
if (preg_match('/cms/Ui', $this->identifier))
|
||||
$isCms = true;
|
||||
$keyToGet = 'id_'.($isCms ? 'cms_' : '').'category'.(in_array($this->identifier, array('id_category', 'id_cms_category')) ? '_parent' : '');
|
||||
foreach ($this->_list AS $i => $tr)
|
||||
foreach ($this->_list AS $tr)
|
||||
{
|
||||
$id = $tr[$this->identifier];
|
||||
echo '<tr'.(array_key_exists($this->identifier,$this->identifiersDnd) ? ' id="tr_'.(($id_category = (int)(Tools::getValue('id_'.($isCms ? 'cms_' : '').'category', '1'))) ? $id_category : '').'_'.$id.'_'.$tr['position'].'"' : '').($irow++ % 2 ? ' class="alt_row"' : '').' '.((isset($tr['color']) AND $this->colorOnBackground) ? 'style="background-color: '.$tr['color'].'"' : '').'>
|
||||
@@ -1934,7 +1962,6 @@ abstract class AdminTabCore
|
||||
{
|
||||
if (sizeof($languages) == 1)
|
||||
return false;
|
||||
$defaultIso = Language::getIsoById($defaultLanguage);
|
||||
$output = '
|
||||
<div class="displayed_flag">
|
||||
<img src="../img/l/'.$defaultLanguage.'.jpg" class="pointer" id="language_current_'.$id.'" onclick="toggleLanguageFlags(this);" alt="" />
|
||||
@@ -2162,6 +2189,10 @@ abstract class AdminTabCore
|
||||
|
||||
if ($this->validateField(Tools::getValue($key), $options))
|
||||
{
|
||||
// check if a method updateOptionFieldName is available
|
||||
$method_name = 'updateOption'.Tools::toCamelCase($key, true);
|
||||
if (method_exists($this, $method_name))
|
||||
$this->$method_name(Tools::getValue($key));
|
||||
if (isset($options['type']) && in_array($options['type'], array('textLang', 'textareaLang')))
|
||||
{
|
||||
$list = array();
|
||||
|
||||
@@ -63,14 +63,6 @@ class AliasCore extends ObjectModel
|
||||
}
|
||||
}
|
||||
|
||||
static public function deleteAliases($search)
|
||||
{
|
||||
return Db::getInstance()->Execute('
|
||||
DELETE
|
||||
FROM `'._DB_PREFIX_.'alias`
|
||||
WHERE `search` LIKE \''.pSQL($search).'\'');
|
||||
}
|
||||
|
||||
public function getAliases()
|
||||
{
|
||||
$aliases = Db::getInstance()->ExecuteS('
|
||||
|
||||
+20
-1
@@ -37,7 +37,7 @@ class AttachmentCore extends ObjectModel
|
||||
public $position;
|
||||
|
||||
protected $fieldsRequired = array('file', 'mime');
|
||||
protected $fieldsSize = array('file' => 40, 'mime' => 64, 'file_name' => 128);
|
||||
protected $fieldsSize = array('file' => 40, 'mime' => 128, 'file_name' => 128);
|
||||
protected $fieldsValidate = array('file' => 'isGenericName', 'mime' => 'isCleanHtml', 'file_name' => 'isGenericName');
|
||||
|
||||
protected $fieldsRequiredLang = array('name');
|
||||
@@ -102,5 +102,24 @@ class AttachmentCore extends ObjectModel
|
||||
}
|
||||
return $result1;
|
||||
}
|
||||
|
||||
public static function getProductAttached($id_lang, $list)
|
||||
{
|
||||
$ids_attachements = array();
|
||||
if (is_array($list))
|
||||
{
|
||||
foreach($list as $attachement)
|
||||
$ids_attachements[] = $attachement['id_attachment'];
|
||||
$tmp = Db::getInstance()->executeS('SELECT * FROM `'._DB_PREFIX_.'product_attachment` pa
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (pa.`id_product` = pl.`id_product`)
|
||||
WHERE `id_attachment` IN ('.implode(',', array_map('intval', $ids_attachements)).') AND pl.`id_lang` = '.(int)$id_lang.';');
|
||||
$productAttachements = array();
|
||||
foreach($tmp as $t)
|
||||
$productAttachements[$t['id_attachment']][] = $t['name'];
|
||||
return $productAttachements;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ class AttributeCore extends ObjectModel
|
||||
* @param boolean $notNull Get only not null fields if true
|
||||
* @return array Attributes
|
||||
*/
|
||||
static public function getAttributes($id_lang, $notNull = false)
|
||||
public static function getAttributes($id_lang, $notNull = false)
|
||||
{
|
||||
return Db::getInstance()->ExecuteS('
|
||||
SELECT ag.*, agl.*, a.`id_attribute`, al.`name`, agl.`name` AS `attribute_group`
|
||||
@@ -139,7 +139,7 @@ class AttributeCore extends ObjectModel
|
||||
* @param integer $id_product
|
||||
* @return mixed Quantity or false
|
||||
*/
|
||||
static public function getAttributeQty($id_product)
|
||||
public static function getAttributeQty($id_product)
|
||||
{
|
||||
Tools::displayAsDeprecated();
|
||||
|
||||
@@ -160,7 +160,7 @@ class AttributeCore extends ObjectModel
|
||||
* @param array &$arr
|
||||
* return bool
|
||||
*/
|
||||
static public function updateQtyProduct(&$arr)
|
||||
public static function updateQtyProduct(&$arr)
|
||||
{
|
||||
Tools::displayAsDeprecated();
|
||||
|
||||
@@ -192,7 +192,7 @@ class AttributeCore extends ObjectModel
|
||||
* @param integer $id_product_attribute
|
||||
* @return mixed Minimal Quantity or false
|
||||
*/
|
||||
static public function getAttributeMinimalQty($id_product_attribute)
|
||||
public static function getAttributeMinimalQty($id_product_attribute)
|
||||
{
|
||||
$minimal_quantity = Db::getInstance()->getValue('
|
||||
SELECT `minimal_quantity`
|
||||
|
||||
@@ -81,7 +81,7 @@ class AttributeGroupCore extends ObjectModel
|
||||
return parent::getTranslationsFields(array('name', 'public_name'));
|
||||
}
|
||||
|
||||
static public function cleanDeadCombinations()
|
||||
public static function cleanDeadCombinations()
|
||||
{
|
||||
$attributeCombinations = Db::getInstance()->ExecuteS('SELECT pac.`id_attribute`, pa.`id_product_attribute` FROM `'._DB_PREFIX_.'product_attribute` pa LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` pac ON (pa.`id_product_attribute` = pac.`id_product_attribute`)');
|
||||
$toRemove = array();
|
||||
@@ -121,7 +121,7 @@ class AttributeGroupCore extends ObjectModel
|
||||
* @param boolean $id_attribute_group Attribute group id
|
||||
* @return array Attributes
|
||||
*/
|
||||
static public function getAttributes($id_lang, $id_attribute_group)
|
||||
public static function getAttributes($id_lang, $id_attribute_group)
|
||||
{
|
||||
return Db::getInstance()->ExecuteS('
|
||||
SELECT *
|
||||
@@ -137,7 +137,7 @@ class AttributeGroupCore extends ObjectModel
|
||||
* @param integer $id_lang Language id
|
||||
* @return array Attributes groups
|
||||
*/
|
||||
static public function getAttributesGroups($id_lang)
|
||||
public static function getAttributesGroups($id_lang)
|
||||
{
|
||||
return Db::getInstance()->ExecuteS('
|
||||
SELECT *
|
||||
|
||||
+49
-4
@@ -31,6 +31,10 @@ class BackupCore
|
||||
public $id;
|
||||
/** @var string Last error messages */
|
||||
public $error;
|
||||
/** @var string default backup directory. */
|
||||
public static $backupDir = '/backups/';
|
||||
/** @var string custom backup directory. */
|
||||
public $customBackupDir = NULL;
|
||||
|
||||
/**
|
||||
* Creates a new backup object
|
||||
@@ -40,24 +44,65 @@ class BackupCore
|
||||
public function __construct($filename = NULL)
|
||||
{
|
||||
if ($filename)
|
||||
$this->id = self::getBackupPath($filename);
|
||||
$this->id = $this->getRealBackupPath($filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* you can set a different path with that function
|
||||
*
|
||||
* @TODO include the prefix name
|
||||
* @param string $dir
|
||||
* @return boolean bo
|
||||
*/
|
||||
public function setCustomBackupPath($dir)
|
||||
{
|
||||
$customDir = DIRECTORY_SEPARATOR.trim($dir,'/').DIRECTORY_SEPARATOR;
|
||||
if(is_dir(_PS_ADMIN_DIR_.DIRECTORY_SEPARATOR.$customDir.DIRECTORY_SEPARATOR))
|
||||
$this->customBackupDir = $customDir;
|
||||
else
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* get the path to use for backup (customBackupDir if specified, or default)
|
||||
*
|
||||
* @param string $filename filename to use
|
||||
* @return string full path
|
||||
*/
|
||||
public function getRealBackupPath($filename = NULL)
|
||||
{
|
||||
$backupDir = Backup::getBackupPath($filename);
|
||||
if (!empty($this->customBackupDir))
|
||||
{
|
||||
$backupDir = str_replace(_PS_ADMIN_DIR_.self::$backupDir, _PS_ADMIN_DIR_.$this->customBackupDir, $backupDir);
|
||||
|
||||
if(strrpos($backupDir,DIRECTORY_SEPARATOR))
|
||||
$backupDir .= DIRECTORY_SEPARATOR;
|
||||
}
|
||||
return $backupDir;
|
||||
}
|
||||
/**
|
||||
* Get the full path of the backup file
|
||||
*
|
||||
* @param string $filename Filename of the backup file
|
||||
* @param string $filename prefix of the backup file (datetime will be the second part)
|
||||
* @return The full path of the backup file, or false if the backup file does not exists
|
||||
*/
|
||||
public static function getBackupPath($filename)
|
||||
{
|
||||
$backupdir = realpath(PS_ADMIN_DIR.'/backups/');
|
||||
$backupdir = realpath(_PS_ADMIN_DIR_.self::$backupDir);
|
||||
|
||||
if ($backupdir === false)
|
||||
die(Tools::displayError('Backups directory does not exist.'));
|
||||
|
||||
// Check the realpath so we can validate the backup file is under the backup directory
|
||||
if(!empty($filename))
|
||||
$backupfile = realpath($backupdir.'/'.$filename);
|
||||
else
|
||||
$backupfile = $backupdir.DIRECTORY_SEPARATOR;
|
||||
|
||||
if ($backupfile === false OR strncmp($backupdir, $backupfile, strlen($backupdir)) != 0)
|
||||
die (Tools::displayError());
|
||||
|
||||
@@ -132,7 +177,7 @@ class BackupCore
|
||||
// Generate some random number, to make it extra hard to guess backup file names
|
||||
$rand = dechex ( mt_rand(0, min(0xffffffff, mt_getrandmax() ) ) );
|
||||
$date = time();
|
||||
$backupfile = PS_ADMIN_DIR . '/backups/' . $date . '-' . $rand . '.sql';
|
||||
$backupfile = $this->getRealBackupPath().$date.'-'.$rand.'.sql';
|
||||
|
||||
// Figure out what compression is available and open the file
|
||||
if (function_exists('bzopen'))
|
||||
|
||||
+3
-3
@@ -175,7 +175,7 @@ class CMSCore extends ObjectModel
|
||||
AND `id_cms_category`='.(int)($movedCms['id_cms_category'])));
|
||||
}
|
||||
|
||||
static public function cleanPositions($id_category)
|
||||
public static function cleanPositions($id_category)
|
||||
{
|
||||
$result = Db::getInstance()->ExecuteS('
|
||||
SELECT `id_cms`
|
||||
@@ -194,12 +194,12 @@ class CMSCore extends ObjectModel
|
||||
return true;
|
||||
}
|
||||
|
||||
static public function getLastPosition($id_category)
|
||||
public static function getLastPosition($id_category)
|
||||
{
|
||||
return (Db::getInstance()->getValue('SELECT MAX(position)+1 FROM `'._DB_PREFIX_.'cms` WHERE `id_cms_category` = '.(int)($id_category)));
|
||||
}
|
||||
|
||||
static public function getCMSPages($id_lang = NULL, $id_cms_category = NULL, $active = true)
|
||||
public static function getCMSPages($id_lang = NULL, $id_cms_category = NULL, $active = true)
|
||||
{
|
||||
return Db::getInstance()->ExecuteS('
|
||||
SELECT *
|
||||
|
||||
+32
-11
@@ -218,14 +218,14 @@ class CMSCategoryCore extends ObjectModel
|
||||
return $category;
|
||||
}
|
||||
|
||||
static public function recurseCMSCategory($categories, $current, $id_cms_category = 1, $id_selected = 1, $is_html = 0)
|
||||
public static function recurseCMSCategory($categories, $current, $id_cms_category = 1, $id_selected = 1, $is_html = 0)
|
||||
{
|
||||
$html = '<option value="'.$id_cms_category.'"'.(($id_selected == $id_cms_category) ? ' selected="selected"' : '').'>'.
|
||||
str_repeat(' ', $current['infos']['level_depth'] * 5).self::hideCMSCategoryPosition(stripslashes($current['infos']['name'])).'</option>';
|
||||
if ($is_html == 0)
|
||||
echo $html;
|
||||
if (isset($categories[$id_cms_category]))
|
||||
foreach ($categories[$id_cms_category] AS $key => $row)
|
||||
foreach (array_keys($categories[$id_cms_category]) AS $key)
|
||||
$html .= self::recurseCMSCategory($categories, $categories[$id_cms_category][$key], $key, $id_selected, $is_html);
|
||||
return $html;
|
||||
}
|
||||
@@ -247,7 +247,7 @@ class CMSCategoryCore extends ObjectModel
|
||||
SELECT `id_cms_category`
|
||||
FROM `'._DB_PREFIX_.'cms_category`
|
||||
WHERE `id_parent` = '.(int)($id_cms_category));
|
||||
foreach ($result AS $k => $row)
|
||||
foreach ($result AS $row)
|
||||
{
|
||||
$toDelete[] = (int)($row['id_cms_category']);
|
||||
$this->recursiveDelete($toDelete, (int)($row['id_cms_category']));
|
||||
@@ -322,7 +322,7 @@ class CMSCategoryCore extends ObjectModel
|
||||
* @param boolean $active return only active categories
|
||||
* @return array Categories
|
||||
*/
|
||||
static public function getCategories($id_lang, $active = true, $order = true)
|
||||
public static function getCategories($id_lang, $active = true, $order = true)
|
||||
{
|
||||
if (!Validate::isBool($active))
|
||||
die(Tools::displayError());
|
||||
@@ -344,7 +344,7 @@ class CMSCategoryCore extends ObjectModel
|
||||
return $categories;
|
||||
}
|
||||
|
||||
static public function getSimpleCategories($id_lang)
|
||||
public static function getSimpleCategories($id_lang)
|
||||
{
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
||||
SELECT c.`id_cms_category`, cl.`name`
|
||||
@@ -389,7 +389,7 @@ class CMSCategoryCore extends ObjectModel
|
||||
* @param string $name CMSCategory name
|
||||
* @return string Name without position
|
||||
*/
|
||||
static public function hideCMSCategoryPosition($name)
|
||||
public static function hideCMSCategoryPosition($name)
|
||||
{
|
||||
return preg_replace('/^[0-9]+\./', '', $name);
|
||||
}
|
||||
@@ -401,12 +401,12 @@ class CMSCategoryCore extends ObjectModel
|
||||
* @param boolean $active return only active categories
|
||||
* @return array categories
|
||||
*/
|
||||
static public function getHomeCategories($id_lang, $active = true)
|
||||
public static function getHomeCategories($id_lang, $active = true)
|
||||
{
|
||||
return self::getChildren(1, $id_lang, $active);
|
||||
}
|
||||
|
||||
static public function getChildren($id_parent, $id_lang, $active = true)
|
||||
public static function getChildren($id_parent, $id_lang, $active = true)
|
||||
{
|
||||
if (!Validate::isBool($active))
|
||||
die(Tools::displayError());
|
||||
@@ -500,7 +500,7 @@ class CMSCategoryCore extends ObjectModel
|
||||
* @param boolean $unrestricted allows search without lang and includes first CMSCategory and exact match
|
||||
* @return array Corresponding categories
|
||||
*/
|
||||
static public function searchByName($id_lang, $query, $unrestricted = false)
|
||||
public static function searchByName($id_lang, $query, $unrestricted = false)
|
||||
{
|
||||
if ($unrestricted === true)
|
||||
return Db::getInstance()->getRow('
|
||||
@@ -516,6 +516,27 @@ class CMSCategoryCore extends ObjectModel
|
||||
WHERE `name` LIKE \'%'.pSQL($query).'%\' AND c.`id_cms_category` != 1');
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve CMSCategory by name and parent CMSCategory id
|
||||
*
|
||||
* @param integer $id_lang Language ID
|
||||
* @param string $CMSCategory_name Searched CMSCategory name
|
||||
* @param integer $id_parent_CMSCategory parent CMSCategory ID
|
||||
* @return array Corresponding CMSCategory
|
||||
* @deprecated
|
||||
*/
|
||||
public static function searchByNameAndParentCMSCategoryId($id_lang, $CMSCategory_name, $id_parent_CMSCategory)
|
||||
{
|
||||
Tools::displayAsDeprecated();
|
||||
return Db::getInstance()->getRow('
|
||||
SELECT c.*, cl.*
|
||||
FROM `'._DB_PREFIX_.'cms_category` c
|
||||
LEFT JOIN `'._DB_PREFIX_.'cms_category_lang` cl ON (c.`id_cms_category` = cl.`id_cms_category` AND `id_lang` = '.(int)($id_lang).')
|
||||
WHERE `name` LIKE \''.pSQL($CMSCategory_name).'\'
|
||||
AND c.`id_cms_category` != 1
|
||||
AND c.`id_parent` = '.(int)($id_parent_CMSCategory));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Each parent CMSCategory of this CMSCategory until the root CMSCategory
|
||||
*
|
||||
@@ -578,7 +599,7 @@ class CMSCategoryCore extends ObjectModel
|
||||
AND `id_cms_category`='.(int)($movedCategory['id_cms_category'])));
|
||||
}
|
||||
|
||||
static public function cleanPositions($id_category_parent)
|
||||
public static function cleanPositions($id_category_parent)
|
||||
{
|
||||
$result = Db::getInstance()->ExecuteS('
|
||||
SELECT `id_cms_category`
|
||||
@@ -597,7 +618,7 @@ class CMSCategoryCore extends ObjectModel
|
||||
return true;
|
||||
}
|
||||
|
||||
static public function getLastPosition($id_category_parent)
|
||||
public static function getLastPosition($id_category_parent)
|
||||
{
|
||||
return (Db::getInstance()->getValue('SELECT MAX(position)+1 FROM `'._DB_PREFIX_.'cms_category` WHERE `id_parent` = '.(int)($id_category_parent)));
|
||||
}
|
||||
|
||||
+1
-1
@@ -133,7 +133,7 @@ class CacheFSCore extends Cache {
|
||||
foreach ($res[1] AS $table)
|
||||
if (isset($this->_tablesCached[$table]))
|
||||
{
|
||||
foreach ($this->_tablesCached[$table] AS $fsKey => $foo)
|
||||
foreach (array_keys($this->_tablesCached[$table]) AS $fsKey)
|
||||
{
|
||||
$this->delete($fsKey);
|
||||
$this->delete($fsKey.'_nrows');
|
||||
|
||||
+2
-2
@@ -143,7 +143,7 @@ class CarrierCore extends ObjectModel
|
||||
{
|
||||
if (!parent::add($autodate, $nullValues) OR !Validate::isLoadedObject($this))
|
||||
return false;
|
||||
if (!$result = Db::getInstance()->ExecuteS('SELECT `id_carrier` FROM `'._DB_PREFIX_.$this->table.'` WHERE `deleted` = 0'))
|
||||
if (!Db::getInstance()->ExecuteS('SELECT `id_carrier` FROM `'._DB_PREFIX_.$this->table.'` WHERE `deleted` = 0'))
|
||||
return false;
|
||||
if (!$numRows = Db::getInstance()->NumRows())
|
||||
return false;
|
||||
@@ -432,7 +432,7 @@ class CarrierCore extends ObjectModel
|
||||
{
|
||||
// Get id zone
|
||||
if (!$id_zone)
|
||||
$id_zone = (int)$defaultCountry->id_zone;
|
||||
$id_zone = Country::getIdZone(Country::getDefaultCountryId());
|
||||
|
||||
// Get only carriers that have a range compatible with cart
|
||||
if (($shippingMethod == Carrier::SHIPPING_METHOD_WEIGHT AND (!Carrier::checkDeliveryPriceByWeight($row['id_carrier'], $cart->getTotalWeight(), $id_zone)))
|
||||
|
||||
+51
-32
@@ -219,7 +219,7 @@ class CartCore extends ObjectModel
|
||||
return parent::delete();
|
||||
}
|
||||
|
||||
static public function getTaxesAverageUsed($id_cart)
|
||||
public static function getTaxesAverageUsed($id_cart)
|
||||
{
|
||||
$cart = new Cart((int)($id_cart));
|
||||
if (!Validate::isLoadedObject($cart))
|
||||
@@ -357,7 +357,7 @@ class CartCore extends ObjectModel
|
||||
pl.`description_short`, pl.`available_now`, pl.`available_later`, p.`id_product`, p.`id_category_default`, p.`id_supplier`, p.`id_manufacturer`, p.`on_sale`, p.`ecotax`, p.`additional_shipping_cost`, p.`available_for_order`,
|
||||
p.`price`, p.`weight`, p.`width`, p.`height`, p.`depth`, p.`out_of_stock`, p.`active`, p.`date_add`, p.`date_upd`, IFNULL(pa.`minimal_quantity`, p.`minimal_quantity`) as minimal_quantity,
|
||||
t.`id_tax`, tl.`name` AS tax, t.`rate`, pa.`price` AS price_attribute, stock.quantity,
|
||||
pa.`ecotax` AS ecotax_attr, i.`id_image`, il.`legend`, pl.`link_rewrite`, cl.`link_rewrite` AS category, CONCAT(cp.`id_product`, cp.`id_product_attribute`) AS unique_id,
|
||||
pa.`ecotax` AS ecotax_attr, pl.`link_rewrite`, cl.`link_rewrite` AS category, CONCAT(cp.`id_product`, cp.`id_product_attribute`) AS unique_id,
|
||||
IF (IFNULL(pa.`reference`, \'\') = \'\', p.`reference`, pa.`reference`) AS reference,
|
||||
IF (IFNULL(pa.`supplier_reference`, \'\') = \'\', p.`supplier_reference`, pa.`supplier_reference`) AS supplier_reference,
|
||||
(p.`weight`+ pa.`weight`) weight_attribute,
|
||||
@@ -374,17 +374,6 @@ class CartCore extends ObjectModel
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax_lang` tl ON (t.`id_tax` = tl.`id_tax` AND tl.`id_lang` = '.(int)$this->id_lang.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'customization` cu ON (p.`id_product` = cu.`id_product`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_attribute_image` pai ON (pai.`id_product_attribute` = pa.`id_product_attribute`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'image` i ON (IF(pai.`id_image`,
|
||||
i.`id_image` =
|
||||
(SELECT i2.`id_image`
|
||||
FROM `'._DB_PREFIX_.'image` i2
|
||||
INNER JOIN `'._DB_PREFIX_.'product_attribute_image` pai2 ON (pai2.`id_image` = i2.`id_image`)
|
||||
WHERE i2.`id_product` = p.`id_product` AND pai2.`id_product_attribute` = pa.`id_product_attribute`
|
||||
ORDER BY i2.`position`
|
||||
LIMIT 1),
|
||||
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)$this->id_lang.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (p.`id_category_default` = cl.`id_category` AND cl.`id_lang` = '.(int)$this->id_lang.')
|
||||
'.Product::sqlStock('cp', 'cp').'
|
||||
WHERE cp.`id_cart` = '.(int)$this->id.'
|
||||
@@ -409,7 +398,7 @@ class CartCore extends ObjectModel
|
||||
$this->_products = array();
|
||||
if (empty($result))
|
||||
return array();
|
||||
foreach ($result AS $k => $row)
|
||||
foreach ($result AS $row)
|
||||
{
|
||||
if (isset($row['ecotax_attr']) AND $row['ecotax_attr'] > 0)
|
||||
$row['ecotax'] = (float)($row['ecotax_attr']);
|
||||
@@ -439,7 +428,27 @@ class CartCore extends ObjectModel
|
||||
$row['total_wt'] = $row['price_wt'] * (int)($row['cart_quantity']);
|
||||
$row['total'] = Tools::ps_round($row['price'] * (int)($row['cart_quantity']), 2);
|
||||
}
|
||||
$row['reduction_applies'] = $specificPriceOutput AND (float)($specificPriceOutput['reduction']);
|
||||
|
||||
$row2 = Db::getInstance()->getRow('
|
||||
SELECT i.`id_image`, il.`legend`
|
||||
FROM `'._DB_PREFIX_.'image` i
|
||||
LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$this->id_lang.')
|
||||
WHERE '.((isset($row['`pai_id_image`']) AND $row['`pai_id_image`'])
|
||||
? 'i.`id_image` = (
|
||||
SELECT i2.`id_image`
|
||||
FROM `'._DB_PREFIX_.'image` i2
|
||||
INNER JOIN `'._DB_PREFIX_.'product_attribute_image` pai2 ON (pai2.`id_image` = i2.`id_image`)
|
||||
WHERE i2.`id_product` = p.`id_product` AND pai2.`id_product_attribute` = pa.`id_product_attribute`
|
||||
ORDER BY i2.`position`
|
||||
LIMIT 1
|
||||
)'
|
||||
: 'i.`id_product` = '.(int)$row['id_product'].' AND i.`cover` = 1').'
|
||||
');
|
||||
if (!$row2)
|
||||
$row2 = array('id_image' => false, 'legend' => false);
|
||||
$row = array_merge($row, $row2);
|
||||
|
||||
$row['reduction_applies'] = ($specificPriceOutput AND (float)$specificPriceOutput['reduction']);
|
||||
$row['id_image'] = Product::defineProductImage($row,$this->id_lang);
|
||||
$row['allow_oosp'] = Product::isAvailableWhenOutOfStock($row['out_of_stock']);
|
||||
$row['features'] = Product::getFeaturesStatic((int)$row['id_product']);
|
||||
@@ -454,8 +463,6 @@ class CartCore extends ObjectModel
|
||||
public static function cacheSomeAttributesLists($ipaList, $id_lang)
|
||||
{
|
||||
$paImplode = array();
|
||||
$attributesList = array();
|
||||
$attributesListSmall = array();
|
||||
foreach ($ipaList as $id_product_attribute)
|
||||
if ((int)$id_product_attribute AND !array_key_exists($id_product_attribute.'-'.$id_lang, self::$_attributesLists))
|
||||
{
|
||||
@@ -608,7 +615,7 @@ class CartCore extends ObjectModel
|
||||
else
|
||||
Db::getInstance()->Execute('
|
||||
UPDATE `'._DB_PREFIX_.'cart_product`
|
||||
SET `quantity` = `quantity` '.$qty.'
|
||||
SET `quantity` = `quantity` '.$qty.', `date_add` = NOW()
|
||||
WHERE `id_product` = '.(int)$id_product.
|
||||
(!empty($id_product_attribute) ? ' AND `id_product_attribute` = '.(int)$id_product_attribute : '').'
|
||||
AND `id_cart` = '.(int)$this->id.'
|
||||
@@ -748,7 +755,7 @@ class CartCore extends ObjectModel
|
||||
|
||||
$query = 'INSERT INTO `'._DB_PREFIX_.'customized_data` (`id_customization`, `type`, `index`, `value`) VALUES ('.(int)$id_customization.', '.(int)$type.', '.(int)$index.', \''.pSql($field).'\')';
|
||||
|
||||
if (!$result = Db::getInstance()->Execute($query))
|
||||
if (!Db::getInstance()->Execute($query))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
@@ -874,7 +881,7 @@ class CartCore extends ObjectModel
|
||||
return true;
|
||||
}
|
||||
|
||||
static public function getTotalCart($id_cart, $use_tax_display = false)
|
||||
public static function getTotalCart($id_cart, $use_tax_display = false)
|
||||
{
|
||||
$cart = new Cart((int)($id_cart));
|
||||
if (!Validate::isLoadedObject($cart))
|
||||
@@ -1103,7 +1110,6 @@ class CartCore extends ObjectModel
|
||||
else
|
||||
$result = Carrier::getCarriers((int)(Configuration::get('PS_LANG_DEFAULT')), true, false, (int)($id_zone));
|
||||
|
||||
$resultsArray = array();
|
||||
foreach ($result AS $k => $row)
|
||||
{
|
||||
if ($row['id_carrier'] == Configuration::get('PS_CARRIER_DEFAULT'))
|
||||
@@ -1232,7 +1238,10 @@ class CartCore extends ObjectModel
|
||||
{
|
||||
$moduleName = $carrier->external_module_name;
|
||||
$module = Module::getInstanceByName($moduleName);
|
||||
if (key_exists('id_carrier', $module))
|
||||
|
||||
if (Validate::isLoadedObject($module))
|
||||
{
|
||||
if (array_key_exists('id_carrier', $module))
|
||||
$module->id_carrier = $carrier->id;
|
||||
if($carrier->need_range)
|
||||
$shipping_cost = $module->getOrderShippingCost($this, $shipping_cost);
|
||||
@@ -1243,6 +1252,9 @@ class CartCore extends ObjectModel
|
||||
if ($shipping_cost === false)
|
||||
return false;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
// Apply tax
|
||||
if (isset($carrierTax))
|
||||
@@ -1327,13 +1339,13 @@ class CartCore extends ObjectModel
|
||||
|
||||
$groups = Customer::getGroupsStatic($this->id_customer);
|
||||
|
||||
if (($discountObj->id_customer OR $discountObj->id_group) AND ($this->id_customer != $discountObj->id_customer AND !in_array($discountObj->id_group, $groups)))
|
||||
if (($discountObj->id_customer OR $discountObj->id_group) AND ((($this->id_customer != $discountObj->id_customer) OR ($this->id_customer == 0)) AND !in_array($discountObj->id_group, $groups)))
|
||||
{
|
||||
if (!$customer->isLogged())
|
||||
return Tools::displayError('You cannot use this voucher.').' - '.Tools::displayError('Please log in.');
|
||||
return Tools::displayError('You cannot use this voucher.');
|
||||
}
|
||||
$currentDate = date('Y-m-d');
|
||||
|
||||
$onlyProductWithDiscount = true;
|
||||
if (!$discountObj->cumulable_reduction)
|
||||
{
|
||||
@@ -1376,6 +1388,10 @@ class CartCore extends ObjectModel
|
||||
$delivery = new Address((int)($this->id_address_delivery));
|
||||
$invoice = new Address((int)($this->id_address_invoice));
|
||||
|
||||
// New layout system with personalization fields
|
||||
$formattedAddresses['invoice'] = AddressFormat::getFormattedLayoutData($invoice);
|
||||
$formattedAddresses['delivery'] = AddressFormat::getFormattedLayoutData($delivery);
|
||||
|
||||
$total_tax = $this->getOrderTotal() - $this->getOrderTotal(false);
|
||||
|
||||
if ($total_tax < 0)
|
||||
@@ -1399,6 +1415,7 @@ class CartCore extends ObjectModel
|
||||
'delivery_state' => State::getNameById($delivery->id_state),
|
||||
'invoice' => $invoice,
|
||||
'invoice_state' => State::getNameById($invoice->id_state),
|
||||
'formattedAddresses' => $formattedAddresses,
|
||||
'carrier' => new Carrier($this->id_carrier, $id_lang),
|
||||
'products' => $this->getProducts(false),
|
||||
'discounts' => $this->getDiscounts(false, true),
|
||||
@@ -1427,7 +1444,7 @@ class CartCore extends ObjectModel
|
||||
return true;
|
||||
}
|
||||
|
||||
static public function lastNoneOrderedCart($id_customer)
|
||||
public static function lastNoneOrderedCart($id_customer)
|
||||
{
|
||||
$sql = 'SELECT c.`id_cart`
|
||||
FROM '._DB_PREFIX_.'cart c
|
||||
@@ -1470,7 +1487,7 @@ class CartCore extends ObjectModel
|
||||
return self::$_isVirtualCart[$this->id];
|
||||
}
|
||||
|
||||
static public function getCartByOrderId($id_order)
|
||||
public static function getCartByOrderId($id_order)
|
||||
{
|
||||
if ($id_cart = self::getCartIdByOrderId($id_order))
|
||||
return new Cart((int)($id_cart));
|
||||
@@ -1478,7 +1495,7 @@ class CartCore extends ObjectModel
|
||||
return false;
|
||||
}
|
||||
|
||||
static public function getCartIdByOrderId($id_order)
|
||||
public static function getCartIdByOrderId($id_order)
|
||||
{
|
||||
$result = Db::getInstance()->getRow('SELECT `id_cart` FROM '._DB_PREFIX_.'orders WHERE `id_order` = '.(int)$id_order);
|
||||
if (!$result OR empty($result) OR !key_exists('id_cart', $result))
|
||||
@@ -1563,7 +1580,7 @@ class CartCore extends ObjectModel
|
||||
return $result;
|
||||
}
|
||||
|
||||
static public function getCustomerCarts($id_customer)
|
||||
public static function getCustomerCarts($id_customer)
|
||||
{
|
||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
||||
SELECT *
|
||||
@@ -1573,7 +1590,7 @@ class CartCore extends ObjectModel
|
||||
return $result;
|
||||
}
|
||||
|
||||
static public function replaceZeroByShopName($echo, $tr)
|
||||
public static function replaceZeroByShopName($echo, $tr)
|
||||
{
|
||||
return ($echo == '0' ? Configuration::get('PS_SHOP_NAME') : $echo);
|
||||
}
|
||||
@@ -1657,8 +1674,8 @@ class CartCore extends ObjectModel
|
||||
{
|
||||
$query = 'INSERT INTO `'._DB_PREFIX_.'cart_product`(`id_cart`, `id_product`, `id_product_attribute`, `quantity`, `date_add`) VALUES ';
|
||||
foreach ($values as $value)
|
||||
$query .= '('.(int)$this->id.', '.(int)$value['id_product'].', '.(int)$value['id_product_attribute'].', '.(int)$value['quantity'].', NOW()),';
|
||||
$result = Db::getInstance()->Execute(rtrim($query, ','));
|
||||
$query .= '('.(int)$this->id.', '.(int)$value['id_product'].', '.(isset($value['id_product_attribute']) ? (int)$value['id_product_attribute'] : 'NULL').', '.(int)$value['quantity'].', NOW()),';
|
||||
Db::getInstance()->Execute(rtrim($query, ','));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -1676,7 +1693,7 @@ class CartCore extends ObjectModel
|
||||
* @param int $id_cart
|
||||
* @return bool true if cart has been made by a guest customer
|
||||
*/
|
||||
static public function isGuestCartByCartId($id_cart)
|
||||
public static function isGuestCartByCartId($id_cart)
|
||||
{
|
||||
if (!(int)$id_cart)
|
||||
return false;
|
||||
@@ -1699,6 +1716,8 @@ class CartCore extends ObjectModel
|
||||
{
|
||||
$carrier = new Carrier((int)$id_carrier, Configuration::get('PS_LANG_DEFAULT'));
|
||||
$shippingMethod = $carrier->getShippingMethod();
|
||||
if (!$carrier->range_behavior)
|
||||
return true;
|
||||
|
||||
if ($shippingMethod == Carrier::SHIPPING_METHOD_FREE)
|
||||
return true;
|
||||
|
||||
+32
-37
@@ -179,6 +179,16 @@ class CategoryCore extends ObjectModel
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ObjectModel::toggleStatus()
|
||||
*/
|
||||
public function toggleStatus()
|
||||
{
|
||||
$result = parent::toggleStatus();
|
||||
Module::hookExec('categoryUpdate');
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursive scan of subcategories
|
||||
*
|
||||
@@ -186,14 +196,16 @@ class CategoryCore extends ObjectModel
|
||||
* @param integer $currentDepth specify the current depth in the tree (don't use it, only for rucursivity!)
|
||||
* @param integer $id_lang Specify the id of the language used
|
||||
* @param array $excludedIdsArray specify a list of ids to exclude of results
|
||||
* @param Link $link
|
||||
*
|
||||
* @return array Subcategories lite tree
|
||||
*/
|
||||
function recurseLiteCategTree($maxDepth = 3, $currentDepth = 0, $id_lang = NULL, $excludedIdsArray = NULL, Link $link = NULL)
|
||||
public function recurseLiteCategTree($maxDepth = 3, $currentDepth = 0, $id_lang = NULL, $excludedIdsArray = NULL)
|
||||
{
|
||||
$id_lang = is_null($id_lang) ? Context::getContext()->language->id : (int)$id_lang;
|
||||
|
||||
if (!(int)$id_lang)
|
||||
$id_lang = _USER_ID_LANG_;
|
||||
|
||||
$children = array();
|
||||
if (($maxDepth == 0 OR $currentDepth < $maxDepth) AND $subcats = $this->getSubCategories($id_lang, true) AND sizeof($subcats))
|
||||
foreach ($subcats AS &$subcat)
|
||||
@@ -202,7 +214,7 @@ class CategoryCore extends ObjectModel
|
||||
break;
|
||||
elseif (!is_array($excludedIdsArray) || !in_array($subcat['id_category'], $excludedIdsArray))
|
||||
{
|
||||
$categ = new Category((int)$subcat['id_category'], $id_lang);
|
||||
$categ = new Category($subcat['id_category'], $id_lang);
|
||||
$children[] = $categ->recurseLiteCategTree($maxDepth, $currentDepth + 1, $id_lang, $excludedIdsArray);
|
||||
}
|
||||
}
|
||||
@@ -216,12 +228,12 @@ class CategoryCore extends ObjectModel
|
||||
);
|
||||
}
|
||||
|
||||
static public function recurseCategory($categories, $current, $id_category = 1, $id_selected = 1)
|
||||
public static function recurseCategory($categories, $current, $id_category = 1, $id_selected = 1)
|
||||
{
|
||||
echo '<option value="'.$id_category.'"'.(($id_selected == $id_category) ? ' selected="selected"' : '').'>'.
|
||||
str_repeat(' ', $current['infos']['level_depth'] * 5).stripslashes($current['infos']['name']).'</option>';
|
||||
if (isset($categories[$id_category]))
|
||||
foreach ($categories[$id_category] AS $key => $row)
|
||||
foreach (array_keys($categories[$id_category]) AS $key)
|
||||
self::recurseCategory($categories, $categories[$id_category][$key], $key, $id_selected);
|
||||
}
|
||||
|
||||
@@ -241,7 +253,7 @@ class CategoryCore extends ObjectModel
|
||||
SELECT `id_category`
|
||||
FROM `'._DB_PREFIX_.'category`
|
||||
WHERE `id_parent` = '.(int)($id_category));
|
||||
foreach ($result AS $k => $row)
|
||||
foreach ($result AS $row)
|
||||
{
|
||||
$toDelete[] = (int)($row['id_category']);
|
||||
$this->recursiveDelete($toDelete, (int)($row['id_category']));
|
||||
@@ -353,7 +365,7 @@ class CategoryCore extends ObjectModel
|
||||
{
|
||||
$left = (int)$n++;
|
||||
if (isset($categories[(int)$id_category]['subcategories']))
|
||||
foreach ($categories[(int)$id_category]['subcategories'] AS $id_subcategory => $value)
|
||||
foreach (array_keys($categories[(int)$id_category]['subcategories']) AS $id_subcategory)
|
||||
self::_subTree($categories, (int)$id_subcategory, $n);
|
||||
$right = (int)$n++;
|
||||
|
||||
@@ -367,7 +379,7 @@ class CategoryCore extends ObjectModel
|
||||
* @param boolean $active return only active categories
|
||||
* @return array Categories
|
||||
*/
|
||||
static public function getCategories($id_lang = false, $active = true, $order = true, $sql_filter = '', $sql_sort = '', $sql_limit = '')
|
||||
public static function getCategories($id_lang = false, $active = true, $order = true, $sql_filter = '', $sql_sort = '',$sql_limit = '')
|
||||
{
|
||||
if (!Validate::isBool($active))
|
||||
die(Tools::displayError());
|
||||
@@ -392,7 +404,7 @@ class CategoryCore extends ObjectModel
|
||||
return $categories;
|
||||
}
|
||||
|
||||
static public function getSimpleCategories($id_lang)
|
||||
public static function getSimpleCategories($id_lang)
|
||||
{
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
||||
SELECT c.`id_category`, cl.`name`
|
||||
@@ -594,37 +606,19 @@ class CategoryCore extends ObjectModel
|
||||
* @param int $id_lang
|
||||
* @return array
|
||||
*/
|
||||
public static function getChildrenWithNbSelectedSubCatForProduct($id_parent, $id_product = 0, $ids_categories = null, $id_lang)
|
||||
public static function getChildrenWithNbSelectedSubCat($id_parent, $selectedCat, $id_lang)
|
||||
{
|
||||
$categories_product_str = '';
|
||||
if ($id_product)
|
||||
{
|
||||
$categories_product = Db::getInstance()->ExecuteS('
|
||||
SELECT `id_category`
|
||||
FROM `'._DB_PREFIX_.'category_product`
|
||||
WHERE `id_product` = '.(int)$id_product);
|
||||
if (sizeof($categories_product))
|
||||
foreach ($categories_product as $category_product)
|
||||
$categories_product_str .= $category_product['id_category'].',';
|
||||
}
|
||||
else
|
||||
{
|
||||
$categories_product = array();
|
||||
$categories_product_str = $ids_categories;
|
||||
}
|
||||
$categories_product_str = rtrim($categories_product_str, ',');
|
||||
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
||||
SELECT c.`id_category`, cl.`name`, IF((
|
||||
SELECT c.`id_category`, c.`level_depth`, cl.`name`, IF((
|
||||
SELECT COUNT(*)
|
||||
FROM `'._DB_PREFIX_.'category` c2
|
||||
WHERE c2.`id_parent` = c.`id_category`
|
||||
) > 0, 1, 0) AS has_children, '.($categories_product_str ? '(
|
||||
) > 0, 1, 0) AS has_children, '.($selectedCat ? '(
|
||||
SELECT count(c3.`id_category`)
|
||||
FROM `'._DB_PREFIX_.'category` c3
|
||||
WHERE c3.`nleft` > c.`nleft`
|
||||
AND c3.`nright` < c.`nright`
|
||||
AND c3.`id_category` IN ('.$categories_product_str.')
|
||||
AND c3.`id_category` IN ('.$selectedCat.')
|
||||
)' : '0').' AS nbSelectedSubCat
|
||||
FROM `'._DB_PREFIX_.'category` c
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON c.`id_category` = cl.`id_category`
|
||||
@@ -725,7 +719,7 @@ class CategoryCore extends ObjectModel
|
||||
* @param boolean $unrestricted allows search without lang and includes first category and exact match
|
||||
* @return array Corresponding categories
|
||||
*/
|
||||
static public function searchByName($id_lang, $query, $unrestricted = false)
|
||||
public static function searchByName($id_lang, $query, $unrestricted = false)
|
||||
{
|
||||
if ($unrestricted === true)
|
||||
return Db::getInstance()->getRow('
|
||||
@@ -749,7 +743,7 @@ class CategoryCore extends ObjectModel
|
||||
* @param integer $id_parent_category parent category ID
|
||||
* @return array Corresponding category
|
||||
*/
|
||||
static public function searchByNameAndParentCategoryId($id_lang, $category_name, $id_parent_category)
|
||||
public static function searchByNameAndParentCategoryId($id_lang, $category_name, $id_parent_category)
|
||||
{
|
||||
return Db::getInstance()->getRow('
|
||||
SELECT c.*, cl.*
|
||||
@@ -794,7 +788,7 @@ class CategoryCore extends ObjectModel
|
||||
* @param $id_category Category id
|
||||
* @return boolean
|
||||
*/
|
||||
static public function categoryExists($id_category)
|
||||
public static function categoryExists($id_category)
|
||||
{
|
||||
$row = Db::getInstance()->getRow('
|
||||
SELECT `id_category`
|
||||
@@ -867,7 +861,7 @@ class CategoryCore extends ObjectModel
|
||||
$this->addGroups(array(1));
|
||||
}
|
||||
|
||||
static public function setNewGroupForHome($id_group)
|
||||
public static function setNewGroupForHome($id_group)
|
||||
{
|
||||
if (!(int)($id_group))
|
||||
return false;
|
||||
@@ -920,7 +914,7 @@ class CategoryCore extends ObjectModel
|
||||
* @param mixed $id_category_parent
|
||||
* @return boolean true if succeed
|
||||
*/
|
||||
static public function cleanPositions($id_category_parent)
|
||||
public static function cleanPositions($id_category_parent)
|
||||
{
|
||||
$return = true;
|
||||
|
||||
@@ -941,7 +935,7 @@ class CategoryCore extends ObjectModel
|
||||
return $return;
|
||||
}
|
||||
|
||||
static public function getLastPosition($id_category_parent)
|
||||
public static function getLastPosition($id_category_parent)
|
||||
{
|
||||
return (Db::getInstance()->getValue('SELECT MAX(position)+1 FROM `'._DB_PREFIX_.'category` WHERE `id_parent` = '.(int)($id_category_parent)));
|
||||
}
|
||||
@@ -1022,3 +1016,4 @@ class CategoryCore extends ObjectModel
|
||||
return $result[0]['nb_product_recursive'];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -169,7 +169,7 @@ class CombinationCore extends ObjectModel
|
||||
$sqlValues = array();
|
||||
foreach ($values as $value)
|
||||
$sqlValues[] = '('.(int)$this->id.', '.(int)$value['id'].')';
|
||||
$result = Db::getInstance()->Execute('
|
||||
Db::getInstance()->Execute('
|
||||
INSERT INTO `'._DB_PREFIX_.'product_attribute_image` (`id_product_attribute`, `id_image`)
|
||||
VALUES '.implode(',', $sqlValues)
|
||||
);
|
||||
|
||||
@@ -0,0 +1,198 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2011 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/osl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2011 PrestaShop SA
|
||||
* @version Release: $Revision$
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
class CompareProduct extends ObjectModel
|
||||
{
|
||||
public $id;
|
||||
|
||||
public $id_product;
|
||||
|
||||
public $id_guest;
|
||||
|
||||
public $id_customer;
|
||||
|
||||
public $date_add;
|
||||
|
||||
public $date_upd;
|
||||
|
||||
protected $fieldRequired = array(
|
||||
'id_product',
|
||||
'id_guest',
|
||||
'id_customer');
|
||||
|
||||
protected $fieldsValidate = array(
|
||||
'id_product' => 'isUnsignedInt',
|
||||
'id_guest' => 'isUnsignedInt',
|
||||
'id_customer' => 'isUnsignedInt'
|
||||
);
|
||||
|
||||
protected $table = 'compare_product';
|
||||
|
||||
protected $identifier = 'id_compare_product';
|
||||
|
||||
|
||||
/**
|
||||
* Get all compare products of the guest
|
||||
* @param int $id_guest
|
||||
* @return array
|
||||
*/
|
||||
public static function getGuestCompareProducts($id_guest)
|
||||
{
|
||||
$results = Db::getInstance()->ExecuteS('
|
||||
SELECT DISTINCT `id_product`
|
||||
FROM `'._DB_PREFIX_.'compare_product`
|
||||
WHERE `id_guest` = '.(int)($id_guest));
|
||||
|
||||
$compareProducts = null;
|
||||
|
||||
foreach($results as $result)
|
||||
$compareProducts[] = $result['id_product'];
|
||||
|
||||
return $compareProducts;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a compare product for the guest
|
||||
* @param int $id_guest, int $id_product
|
||||
* @return boolean
|
||||
*/
|
||||
public static function addGuestCompareProduct($id_guest, $id_product)
|
||||
{
|
||||
return Db::getInstance()->Execute('
|
||||
INSERT INTO `'._DB_PREFIX_.'compare_product` (`id_product`, `id_guest`, `date_add`, `date_upd`)
|
||||
VALUES ('.(int)($id_product).', '.(int)($id_guest).', NOW(), NOW())
|
||||
');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove a compare product for the guest
|
||||
* @param int $id_guest, int $id_product
|
||||
* @return boolean
|
||||
*/
|
||||
public static function removeGuestCompareProduct($id_guest, $id_product)
|
||||
{
|
||||
return Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'compare_product` WHERE `id_guest` = '.(int)($id_guest).' AND `id_product` = '.(int)($id_product));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the number of compare products of the guest
|
||||
* @param int $id_guest
|
||||
* @return int
|
||||
*/
|
||||
public static function getGuestNumberProducts($id_guest)
|
||||
{
|
||||
return (int)(Db::getInstance()->getValue('
|
||||
SELECT count(`id_compare_product`)
|
||||
FROM `'._DB_PREFIX_.'compare_product`
|
||||
WHERE `id_guest` = '.(int)($id_guest)));;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all comapare products of the customer
|
||||
* @param int $id_customer
|
||||
* @return array
|
||||
*/
|
||||
public static function getCustomerCompareProducts($id_customer)
|
||||
{
|
||||
$results = Db::getInstance()->ExecuteS('
|
||||
SELECT DISTINCT `id_product`
|
||||
FROM `'._DB_PREFIX_.'compare_product`
|
||||
WHERE `id_customer` = '.(int)($id_customer));
|
||||
|
||||
$compareProducts = null;
|
||||
|
||||
foreach($results as $result)
|
||||
$compareProducts[] = $result['id_product'];
|
||||
|
||||
return $compareProducts;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a compare product for the customer
|
||||
* @param int $id_customer, int $id_product
|
||||
* @return boolean
|
||||
*/
|
||||
public static function addCustomerCompareProduct($id_customer, $id_product)
|
||||
{
|
||||
return Db::getInstance()->Execute('INSERT INTO `'._DB_PREFIX_.'compare_product` (`id_product`, `id_customer`, `date_add`, `date_upd`) VALUES ('.(int)($id_product).', '.(int)($id_customer).', NOW(), NOW())');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove a compare product for the customer
|
||||
* @param int $id_customer, int $id_product
|
||||
* @return boolean
|
||||
*/
|
||||
public static function removeCustomerCompareProduct($id_customer, $id_product)
|
||||
{
|
||||
return Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'compare_product` WHERE `id_customer` = '.(int)($id_customer).' AND `id_product` = '.(int)($id_product));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the number of compare products of the customer
|
||||
* @param int $id_customer
|
||||
* @return int
|
||||
*/
|
||||
public static function getCustomerNumberProducts($id_customer)
|
||||
{
|
||||
return (int)(Db::getInstance()->getValue('
|
||||
SELECT count(`id_compare_product`)
|
||||
FROM `'._DB_PREFIX_.'compare_product`
|
||||
WHERE `id_customer` = '.(int)($id_customer)));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Clean entries which are older than the period
|
||||
* @param string $period
|
||||
* @return void
|
||||
*/
|
||||
public static function cleanCompareProducts($period = 'week')
|
||||
{
|
||||
if ($period === 'week')
|
||||
$interval = '1 WEEK';
|
||||
elseif ($period === 'month')
|
||||
$interval = '1 MONTH';
|
||||
elseif ($period === 'year')
|
||||
$interval = '1 YEAR';
|
||||
else
|
||||
return;
|
||||
|
||||
if ($interval != null)
|
||||
{
|
||||
Db::getInstance()->Execute('
|
||||
DELETE FROM `'._DB_PREFIX_.'compare_product`
|
||||
WHERE date_upd < DATE_SUB(NOW(), INTERVAL '.pSQL($interval).')');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,230 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2011 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/osl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2011 PrestaShop SA
|
||||
* @version Release: $Revision$
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
class ConfigurationTestCore
|
||||
{
|
||||
static function check($tests)
|
||||
{
|
||||
$res = array();
|
||||
foreach ($tests AS $key => $test)
|
||||
$res[$key] = self::run($key, $test);
|
||||
return $res;
|
||||
}
|
||||
|
||||
static function run($ptr, $arg = 0)
|
||||
{
|
||||
if (call_user_func(array('ConfigurationTest', 'test_'.$ptr), $arg))
|
||||
return ('ok');
|
||||
return ('fail');
|
||||
}
|
||||
|
||||
// Misc functions
|
||||
static function test_phpversion()
|
||||
{
|
||||
return version_compare(substr(phpversion(), 0, 3), '5.0', '>=');
|
||||
}
|
||||
|
||||
static function test_mysql_support()
|
||||
{
|
||||
return function_exists('mysql_connect');
|
||||
}
|
||||
|
||||
static function test_magicquotes()
|
||||
{
|
||||
return !ini_get('magic_quotes_gpc');
|
||||
}
|
||||
|
||||
static function test_upload()
|
||||
{
|
||||
return ini_get('file_uploads');
|
||||
}
|
||||
|
||||
static function test_fopen()
|
||||
{
|
||||
return ini_get('allow_url_fopen');
|
||||
}
|
||||
|
||||
static function test_system($funcs)
|
||||
{
|
||||
foreach ($funcs AS $func)
|
||||
if (!function_exists($func))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
static function test_gd()
|
||||
{
|
||||
return function_exists('imagecreatetruecolor');
|
||||
}
|
||||
|
||||
static function test_register_globals()
|
||||
{
|
||||
return !ini_get('register_globals');
|
||||
}
|
||||
|
||||
static function test_gz()
|
||||
{
|
||||
if (function_exists('gzencode'))
|
||||
return !(@gzencode('dd') === false);
|
||||
return false;
|
||||
}
|
||||
|
||||
// is_writable dirs
|
||||
static function test_dir($dir, $recursive = false)
|
||||
{
|
||||
if (!file_exists($dir) OR !$dh = opendir($dir))
|
||||
return false;
|
||||
$dummy = rtrim($dir, '/').'/'.uniqid();
|
||||
if (@file_put_contents($dummy, 'test'))
|
||||
{
|
||||
@unlink($dummy);
|
||||
if (!$recursive)
|
||||
return true;
|
||||
}
|
||||
elseif (!is_writable($dir))
|
||||
return false;
|
||||
if ($recursive)
|
||||
{
|
||||
while (($file = readdir($dh)) !== false)
|
||||
if (@filetype($dir.$file) == 'dir' AND $file != '.' AND $file != '..')
|
||||
if (!self::test_dir($dir.$file, true))
|
||||
return false;
|
||||
}
|
||||
closedir($dh);
|
||||
return true;
|
||||
}
|
||||
|
||||
// is_writable files
|
||||
static function test_file($file)
|
||||
{
|
||||
return (file_exists($file) AND is_writable($file));
|
||||
}
|
||||
|
||||
static function test_config_dir($dir)
|
||||
{
|
||||
return self::test_dir($dir);
|
||||
}
|
||||
|
||||
static function test_sitemap($dir)
|
||||
{
|
||||
return self::test_file($dir);
|
||||
}
|
||||
|
||||
static function test_root_dir($dir)
|
||||
{
|
||||
return self::test_dir($dir);
|
||||
}
|
||||
|
||||
static function test_log_dir($dir)
|
||||
{
|
||||
return self::test_dir($dir);
|
||||
}
|
||||
|
||||
static function test_admin_dir($dir)
|
||||
{
|
||||
return self::test_dir($dir);
|
||||
}
|
||||
|
||||
static function test_img_dir($dir)
|
||||
{
|
||||
return self::test_dir($dir, true);
|
||||
}
|
||||
|
||||
static function test_module_dir($dir)
|
||||
{
|
||||
return self::test_dir($dir, true);
|
||||
}
|
||||
|
||||
static function test_tools_dir($dir)
|
||||
{
|
||||
return self::test_dir($dir);
|
||||
}
|
||||
|
||||
static function test_cache_dir($dir)
|
||||
{
|
||||
return self::test_dir($dir);
|
||||
}
|
||||
|
||||
static function test_tools_v2_dir($dir)
|
||||
{
|
||||
return self::test_dir($dir);
|
||||
}
|
||||
|
||||
static function test_cache_v2_dir($dir)
|
||||
{
|
||||
return self::test_dir($dir);
|
||||
}
|
||||
|
||||
static function test_download_dir($dir)
|
||||
{
|
||||
return self::test_dir($dir);
|
||||
}
|
||||
|
||||
static function test_mails_dir($dir)
|
||||
{
|
||||
return self::test_dir($dir, true);
|
||||
}
|
||||
|
||||
static function test_translations_dir($dir)
|
||||
{
|
||||
return self::test_dir($dir, true);
|
||||
}
|
||||
|
||||
static function test_theme_lang_dir($dir)
|
||||
{
|
||||
if (!file_exists($dir))
|
||||
return true;
|
||||
return self::test_dir($dir, true);
|
||||
}
|
||||
|
||||
static function test_theme_cache_dir($dir)
|
||||
{
|
||||
if (!file_exists($dir))
|
||||
return true;
|
||||
return self::test_dir($dir, true);
|
||||
}
|
||||
|
||||
static function test_customizable_products_dir($dir)
|
||||
{
|
||||
return self::test_dir($dir);
|
||||
}
|
||||
|
||||
static function test_virtual_products_dir($dir)
|
||||
{
|
||||
return self::test_dir($dir);
|
||||
}
|
||||
|
||||
static function test_mcrypt()
|
||||
{
|
||||
return function_exists('mcrypt_encrypt');
|
||||
}
|
||||
|
||||
static function test_dom()
|
||||
{
|
||||
return extension_loaded('Dom');
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -339,7 +339,7 @@ class CookieCore
|
||||
public function unsetFamily($origin)
|
||||
{
|
||||
$family = $this->getFamily($origin);
|
||||
foreach ($family AS $member => $value)
|
||||
foreach (array_keys($family) AS $member)
|
||||
unset($this->$member);
|
||||
}
|
||||
|
||||
|
||||
+9
-9
@@ -157,7 +157,7 @@ class CountryCore extends ObjectModel
|
||||
* @param string $iso_code Country iso code
|
||||
* @return integer Country ID
|
||||
*/
|
||||
static public function getByIso($iso_code)
|
||||
public static function getByIso($iso_code)
|
||||
{
|
||||
if (!Validate::isLanguageIsoCode($iso_code))
|
||||
die(Tools::displayError());
|
||||
@@ -169,7 +169,7 @@ class CountryCore extends ObjectModel
|
||||
return $result['id_country'];
|
||||
}
|
||||
|
||||
static public function getIdZone($id_country)
|
||||
public static function getIdZone($id_country)
|
||||
{
|
||||
if (!Validate::isUnsignedId($id_country))
|
||||
die(Tools::displayError());
|
||||
@@ -193,7 +193,7 @@ class CountryCore extends ObjectModel
|
||||
* @param integer $id_country Country ID
|
||||
* @return string Country name
|
||||
*/
|
||||
static public function getNameById($id_lang, $id_country)
|
||||
public static function getNameById($id_lang, $id_country)
|
||||
{
|
||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
||||
SELECT `name`
|
||||
@@ -210,7 +210,7 @@ class CountryCore extends ObjectModel
|
||||
* @param integer $id_country Country ID
|
||||
* @return string Country iso
|
||||
*/
|
||||
static public function getIsoById($id_country)
|
||||
public static function getIsoById($id_country)
|
||||
{
|
||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
||||
SELECT `iso_code`
|
||||
@@ -227,7 +227,7 @@ class CountryCore extends ObjectModel
|
||||
* @param string $country Country Name
|
||||
* @return intval Country id
|
||||
*/
|
||||
static public function getIdByName($id_lang = NULL, $country)
|
||||
public static function getIdByName($id_lang = NULL, $country)
|
||||
{
|
||||
$sql = '
|
||||
SELECT `id_country`
|
||||
@@ -241,7 +241,7 @@ class CountryCore extends ObjectModel
|
||||
return ((int)($result['id_country']));
|
||||
}
|
||||
|
||||
static public function getNeedZipCode($id_country)
|
||||
public static function getNeedZipCode($id_country)
|
||||
{
|
||||
if (!(int)($id_country))
|
||||
return false;
|
||||
@@ -252,7 +252,7 @@ class CountryCore extends ObjectModel
|
||||
WHERE `id_country` = '.(int)($id_country));
|
||||
}
|
||||
|
||||
static public function getZipCodeFormat($id_country)
|
||||
public static function getZipCodeFormat($id_country)
|
||||
{
|
||||
if (!(int)($id_country))
|
||||
return false;
|
||||
@@ -303,7 +303,7 @@ class CountryCore extends ObjectModel
|
||||
return (bool)self::isNeedDniByCountryId($this->id);
|
||||
}
|
||||
|
||||
static public function isNeedDniByCountryId($id_country)
|
||||
public static function isNeedDniByCountryId($id_country)
|
||||
{
|
||||
return (bool)Db::getInstance()->getValue('
|
||||
SELECT `need_identification_number`
|
||||
@@ -311,7 +311,7 @@ class CountryCore extends ObjectModel
|
||||
WHERE `id_country` = '.(int)$id_country);
|
||||
}
|
||||
|
||||
static public function containsStates($id_country)
|
||||
public static function containsStates($id_country)
|
||||
{
|
||||
return (bool)Db::getInstance()->getValue('
|
||||
SELECT `contains_states`
|
||||
|
||||
@@ -127,7 +127,6 @@ class CurrencyCore extends ObjectModel
|
||||
{
|
||||
if (!is_array($selection) OR !Validate::isTableOrIdentifier($this->identifier) OR !Validate::isTableOrIdentifier($this->table))
|
||||
die(Tools::displayError());
|
||||
$result = true;
|
||||
foreach ($selection AS $id)
|
||||
{
|
||||
$obj = new Currency((int)($id));
|
||||
@@ -238,7 +237,7 @@ class CurrencyCore extends ObjectModel
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql);
|
||||
}
|
||||
|
||||
static public function getCurrency($id_currency)
|
||||
public static function getCurrency($id_currency)
|
||||
{
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
||||
SELECT *
|
||||
@@ -247,7 +246,7 @@ class CurrencyCore extends ObjectModel
|
||||
AND `id_currency` = '.(int)($id_currency));
|
||||
}
|
||||
|
||||
static public function getIdByIsoCode($iso_code)
|
||||
public static function getIdByIsoCode($iso_code)
|
||||
{
|
||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
||||
SELECT `id_currency`
|
||||
@@ -319,10 +318,10 @@ class CurrencyCore extends ObjectModel
|
||||
return new Currency($id_currency);
|
||||
}
|
||||
|
||||
static public function refreshCurrencies()
|
||||
public static function refreshCurrencies()
|
||||
{
|
||||
// Parse
|
||||
if (!$feed = @simplexml_load_file('http://www.prestashop.com/xml/currencies.xml'))
|
||||
if (!$feed = Tools::simplexml_load_file('http://www.prestashop.com/xml/currencies.xml'))
|
||||
return Tools::displayError('Cannot parse feed.');
|
||||
|
||||
// Default feed currency (EUR)
|
||||
@@ -343,13 +342,13 @@ class CurrencyCore extends ObjectModel
|
||||
* @deprecated as of 1.5 use $context->currency instead
|
||||
* @return Currency
|
||||
*/
|
||||
static public function getCurrent()
|
||||
public static function getCurrent()
|
||||
{
|
||||
Tools::displayAsDeprecated();
|
||||
return Context::getContext()->currency;
|
||||
}
|
||||
|
||||
static public function getCurrencyInstance($id)
|
||||
public static function getCurrencyInstance($id)
|
||||
{
|
||||
if (!array_key_exists($id, self::$currencies))
|
||||
self::$currencies[(int)($id)] = new Currency($id);
|
||||
|
||||
@@ -306,7 +306,7 @@ class CustomerCore extends ObjectModel
|
||||
* @param integer $id_address Address ID
|
||||
* @return boolean result
|
||||
*/
|
||||
static public function customerHasAddress($id_customer, $id_address)
|
||||
public static function customerHasAddress($id_customer, $id_address)
|
||||
{
|
||||
if (!array_key_exists($id_customer, self::$_customerHasAddress))
|
||||
{
|
||||
@@ -320,7 +320,7 @@ class CustomerCore extends ObjectModel
|
||||
return self::$_customerHasAddress[$id_customer];
|
||||
}
|
||||
|
||||
static public function resetAddressCache($id_customer)
|
||||
public static function resetAddressCache($id_customer)
|
||||
{
|
||||
if (array_key_exists($id_customer, self::$_customerHasAddress))
|
||||
unset(self::$_customerHasAddress[$id_customer]);
|
||||
@@ -364,7 +364,7 @@ class CustomerCore extends ObjectModel
|
||||
* @param string $passwd Password
|
||||
* @return boolean result
|
||||
*/
|
||||
static public function checkPassword($id_customer, $passwd)
|
||||
public static function checkPassword($id_customer, $passwd)
|
||||
{
|
||||
if (!Validate::isUnsignedId($id_customer) OR !Validate::isMd5($passwd))
|
||||
die (Tools::displayError());
|
||||
@@ -452,7 +452,7 @@ class CustomerCore extends ObjectModel
|
||||
return self::customerIdExistsStatic((int)($id_customer));
|
||||
}
|
||||
|
||||
static public function customerIdExistsStatic($id_customer)
|
||||
public static function customerIdExistsStatic($id_customer)
|
||||
{
|
||||
$row = Db::getInstance()->getRow('
|
||||
SELECT `id_customer`
|
||||
@@ -506,10 +506,10 @@ class CustomerCore extends ObjectModel
|
||||
WHERE o.valid = 1 AND o.`id_customer` = '.(int)($this->id));
|
||||
}
|
||||
|
||||
static public function getDefaultGroupId($id_customer)
|
||||
public static function getDefaultGroupId($id_customer)
|
||||
{
|
||||
if (!isset(self::$_defaultGroupId[(int)($id_customer)]))
|
||||
self::$_defaultGroupId[(int)($id_customer)] = Db::getInstance()->getValue('SELECT `id_default_group` FROM `'._DB_PREFIX_.'customer` WHERE `id_customer` = '.(int)($id_customer));
|
||||
self::$_defaultGroupId[(int)($id_customer)] = Db::getInstance()->getValue('SELECT `id_default_group` FROM `'._DB_PREFIX_.'customer` WHERE `id_customer` = '.(int)$id_customer);
|
||||
return self::$_defaultGroupId[(int)($id_customer)];
|
||||
}
|
||||
|
||||
@@ -568,7 +568,7 @@ class CustomerCore extends ObjectModel
|
||||
return false;
|
||||
}
|
||||
|
||||
static public function printNewsIcon($id_customer, $tr)
|
||||
public static function printNewsIcon($id_customer, $tr)
|
||||
{
|
||||
$customer = new Customer($tr['id_customer']);
|
||||
if (!Validate::isLoadedObject($customer))
|
||||
@@ -578,7 +578,7 @@ class CustomerCore extends ObjectModel
|
||||
'</a>';
|
||||
}
|
||||
|
||||
static public function printOptinIcon($id_customer, $tr)
|
||||
public static function printOptinIcon($id_customer, $tr)
|
||||
{
|
||||
$customer = new Customer($tr['id_customer']);
|
||||
if (!Validate::isLoadedObject($customer))
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
class CustomizationCore
|
||||
{
|
||||
|
||||
static public function getReturnedCustomizations($id_order)
|
||||
public static function getReturnedCustomizations($id_order)
|
||||
{
|
||||
if (($result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
||||
SELECT ore.`id_order_return`, ord.`id_order_detail`, ord.`id_customization`, ord.`product_quantity`
|
||||
@@ -42,7 +42,7 @@ class CustomizationCore
|
||||
return $customizations;
|
||||
}
|
||||
|
||||
static public function getOrderedCustomizations($id_cart)
|
||||
public static function getOrderedCustomizations($id_cart)
|
||||
{
|
||||
if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('SELECT `id_customization`, `quantity` FROM `'._DB_PREFIX_.'customization` WHERE `id_cart` = '.(int)($id_cart)))
|
||||
return false;
|
||||
@@ -52,7 +52,7 @@ class CustomizationCore
|
||||
return $customizations;
|
||||
}
|
||||
|
||||
static public function countCustomizationQuantityByProduct($customizations)
|
||||
public static function countCustomizationQuantityByProduct($customizations)
|
||||
{
|
||||
$total = array();
|
||||
foreach ($customizations AS $customization)
|
||||
@@ -60,7 +60,7 @@ class CustomizationCore
|
||||
return $total;
|
||||
}
|
||||
|
||||
static public function getLabel($id_customization, $id_lang)
|
||||
public static function getLabel($id_customization, $id_lang)
|
||||
{
|
||||
if (!$id_customization || !$id_lang)
|
||||
return false;
|
||||
|
||||
+1
-1
@@ -353,7 +353,7 @@ abstract class DbCore
|
||||
Cache::getInstance()->setQuery($sql, $resultArray);
|
||||
return $resultArray;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* getRow return an associative array containing the first row of the query
|
||||
* This function automatically add "limit 1" to the query
|
||||
|
||||
+9
-10
@@ -190,7 +190,7 @@ class DiscountCore extends ObjectModel
|
||||
*
|
||||
* @return array Discount types
|
||||
*/
|
||||
static public function getDiscountTypes($id_lang)
|
||||
public static function getDiscountTypes($id_lang)
|
||||
{
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
||||
SELECT *
|
||||
@@ -294,7 +294,6 @@ class DiscountCore extends ObjectModel
|
||||
return 0;
|
||||
$products = $cart->getProducts();
|
||||
$categories = Discount::getCategories((int)$this->id);
|
||||
$in_category = false;
|
||||
|
||||
foreach ($products AS $product)
|
||||
if (count($categories) AND Product::idIsOnCategoryId($product['id_product'], $categories))
|
||||
@@ -341,7 +340,7 @@ class DiscountCore extends ObjectModel
|
||||
return 0;
|
||||
}
|
||||
|
||||
static public function getCategories($id_discount)
|
||||
public static function getCategories($id_discount)
|
||||
{
|
||||
return Db::getInstance()->ExecuteS('
|
||||
SELECT `id_category`
|
||||
@@ -376,12 +375,12 @@ class DiscountCore extends ObjectModel
|
||||
}
|
||||
}
|
||||
|
||||
static public function discountExists($discountName, $id_discount = 0)
|
||||
public static function discountExists($discountName, $id_discount = 0)
|
||||
{
|
||||
return Db::getInstance()->getRow('SELECT `id_discount` FROM '._DB_PREFIX_.'discount WHERE `name` LIKE \''.pSQL($discountName).'\' AND `id_discount` != '.(int)($id_discount));
|
||||
}
|
||||
|
||||
static public function createOrderDiscount($order, $productList, $qtyList, $name, $shipping_cost = false, $id_category = 0, $subcategory = 0)
|
||||
public static function createOrderDiscount($order, $productList, $qtyList, $name, $shipping_cost = false, $id_category = 0, $subcategory = 0)
|
||||
{
|
||||
$languages = Language::getLanguages($order);
|
||||
$products = $order->getProducts(false, $productList, $qtyList);
|
||||
@@ -430,7 +429,7 @@ class DiscountCore extends ObjectModel
|
||||
return $voucher;
|
||||
}
|
||||
|
||||
static public function display($discountValue, $discountType, $currency = false)
|
||||
public static function display($discountValue, $discountType, $currency = false)
|
||||
{
|
||||
if ((float)($discountValue) AND (int)($discountType))
|
||||
{
|
||||
@@ -442,7 +441,7 @@ class DiscountCore extends ObjectModel
|
||||
return ''; // return a string because it's a display method
|
||||
}
|
||||
|
||||
static public function getVouchersToCartDisplay($id_lang, $id_customer)
|
||||
public static function getVouchersToCartDisplay($id_lang, $id_customer)
|
||||
{
|
||||
return Db::getInstance()->ExecuteS('
|
||||
SELECT d.`name`, dl.`description`, d.`id_discount`
|
||||
@@ -456,7 +455,7 @@ class DiscountCore extends ObjectModel
|
||||
OR d.`id_group` IN (SELECT `id_group` FROM `'._DB_PREFIX_.'customer_group` WHERE `id_customer` = '.(int)($id_customer).')))' : 'OR d.`id_group` = 1)'));
|
||||
}
|
||||
|
||||
static public function deleteByIdCustomer($id_customer)
|
||||
public static function deleteByIdCustomer($id_customer)
|
||||
{
|
||||
$discounts = Db::getInstance()->ExecuteS('SELECT `id_discount` FROM `'._DB_PREFIX_.'discount` WHERE `id_customer` = '.(int)($id_customer));
|
||||
foreach ($discounts as $discount)
|
||||
@@ -468,7 +467,7 @@ class DiscountCore extends ObjectModel
|
||||
return true;
|
||||
}
|
||||
|
||||
static public function deleteByIdGroup($id_group)
|
||||
public static function deleteByIdGroup($id_group)
|
||||
{
|
||||
$discounts = Db::getInstance()->ExecuteS('SELECT `id_discount` FROM `'._DB_PREFIX_.'discount` WHERE `id_group` = '.(int)($id_group));
|
||||
foreach ($discounts as $discount)
|
||||
@@ -480,7 +479,7 @@ class DiscountCore extends ObjectModel
|
||||
return true;
|
||||
}
|
||||
|
||||
static public function getDiscount($id_discount)
|
||||
public static function getDiscount($id_discount)
|
||||
{
|
||||
return Db::getInstance()->getRow('SELECT * FROM `'._DB_PREFIX_.'discount` WHERE `id_discount` = '.(int)$id_discount);
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ class EmployeeCore extends ObjectModel
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
|
||||
public function add($autodate = true, $nullValues = true)
|
||||
{
|
||||
$this->last_passwd_gen = date('Y-m-d H:i:s', strtotime('-'.Configuration::get('PS_PASSWD_TIME_BACK').'minutes'));
|
||||
@@ -151,7 +151,7 @@ class EmployeeCore extends ObjectModel
|
||||
return $this;
|
||||
}
|
||||
|
||||
static public function employeeExists($email)
|
||||
public static function employeeExists($email)
|
||||
{
|
||||
if (!Validate::isEmail($email))
|
||||
die (Tools::displayError());
|
||||
@@ -168,7 +168,7 @@ class EmployeeCore extends ObjectModel
|
||||
* @param string $passwd Password
|
||||
* @return boolean result
|
||||
*/
|
||||
static public function checkPassword($id_employee, $passwd)
|
||||
public static function checkPassword($id_employee, $passwd)
|
||||
{
|
||||
if (!Validate::isUnsignedId($id_employee) OR !Validate::isPasswd($passwd, 8))
|
||||
die (Tools::displayError());
|
||||
@@ -181,7 +181,7 @@ class EmployeeCore extends ObjectModel
|
||||
AND active = 1');
|
||||
}
|
||||
|
||||
static public function countProfile($id_profile, $activeOnly = false)
|
||||
public static function countProfile($id_profile, $activeOnly = false)
|
||||
{
|
||||
return Db::getInstance()->getValue('
|
||||
SELECT COUNT(*)
|
||||
|
||||
+5
-5
@@ -67,7 +67,7 @@ class FeatureCore extends ObjectModel
|
||||
* @return array Array with feature's data
|
||||
* @static
|
||||
*/
|
||||
static public function getFeature($id_lang, $id_feature)
|
||||
public static function getFeature($id_lang, $id_feature)
|
||||
{
|
||||
return Db::getInstance()->getRow('
|
||||
SELECT *
|
||||
@@ -83,7 +83,7 @@ class FeatureCore extends ObjectModel
|
||||
* @return array Multiple arrays with feature's data
|
||||
* @static
|
||||
*/
|
||||
static public function getFeatures($id_lang)
|
||||
public static function getFeatures($id_lang)
|
||||
{
|
||||
return Db::getInstance()->ExecuteS('
|
||||
SELECT *
|
||||
@@ -132,7 +132,7 @@ class FeatureCore extends ObjectModel
|
||||
$fields = $this->getTranslationsFieldsChild();
|
||||
foreach ($fields as $field)
|
||||
{
|
||||
foreach ($field as $key => $value)
|
||||
foreach (array_keys($field) as $key)
|
||||
if (!Validate::isTableOrIdentifier($key))
|
||||
die(Tools::displayError());
|
||||
$mode = Db::getInstance()->getRow('SELECT `id_lang` FROM `'.pSQL(_DB_PREFIX_.$this->table).'_lang` WHERE `'.pSQL($this->identifier).
|
||||
@@ -151,7 +151,7 @@ class FeatureCore extends ObjectModel
|
||||
* @return int Number of feature
|
||||
* @static
|
||||
*/
|
||||
static public function nbFeatures($id_lang)
|
||||
public static function nbFeatures($id_lang)
|
||||
{
|
||||
$result = Db::getInstance()->getRow('
|
||||
SELECT COUNT(ag.`id_feature`) as nb
|
||||
@@ -168,7 +168,7 @@ class FeatureCore extends ObjectModel
|
||||
* @param integer $id_product Product id
|
||||
* @param array $value Feature Value
|
||||
*/
|
||||
static public function addFeatureImport($name)
|
||||
public static function addFeatureImport($name)
|
||||
{
|
||||
$rq = Db::getInstance()->getRow('SELECT `id_feature` FROM '._DB_PREFIX_.'feature_lang WHERE `name` = \''.pSQL($name).'\' GROUP BY `id_feature`');
|
||||
if (!empty($rq))
|
||||
|
||||
@@ -81,7 +81,7 @@ class FeatureValueCore extends ObjectModel
|
||||
* @return array Array with feature's values
|
||||
* @static
|
||||
*/
|
||||
static public function getFeatureValues($id_feature)
|
||||
public static function getFeatureValues($id_feature)
|
||||
{
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
||||
SELECT *
|
||||
@@ -97,7 +97,7 @@ class FeatureValueCore extends ObjectModel
|
||||
* @return array Array with feature's values
|
||||
* @static
|
||||
*/
|
||||
static public function getFeatureValuesWithLang($id_lang, $id_feature)
|
||||
public static function getFeatureValuesWithLang($id_lang, $id_feature)
|
||||
{
|
||||
return Db::getInstance()->ExecuteS('
|
||||
SELECT *
|
||||
@@ -114,7 +114,7 @@ class FeatureValueCore extends ObjectModel
|
||||
* @return array Array with value's languages
|
||||
* @static
|
||||
*/
|
||||
static public function getFeatureValueLang($id_feature_value)
|
||||
public static function getFeatureValueLang($id_feature_value)
|
||||
{
|
||||
return Db::getInstance()->ExecuteS('
|
||||
SELECT *
|
||||
@@ -131,14 +131,14 @@ class FeatureValueCore extends ObjectModel
|
||||
* @return string String value name selected
|
||||
* @static
|
||||
*/
|
||||
static public function selectLang($lang, $id_lang)
|
||||
public static function selectLang($lang, $id_lang)
|
||||
{
|
||||
foreach ($lang as $tab)
|
||||
if ($tab['id_lang'] == $id_lang)
|
||||
return $tab['value'];
|
||||
}
|
||||
|
||||
static public function addFeatureValueImport($id_feature, $name)
|
||||
public static function addFeatureValueImport($id_feature, $name)
|
||||
{
|
||||
$rq = Db::getInstance()->ExecuteS('
|
||||
SELECT fv.`id_feature_value`
|
||||
|
||||
@@ -115,6 +115,8 @@ class FrontControllerCore
|
||||
|
||||
ob_start();
|
||||
|
||||
$defaultCountry = new Country(Configuration::get('PS_COUNTRY_DEFAULT'), Configuration::get('PS_LANG_DEFAULT'));
|
||||
|
||||
// Switch language if needed and init cookie language
|
||||
if ($iso = Tools::getValue('isolang') AND Validate::isLanguageIsoCode($iso) AND ($id_lang = (int)(Language::getIdByIso($iso))))
|
||||
$_GET['id_lang'] = $id_lang;
|
||||
@@ -122,7 +124,7 @@ class FrontControllerCore
|
||||
Tools::switchLanguage();
|
||||
Tools::setCookieLanguage($cookie);
|
||||
$currency = Tools::setCurrency($cookie);
|
||||
|
||||
|
||||
if (Validate::isLoadedObject($currency))
|
||||
$smarty->ps_currency = $currency;
|
||||
if (!Validate::isLoadedObject($language = new Language($cookie->id_lang)))
|
||||
@@ -159,6 +161,7 @@ class FrontControllerCore
|
||||
}
|
||||
|
||||
$_MODULES = array();
|
||||
|
||||
/* Cart already exists */
|
||||
if ((int)$cookie->id_cart)
|
||||
{
|
||||
@@ -232,9 +235,11 @@ class FrontControllerCore
|
||||
$smarty->ps_language = $language;
|
||||
|
||||
/* get page name to display it in body id */
|
||||
// @todo check here
|
||||
$pathinfo = pathinfo(__FILE__);
|
||||
$page_name = Dispatcher::getInstance()->getController();
|
||||
$page_name = (preg_match('/^[0-9]/', $page_name)) ? 'page_'.$page_name : $page_name;
|
||||
|
||||
$smarty->assign(Tools::getMetaTags($language->id, $page_name));
|
||||
$smarty->assign('request_uri', Tools::safeOutput(urldecode($_SERVER['REQUEST_URI'])));
|
||||
|
||||
@@ -285,8 +290,6 @@ class FrontControllerCore
|
||||
'vat_management' => (int)Configuration::get('VATNUMBER_MANAGEMENT'),
|
||||
'opc' => (bool)Configuration::get('PS_ORDER_PROCESS_TYPE'),
|
||||
'PS_CATALOG_MODE' => (bool)Configuration::get('PS_CATALOG_MODE'),
|
||||
'id_current_shop' => $this->id_current_shop,
|
||||
'id_current_group_shop' => (int)$this->id_current_group_shop
|
||||
));
|
||||
|
||||
// Deprecated
|
||||
@@ -473,7 +476,7 @@ class FrontControllerCore
|
||||
{
|
||||
$this->addCSS(_THEME_CSS_DIR_.'global.css', 'all');
|
||||
$this->addJS(array(_PS_JS_DIR_.'jquery/jquery-1.4.4.min.js', _PS_JS_DIR_.'jquery/jquery.easing.1.3.js', _PS_JS_DIR_.'tools.js'));
|
||||
if (Tools::isSubmit('live_edit') AND $ad = Tools::getValue('ad') AND (Tools::getValue('liveToken') == sha1(Tools::getValue('ad')._COOKIE_KEY_)))
|
||||
if (Tools::isSubmit('live_edit') AND Tools::getValue('ad') AND (Tools::getValue('liveToken') == sha1(Tools::getValue('ad')._COOKIE_KEY_)))
|
||||
{
|
||||
$this->addJS(array(
|
||||
_PS_JS_DIR_.'jquery/jquery-ui-1.8.10.custom.min.js',
|
||||
@@ -482,6 +485,9 @@ class FrontControllerCore
|
||||
);
|
||||
$this->addCSS(_PS_CSS_DIR_.'jquery.fancybox-1.3.4.css');
|
||||
}
|
||||
$language = new Language($this->context->language->id);
|
||||
if ($language->is_rtl)
|
||||
Tools::addCSS(_THEME_CSS_DIR_.'rtl.css');
|
||||
}
|
||||
|
||||
public function process()
|
||||
@@ -538,6 +544,8 @@ class FrontControllerCore
|
||||
{
|
||||
if (!$this->context)
|
||||
$this->context = Context::getContext();
|
||||
if (!self::$initialized)
|
||||
$this->init();
|
||||
|
||||
$this->context->smarty->assign(array(
|
||||
'HOOK_RIGHT_COLUMN' => Module::hookExec('rightColumn', array('cart' => $this->context->cart)),
|
||||
@@ -702,7 +710,7 @@ class FrontControllerCore
|
||||
*/
|
||||
public function addJS($js_uri)
|
||||
{
|
||||
if(!isset($this->js_files))
|
||||
if (!isset($this->js_files))
|
||||
$this->js_files = array();
|
||||
// avoid useless operation...
|
||||
if (in_array($js_uri, $this->js_files))
|
||||
|
||||
+8
-14
@@ -82,7 +82,7 @@ class GroupCore extends ObjectModel
|
||||
return parent::getTranslationsFields(array('name'));
|
||||
}
|
||||
|
||||
static public function getGroups($id_lang)
|
||||
public static function getGroups($id_lang)
|
||||
{
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
||||
SELECT g.`id_group`, g.`reduction`, g.`price_display_method`, gl.`name`
|
||||
@@ -110,21 +110,15 @@ class GroupCore extends ObjectModel
|
||||
'.($limit > 0 ? 'LIMIT '.(int)$start.', '.(int)$limit : ''));
|
||||
}
|
||||
|
||||
static public function getReduction($id_customer = NULL)
|
||||
public static function getReduction($id_customer = NULL)
|
||||
{
|
||||
if ($id_customer === NULL)
|
||||
$id_customer = 0;
|
||||
if (!isset(self::$_cacheReduction['customer'][$id_customer]))
|
||||
{
|
||||
if ($id_customer)
|
||||
$customer = new Customer((int)($id_customer));
|
||||
self::$_cacheReduction['customer'][$id_customer] = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
||||
if (!isset(self::$_cacheReduction['customer'][(int)$id_customer]))
|
||||
self::$_cacheReduction['customer'][(int)$id_customer] = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
||||
SELECT `reduction`
|
||||
FROM `'._DB_PREFIX_.'group`
|
||||
WHERE `id_group` = '.((isset($customer) AND Validate::isLoadedObject($customer)) ? (int)($customer->id_default_group) : 1));
|
||||
WHERE `id_group` = '.((int)$id_customer ? Customer::getDefaultGroupId((int)$id_customer) : 1));
|
||||
return self::$_cacheReduction['customer'][(int)$id_customer];
|
||||
}
|
||||
return self::$_cacheReduction['customer'][$id_customer];
|
||||
}
|
||||
|
||||
public static function getReductionByIdGroup($id_group)
|
||||
{
|
||||
@@ -138,7 +132,7 @@ class GroupCore extends ObjectModel
|
||||
return self::$_cacheReduction['group'][$id_group];
|
||||
}
|
||||
|
||||
static public function getPriceDisplayMethod($id_group)
|
||||
public static function getPriceDisplayMethod($id_group)
|
||||
{
|
||||
if (!isset(self::$_groupPriceDisplayMethod[$id_group]))
|
||||
self::$_groupPriceDisplayMethod[$id_group] = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
||||
@@ -148,7 +142,7 @@ class GroupCore extends ObjectModel
|
||||
return self::$_groupPriceDisplayMethod[$id_group];
|
||||
}
|
||||
|
||||
static public function getDefaultPriceDisplayMethod()
|
||||
public static function getDefaultPriceDisplayMethod()
|
||||
{
|
||||
return self::getPriceDisplayMethod(1);
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ class GroupReductionCore extends ObjectModel
|
||||
return Db::getInstance()->Execute(rtrim($query, ', '));
|
||||
}
|
||||
|
||||
static public function getGroupReductions($id_group, $id_lang)
|
||||
public static function getGroupReductions($id_group, $id_lang)
|
||||
{
|
||||
return Db::getInstance()->ExecuteS('
|
||||
SELECT gr.`id_group_reduction`, gr.`id_group`, gr.`id_category`, gr.`reduction`, cl.`name` AS category_name
|
||||
@@ -92,14 +92,14 @@ class GroupReductionCore extends ObjectModel
|
||||
);
|
||||
}
|
||||
|
||||
static public function getValueForProduct($id_product, $id_group)
|
||||
public static function getValueForProduct($id_product, $id_group)
|
||||
{
|
||||
if (!isset(self::$reductionCache[$id_product.'-'.$id_group]))
|
||||
self::$reductionCache[$id_product.'-'.$id_group] = Db::getInstance()->getValue('SELECT `reduction` FROM `'._DB_PREFIX_.'product_group_reduction_cache` WHERE `id_product` = '.(int)($id_product).' AND `id_group` = '.(int)($id_group));
|
||||
return self::$reductionCache[$id_product.'-'.$id_group];
|
||||
}
|
||||
|
||||
static public function doesExist($id_group, $id_category)
|
||||
public static function doesExist($id_group, $id_category)
|
||||
{
|
||||
return (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT `id_group` FROM `'._DB_PREFIX_.'group_reduction` WHERE `id_group` = '.(int)($id_group).' AND `id_category` = '.(int)($id_category));
|
||||
}
|
||||
|
||||
Executable
+118
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2011 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/osl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2011 PrestaShop SA
|
||||
* @version Release: $Revision$
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
/*
|
||||
* TODO : move HTML code in template files
|
||||
*/
|
||||
|
||||
class HelperCore
|
||||
{
|
||||
public static $translationsKeysForAdminCategorieTree = array(
|
||||
'Home', 'selected', 'selecteds', 'Collapse All', 'Expand All', 'Check All', 'Uncheck All'
|
||||
);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param type $trads values of translations keys
|
||||
* For the moment, translation are not automatic
|
||||
* @param type $selected_cat array of selected categories
|
||||
* Format
|
||||
* Array
|
||||
(
|
||||
[0] => 1
|
||||
[1] => 2
|
||||
)
|
||||
* OR
|
||||
Array
|
||||
(
|
||||
[1] => Array
|
||||
(
|
||||
[id_category] => 1
|
||||
[name] => Home page
|
||||
[link_rewrite] => home
|
||||
)
|
||||
)
|
||||
* @param type $input_name name of input
|
||||
* @return string
|
||||
*/
|
||||
public static function renderAdminCategorieTree($trads, $selected_cat = array(), $input_name = 'categoryBox')
|
||||
{
|
||||
$html = '
|
||||
<script src="../js/jquery/treeview/jquery.treeview.js" type="text/javascript"></script>
|
||||
<script src="../js/jquery/treeview/jquery.treeview.async.js" type="text/javascript"></script>
|
||||
<script src="../js/jquery/treeview/jquery.treeview.edit.js" type="text/javascript"></script>
|
||||
<script src="../js/admin-categories-tree.js" type="text/javascript"></script>
|
||||
<script type="text/javascript">
|
||||
var inputName = "'.$input_name.'";
|
||||
var selectedCat = "'.implode(',', array_keys($selected_cat)).'";
|
||||
</script>
|
||||
<script type="text/javascript">
|
||||
var selectedLabel = \''.$trads['selected'].'\';
|
||||
var home = \''.$trads['Home'].'\';
|
||||
</script>
|
||||
<link type="text/css" rel="stylesheet" href="../css/jquery.treeview.css" />
|
||||
';
|
||||
|
||||
$html .= '
|
||||
<div style="background-color:#F4E6C9; width:99%;padding:5px 0 5px 5px;">
|
||||
<a href="#" id="collapse_all" >'.$trads['Collapse All'].'</a>
|
||||
- <a href="#" id="expand_all" >'.$trads['Expand All'].'</a>
|
||||
- <a href="#" id="check_all" >'.$trads['Check All'].'</a>
|
||||
- <a href="#" id="uncheck_all" >'.$trads['Uncheck All'].'</a>
|
||||
</div>
|
||||
';
|
||||
|
||||
$home_is_selected = false;
|
||||
foreach($selected_cat AS $cat)
|
||||
{
|
||||
if (is_array($cat))
|
||||
{
|
||||
if ($cat['id_category'] != 1)
|
||||
$html .= '<input type="hidden" name="'.$input_name.'[]" value="'.$cat['id_category'].'" >';
|
||||
else
|
||||
$home_is_selected = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($cat != 1)
|
||||
$html .= '<input type="hidden" name="'.$input_name.'[]" value="'.$cat.'" >';
|
||||
else
|
||||
$home_is_selected = true;
|
||||
}
|
||||
}
|
||||
$html .= '
|
||||
<ul id="categories-treeview" class="filetree">
|
||||
<li id="1" class="hasChildren">
|
||||
<span class="folder"> <input type="checkbox" name="'.$input_name.'[]" value="1" '.($home_is_selected ? 'checked' : '').' onclick="clickOnCategoryBox($(this));" /> '.$trads['Home'].'</span>
|
||||
<ul>
|
||||
<li><span class="placeholder"> </span></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>';
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -131,7 +131,7 @@ class HookCore extends ObjectModel
|
||||
$order = new Order((int)($id_order));
|
||||
$newOS = new OrderState((int)($newOrderStatusId), $order->id_lang);
|
||||
|
||||
$return = ((int)($newOS->id) == _PS_OS_PAYMENT_) ? Module::hookExec('paymentConfirm', array('id_order' => (int)($order->id))) : true;
|
||||
$return = ((int)($newOS->id) == Configuration::get('PS_OS_PAYMENT')) ? Module::hookExec('paymentConfirm', array('id_order' => (int)($order->id))) : true;
|
||||
$return = Module::hookExec('updateOrderStatus', array('newOrderStatus' => $newOS, 'id_order' => (int)($order->id))) AND $return;
|
||||
return $return;
|
||||
}
|
||||
|
||||
+129
-41
@@ -47,6 +47,9 @@ class ImageCore extends ObjectModel
|
||||
/** @var string image extension */
|
||||
public $image_format = 'jpg';
|
||||
|
||||
/** @var string path to index.php file to be copied to new image folders */
|
||||
public $source_index;
|
||||
|
||||
/** @var string image folder */
|
||||
protected $folder;
|
||||
|
||||
@@ -70,6 +73,7 @@ class ImageCore extends ObjectModel
|
||||
{
|
||||
parent::__construct($id, $id_lang);
|
||||
$this->image_dir = _PS_PROD_IMG_DIR_;
|
||||
$this->source_index = _PS_PROD_IMG_DIR_.'index.php';
|
||||
}
|
||||
|
||||
public function getFields()
|
||||
@@ -118,7 +122,7 @@ class ImageCore extends ObjectModel
|
||||
* @param integer $id_product Product ID
|
||||
* @return array Images
|
||||
*/
|
||||
static public function getImages($id_lang, $id_product)
|
||||
public static function getImages($id_lang, $id_product)
|
||||
{
|
||||
return Db::getInstance()->ExecuteS('
|
||||
SELECT *
|
||||
@@ -133,7 +137,7 @@ class ImageCore extends ObjectModel
|
||||
*
|
||||
* @return array Images
|
||||
*/
|
||||
static public function getAllImages()
|
||||
public static function getAllImages()
|
||||
{
|
||||
return Db::getInstance()->ExecuteS('
|
||||
SELECT `id_image`, `id_product`
|
||||
@@ -147,7 +151,7 @@ class ImageCore extends ObjectModel
|
||||
* @param integer $id_product Product ID
|
||||
* @return integer number of images
|
||||
*/
|
||||
static public function getImagesTotal($id_product)
|
||||
public static function getImagesTotal($id_product)
|
||||
{
|
||||
$result = Db::getInstance()->getRow('
|
||||
SELECT COUNT(`id_image`) AS total
|
||||
@@ -162,7 +166,7 @@ class ImageCore extends ObjectModel
|
||||
* @param integer $id_product Product ID
|
||||
* @return integer highest position of images
|
||||
*/
|
||||
static public function getHighestPosition($id_product)
|
||||
public static function getHighestPosition($id_product)
|
||||
{
|
||||
$result = Db::getInstance()->getRow('
|
||||
SELECT MAX(`position`) AS max
|
||||
@@ -177,7 +181,7 @@ class ImageCore extends ObjectModel
|
||||
* @param integer $id_product Product ID
|
||||
* @return boolean result
|
||||
*/
|
||||
static public function deleteCover($id_product)
|
||||
public static function deleteCover($id_product)
|
||||
{
|
||||
if (!Validate::isUnsignedId($id_product))
|
||||
die(Tools::displayError());
|
||||
@@ -196,7 +200,7 @@ class ImageCore extends ObjectModel
|
||||
* @param integer $id_product Product ID
|
||||
* @return boolean result
|
||||
*/
|
||||
static public function getCover($id_product)
|
||||
public static function getCover($id_product)
|
||||
{
|
||||
return Db::getInstance()->getRow('
|
||||
SELECT * FROM `'._DB_PREFIX_.'image`
|
||||
@@ -210,7 +214,7 @@ class ImageCore extends ObjectModel
|
||||
* @param integer $id_product_old Source product ID
|
||||
* @param boolean $id_product_new Destination product ID
|
||||
*/
|
||||
static public function duplicateProductImages($id_product_old, $id_product_new, $combinationImages)
|
||||
public static function duplicateProductImages($id_product_old, $id_product_new, $combinationImages)
|
||||
{
|
||||
$imagesTypes = ImageType::getImagesTypes('products');
|
||||
$result = Db::getInstance()->ExecuteS('
|
||||
@@ -222,21 +226,22 @@ class ImageCore extends ObjectModel
|
||||
$imageOld = new Image($row['id_image']);
|
||||
$imageNew = clone $imageOld;
|
||||
$imageNew->id_product = (int)($id_product_new);
|
||||
$imageOld->id_product = (int)($id_product_old);
|
||||
// A new id is generated for the cloned image when calling add()
|
||||
if ($imageNew->add())
|
||||
{
|
||||
foreach ($imagesTypes AS $k => $imageType)
|
||||
$new_path = $imageNew->getPathForCreation();
|
||||
foreach ($imagesTypes AS $imageType)
|
||||
{
|
||||
if (file_exists(_PS_PROD_IMG_DIR_.$imageOld->getExistingImgPath().'-'.$imageType['name'].'.jpg'))
|
||||
{
|
||||
if (!Configuration::get('PS_LEGACY_IMAGES'))
|
||||
$imageNew->createImgFolder();
|
||||
copy(_PS_PROD_IMG_DIR_.$imageOld->getExistingImgPath().'-'.$imageType['name'].'.jpg', _PS_PROD_IMG_DIR_.
|
||||
$imageNew->getImgPath().'-'.$imageType['name'].'.jpg');
|
||||
copy(_PS_PROD_IMG_DIR_.$imageOld->getExistingImgPath().'-'.$imageType['name'].'.jpg',
|
||||
$new_path.'-'.$imageType['name'].'.jpg');
|
||||
}
|
||||
}
|
||||
if (file_exists(_PS_PROD_IMG_DIR_.$imageOld->getExistingImgPath().'.jpg'))
|
||||
copy(_PS_PROD_IMG_DIR_.$imageOld->getExistingImgPath().'.jpg',
|
||||
_PS_PROD_IMG_DIR_.$imageNew->getImgPath().'.jpg');
|
||||
copy(_PS_PROD_IMG_DIR_.$imageOld->getExistingImgPath().'.jpg', $new_path.'.jpg');
|
||||
|
||||
self::replaceAttributeImageAssociationId($combinationImages, (int)($imageOld->id), (int)($imageNew->id));
|
||||
}
|
||||
@@ -261,7 +266,7 @@ class ImageCore extends ObjectModel
|
||||
* @param integer $id_product_attribute_old
|
||||
* @return boolean
|
||||
*/
|
||||
static public function duplicateAttributeImageAssociations($combinationImages)
|
||||
public static function duplicateAttributeImageAssociations($combinationImages)
|
||||
{
|
||||
if (!isset($combinationImages['new']) OR !is_array($combinationImages['new']))
|
||||
return true;
|
||||
@@ -305,7 +310,7 @@ class ImageCore extends ObjectModel
|
||||
AND `position` = '.(int)($high_position));
|
||||
}
|
||||
|
||||
static public function getSize($type)
|
||||
public static function getSize($type)
|
||||
{
|
||||
if (!isset(self::$_cacheGetSize[$type]) OR self::$_cacheGetSize[$type] === NULL)
|
||||
self::$_cacheGetSize[$type] = Db::getInstance()->getRow('SELECT `width`, `height` FROM '._DB_PREFIX_.'image_type WHERE `name` = \''.pSQL($type).'\'');
|
||||
@@ -315,7 +320,7 @@ class ImageCore extends ObjectModel
|
||||
/**
|
||||
* Clear all images in tmp dir
|
||||
*/
|
||||
static public function clearTmpDir()
|
||||
public static function clearTmpDir()
|
||||
{
|
||||
foreach (scandir(_PS_TMP_IMG_DIR_) AS $d)
|
||||
if (preg_match('/(.*)\.jpg$/', $d))
|
||||
@@ -334,45 +339,53 @@ class ImageCore extends ObjectModel
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a product image from disk and remove the containing folder if empty
|
||||
* Delete the product image from disk and remove the containing folder if empty
|
||||
* Handles both legacy and new image filesystems
|
||||
*/
|
||||
public function deleteImage()
|
||||
{
|
||||
if (!$this->id)
|
||||
return false;
|
||||
|
||||
// Delete base image
|
||||
if (file_exists($this->image_dir.$this->getExistingImgPath().'.'.$this->image_format))
|
||||
unlink($this->image_dir.$this->getExistingImgPath().'.'.$this->image_format);
|
||||
else
|
||||
return false;
|
||||
|
||||
$files_to_delete = array();
|
||||
|
||||
// Delete auto-generated images
|
||||
$imageTypes = ImageType::getImagesTypes();
|
||||
foreach ($imageTypes AS $imageType)
|
||||
if (file_exists($this->image_dir.$this->getExistingImgPath().'-'.$imageType['name'].'.'.$this->image_format))
|
||||
unlink($this->image_dir.$this->getExistingImgPath().'-'.$imageType['name'].'.'.$this->image_format);
|
||||
$files_to_delete[] = $this->image_dir.$this->getExistingImgPath().'-'.$imageType['name'].'.'.$this->image_format;
|
||||
|
||||
// Can we remove the image folder?
|
||||
// Delete watermark image
|
||||
$files_to_delete[] = $this->image_dir.$this->getExistingImgPath().'-watermark.'.$this->image_format;
|
||||
// delete index.php
|
||||
$files_to_delete[] = $this->image_dir.$this->getImgFolder().'index.php';
|
||||
// Delete tmp images
|
||||
$files_to_delete[] = _PS_TMP_IMG_DIR_.'product_'.$this->id_product.'.'.$this->image_format;
|
||||
$files_to_delete[] = _PS_TMP_IMG_DIR_.'product_mini_'.$this->id_product.'.'.$this->image_format;
|
||||
|
||||
foreach ($files_to_delete as $file)
|
||||
if (file_exists($file) && !@unlink($file))
|
||||
return false;
|
||||
|
||||
// Can we delete the image folder?
|
||||
if (is_dir($this->image_dir.$this->getImgFolder()))
|
||||
{
|
||||
$remove_folder = true;
|
||||
$delete_folder = true;
|
||||
foreach (scandir($this->image_dir.$this->getImgFolder()) as $file)
|
||||
if (($file != '.' && $file != '..'))
|
||||
{
|
||||
$remove_folder = false;
|
||||
$delete_folder = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isset($remove_folder) && $remove_folder)
|
||||
if (isset($delete_folder) && $delete_folder)
|
||||
@rmdir($this->image_dir.$this->getImgFolder());
|
||||
|
||||
// Delete tmp images
|
||||
if (file_exists(_PS_TMP_IMG_DIR_.'product_'.$this->id_product.'.'.$this->image_format)
|
||||
&& !unlink(_PS_TMP_IMG_DIR_.'product_'.$this->id_product.'.'.$this->image_format))
|
||||
return false;
|
||||
if (file_exists(_PS_TMP_IMG_DIR_.'product_mini_'.$this->id_product.'.'.$this->image_format)
|
||||
&& !unlink(_PS_TMP_IMG_DIR_.'product_mini_'.$this->id_product.'.'.$this->image_format))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -398,14 +411,19 @@ class ImageCore extends ObjectModel
|
||||
// Can we remove the image folder?
|
||||
$remove_folder = true;
|
||||
foreach (scandir($path) as $file)
|
||||
if (($file != '.' && $file != '..'))
|
||||
if (($file != '.' && $file != '..'&& $file != 'index.php'))
|
||||
{
|
||||
$remove_folder = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if ($remove_folder)
|
||||
{
|
||||
// we're only removing index.php if it's a folder we want to delete
|
||||
if (file_exists($path.'index.php'))
|
||||
@unlink ($path.'index.php');
|
||||
@rmdir($path);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -417,6 +435,9 @@ class ImageCore extends ObjectModel
|
||||
*/
|
||||
public function getExistingImgPath()
|
||||
{
|
||||
if (!$this->id)
|
||||
return false;
|
||||
|
||||
if (!$this->existing_path)
|
||||
{
|
||||
if (Configuration::get('PS_LEGACY_IMAGES') && file_exists(_PS_PROD_IMG_DIR_.$this->id_product.'-'.$this->id.'.'.$this->image_format))
|
||||
@@ -451,8 +472,21 @@ class ImageCore extends ObjectModel
|
||||
*/
|
||||
public function createImgFolder()
|
||||
{
|
||||
if (!$this->id)
|
||||
return false;
|
||||
|
||||
if (!file_exists(_PS_PROD_IMG_DIR_.$this->getImgFolder()))
|
||||
return @mkdir(_PS_PROD_IMG_DIR_.$this->getImgFolder(), 0755, true);
|
||||
{
|
||||
// Apparently sometimes mkdir cannot set the rights, and sometimes chmod can't. Trying both.
|
||||
$success = @mkdir(_PS_PROD_IMG_DIR_.$this->getImgFolder(), 0755, true)
|
||||
|| @chmod(_PS_PROD_IMG_DIR_.$this->getImgFolder(), 0755);
|
||||
|
||||
// Create an index.php file in the new folder
|
||||
if ($success
|
||||
&& !file_exists(_PS_PROD_IMG_DIR_.$this->getImgFolder().'index.php')
|
||||
&& file_exists($this->source_index))
|
||||
return @copy($this->source_index, _PS_PROD_IMG_DIR_.$this->getImgFolder().'index.php');
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -463,6 +497,9 @@ class ImageCore extends ObjectModel
|
||||
*/
|
||||
public function getImgPath()
|
||||
{
|
||||
if (!$this->id)
|
||||
return false;
|
||||
|
||||
$path = $this->getImgFolder().$this->id;
|
||||
return $path;
|
||||
}
|
||||
@@ -484,6 +521,7 @@ class ImageCore extends ObjectModel
|
||||
/**
|
||||
* Move all legacy product image files from the image folder root to their subfolder in the new filesystem.
|
||||
* If max_execution_time is provided, stops before timeout and returns string "timeout".
|
||||
* If any image cannot be moved, stops and returns "false"
|
||||
*
|
||||
* @return mixed success or timeout
|
||||
*/
|
||||
@@ -491,26 +529,76 @@ class ImageCore extends ObjectModel
|
||||
{
|
||||
$start_time = time();
|
||||
$image = null;
|
||||
$result = true;
|
||||
foreach (scandir(_PS_PROD_IMG_DIR_) as $file)
|
||||
{
|
||||
// matches the base product image or the thumbnails
|
||||
if (preg_match('/^([0-9]+\-)([0-9]+)(\-(.*))?\.jpg$/', $file, $matches))
|
||||
{
|
||||
// don't recreate an image object for each image type
|
||||
if (!$image || $image->id !== (int)$matches[2])
|
||||
$image = new Image((int)$matches[2]);
|
||||
|
||||
if ($image->createImgFolder())
|
||||
{
|
||||
// create the new folder if it does not exist
|
||||
if (!$image->createImgFolder())
|
||||
return false;
|
||||
|
||||
// move the image
|
||||
$new_path = _PS_PROD_IMG_DIR_.$image->getImgPath().(isset($matches[3]) ? $matches[3] : '').'.jpg';
|
||||
$result &= @rename(_PS_PROD_IMG_DIR_.$file, $new_path);
|
||||
if (file_exists($new_path))
|
||||
return false;
|
||||
if (!@rename(_PS_PROD_IMG_DIR_.$file, $new_path) || !file_exists($new_path))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if ((int)$max_execution_time != 0 && (time() - $start_time > (int)$max_execution_time - 4))
|
||||
return 'timeout';
|
||||
}
|
||||
return $result;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function testFileSystem()
|
||||
{
|
||||
$safe_mode = ini_get('safe_mode');
|
||||
if ($safe_mode)
|
||||
return false;
|
||||
$folder1 = _PS_PROD_IMG_DIR_.'testfilesystem/';
|
||||
$test_folder = $folder1.'testsubfolder/';
|
||||
if (file_exists($test_folder))
|
||||
{
|
||||
@rmdir($test_folder);
|
||||
@rmdir($folder1);
|
||||
}
|
||||
if (file_exists($test_folder))
|
||||
return false;
|
||||
@mkdir($test_folder, 0755, true);
|
||||
@chmod($test_folder, 0755);
|
||||
if (!is_writeable($test_folder))
|
||||
return false;
|
||||
@rmdir($test_folder);
|
||||
@rmdir($folder1);
|
||||
if (file_exists($folder1))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the path where a product image should be created (without file format)
|
||||
*
|
||||
* @return string path
|
||||
*/
|
||||
public function getPathForCreation()
|
||||
{
|
||||
if (!$this->id)
|
||||
return false;
|
||||
if(Configuration::get('PS_LEGACY_IMAGES'))
|
||||
{
|
||||
if (!$this->id_product)
|
||||
return false;
|
||||
$path = $this->id_product.'-'.$this->id;
|
||||
} else
|
||||
{
|
||||
$path = $this->getImgPath();
|
||||
$this->createImgFolder();
|
||||
}
|
||||
return _PS_PROD_IMG_DIR_.$path;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ class ImageTypeCore extends ObjectModel
|
||||
* @param string|null Image type
|
||||
* @return array Image type definitions
|
||||
*/
|
||||
static public function getImagesTypes($type = NULL)
|
||||
public static function getImagesTypes($type = NULL)
|
||||
{
|
||||
if (!isset(self::$images_types_cache[$type]))
|
||||
{
|
||||
@@ -123,12 +123,12 @@ class ImageTypeCore extends ObjectModel
|
||||
* @param string $typeName Name
|
||||
* @return integer Number of results found
|
||||
*/
|
||||
static public function typeAlreadyExists($typeName)
|
||||
public static function typeAlreadyExists($typeName)
|
||||
{
|
||||
if (!Validate::isImageTypeName($typeName))
|
||||
die(Tools::displayError());
|
||||
|
||||
$result = Db::getInstance()->ExecuteS('
|
||||
Db::getInstance()->ExecuteS('
|
||||
SELECT `id_image_type`
|
||||
FROM `'._DB_PREFIX_.'image_type`
|
||||
WHERE `name` = \''.pSQL($typeName).'\'');
|
||||
@@ -141,7 +141,7 @@ class ImageTypeCore extends ObjectModel
|
||||
* @param string $name
|
||||
* @param string $type
|
||||
*/
|
||||
static public function getByNameNType($name, $type)
|
||||
public static function getByNameNType($name, $type)
|
||||
{
|
||||
return Db::getInstance()->getRow('SELECT `id_image_type`, `name`, `width`, `height`, `products`, `categories`, `manufacturers`, `suppliers`, `scenes` FROM `'._DB_PREFIX_.'image_type` WHERE `name` = \''.pSQL($name).'\' AND `'.pSQL($type).'` = 1');
|
||||
}
|
||||
|
||||
+21
-11
@@ -38,12 +38,15 @@ class LanguageCore extends ObjectModel
|
||||
/** @var string 5-letter iso code */
|
||||
public $language_code;
|
||||
|
||||
/** @var bool true if this language is right to left language */
|
||||
public $is_rtl = false;
|
||||
|
||||
/** @var boolean Status */
|
||||
public $active = true;
|
||||
|
||||
protected $fieldsRequired = array('name', 'iso_code');
|
||||
protected $fieldsSize = array('name' => 32, 'iso_code' => 2, 'language_code' => 5);
|
||||
protected $fieldsValidate = array('name' => 'isGenericName', 'iso_code' => 'isLanguageIsoCode', 'language_code' => 'isLanguageCode', 'active' => 'isBool');
|
||||
protected $fieldsValidate = array('name' => 'isGenericName', 'iso_code' => 'isLanguageIsoCode', 'language_code' => 'isLanguageCode', 'active' => 'isBool', 'is_rtl' => 'isBool');
|
||||
|
||||
protected $table = 'lang';
|
||||
protected $identifier = 'id_lang';
|
||||
@@ -69,9 +72,10 @@ class LanguageCore extends ObjectModel
|
||||
$fields['name'] = pSQL($this->name);
|
||||
$fields['iso_code'] = pSQL(strtolower($this->iso_code));
|
||||
$fields['language_code'] = pSQL(strtolower($this->language_code));
|
||||
$fields['is_rtl'] = (int)$this->is_rtl;
|
||||
if (empty($fields['language_code']))
|
||||
$fields['language_code'] = $fields['iso_code'];
|
||||
$fields['active'] = (int)($this->active);
|
||||
$fields['active'] = (int)$this->active;
|
||||
return $fields;
|
||||
}
|
||||
|
||||
@@ -103,7 +107,8 @@ class LanguageCore extends ObjectModel
|
||||
return ($resUpdateSQL AND Tools::generateHtaccess(dirname(__FILE__).'/../.htaccess',
|
||||
(int)(Configuration::get('PS_REWRITING_SETTINGS')),
|
||||
(int)(Configuration::get('PS_HTACCESS_CACHE_CONTROL')),
|
||||
Configuration::get('PS_HTACCESS_SPECIFIC')
|
||||
Configuration::get('PS_HTACCESS_SPECIFIC'),
|
||||
(int)Configuration::get('PS_HTACCESS_DISABLE_MULTIVIEWS')
|
||||
));
|
||||
}
|
||||
|
||||
@@ -118,7 +123,8 @@ class LanguageCore extends ObjectModel
|
||||
return (Tools::generateHtaccess(dirname(__FILE__).'/../.htaccess',
|
||||
(int)(Configuration::get('PS_REWRITING_SETTINGS')),
|
||||
(int)(Configuration::get('PS_HTACCESS_CACHE_CONTROL')),
|
||||
Configuration::get('PS_HTACCESS_SPECIFIC')
|
||||
Configuration::get('PS_HTACCESS_SPECIFIC'),
|
||||
(int)Configuration::get('PS_HTACCESS_DISABLE_MULTIVIEWS')
|
||||
));
|
||||
}
|
||||
|
||||
@@ -140,7 +146,7 @@ class LanguageCore extends ObjectModel
|
||||
{
|
||||
if (isset(self::$_checkedLangs[$iso_code]) AND self::$_checkedLangs[$iso_code])
|
||||
return true;
|
||||
foreach (self::getFilesList($iso_code, _THEME_NAME_, false, false, false, true) as $key => $file)
|
||||
foreach (array_keys(self::getFilesList($iso_code, _THEME_NAME_, false, false, false, true)) as $key)
|
||||
if (!file_exists($key))
|
||||
return false;
|
||||
self::$_checkedLangs[$iso_code] = true;
|
||||
@@ -234,7 +240,7 @@ class LanguageCore extends ObjectModel
|
||||
if ($modules)
|
||||
{
|
||||
$modList = Module::getModulesDirOnDisk();
|
||||
foreach ($modList as $k => $mod)
|
||||
foreach ($modList as $mod)
|
||||
{
|
||||
$modDir = _PS_MODULE_DIR_.$mod;
|
||||
// Lang file
|
||||
@@ -290,6 +296,7 @@ class LanguageCore extends ObjectModel
|
||||
|
||||
foreach($tables as $table)
|
||||
foreach($table as $t)
|
||||
if ($t != _DB_PREFIX_.'configuration_lang')
|
||||
$langTables[] = $t;
|
||||
|
||||
Db::getInstance()->Execute('SET @id_lang_default = (SELECT c.`value` FROM `'._DB_PREFIX_.'configuration` c WHERE c.`name` = \'PS_LANG_DEFAULT\' LIMIT 1)');
|
||||
@@ -359,7 +366,7 @@ class LanguageCore extends ObjectModel
|
||||
if (file_exists($key))
|
||||
unlink($key);
|
||||
$modList = scandir(_PS_MODULE_DIR_);
|
||||
foreach ($modList as $k => $mod)
|
||||
foreach ($modList as $mod)
|
||||
{
|
||||
self::recurseDeleteDir(_PS_MODULE_DIR_.$mod.'/mails/'.$this->iso_code);
|
||||
$files = @scandir(_PS_MODULE_DIR_.$mod.'/mails/');
|
||||
@@ -368,7 +375,7 @@ class LanguageCore extends ObjectModel
|
||||
|
||||
if(file_exists(_PS_MODULE_DIR_.$mod.'/'.$this->iso_code.'.php'))
|
||||
{
|
||||
$return = unlink(_PS_MODULE_DIR_.$mod.'/'.$this->iso_code.'.php');
|
||||
unlink(_PS_MODULE_DIR_.$mod.'/'.$this->iso_code.'.php');
|
||||
$files = @scandir(_PS_MODULE_DIR_.$mod);
|
||||
if (count($files) <= 2)
|
||||
self::recurseDeleteDir(_PS_MODULE_DIR_.$mod);
|
||||
@@ -403,7 +410,8 @@ class LanguageCore extends ObjectModel
|
||||
return Tools::generateHtaccess(dirname(__FILE__).'/../.htaccess',
|
||||
(int)(Configuration::get('PS_REWRITING_SETTINGS')),
|
||||
(int)(Configuration::get('PS_HTACCESS_CACHE_CONTROL')),
|
||||
Configuration::get('PS_HTACCESS_SPECIFIC')
|
||||
Configuration::get('PS_HTACCESS_SPECIFIC'),
|
||||
(int)Configuration::get('PS_HTACCESS_DISABLE_MULTIVIEWS')
|
||||
);
|
||||
}
|
||||
|
||||
@@ -426,7 +434,8 @@ class LanguageCore extends ObjectModel
|
||||
Tools::generateHtaccess(dirname(__FILE__).'/../.htaccess',
|
||||
(int)(Configuration::get('PS_REWRITING_SETTINGS')),
|
||||
(int)(Configuration::get('PS_HTACCESS_CACHE_CONTROL')),
|
||||
Configuration::get('PS_HTACCESS_SPECIFIC')
|
||||
Configuration::get('PS_HTACCESS_SPECIFIC'),
|
||||
(int)Configuration::get('PS_HTACCESS_DISABLE_MULTIVIEWS')
|
||||
);
|
||||
|
||||
return $result;
|
||||
@@ -566,7 +575,8 @@ class LanguageCore extends ObjectModel
|
||||
return Tools::generateHtaccess(dirname(__FILE__).'/../.htaccess',
|
||||
(int)(Configuration::get('PS_REWRITING_SETTINGS')),
|
||||
(int)(Configuration::get('PS_HTACCESS_CACHE_CONTROL')),
|
||||
Configuration::get('PS_HTACCESS_SPECIFIC')
|
||||
Configuration::get('PS_HTACCESS_SPECIFIC'),
|
||||
(int)Configuration::get('PS_HTACCESS_DISABLE_MULTIVIEWS')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
+3
-2
@@ -234,9 +234,10 @@ class LinkCore
|
||||
*/
|
||||
public function getImageLink($name, $ids, $type = NULL)
|
||||
{
|
||||
// legacy mode
|
||||
if (Configuration::get('PS_LEGACY_IMAGES')
|
||||
// legacy mode or default image
|
||||
if ((Configuration::get('PS_LEGACY_IMAGES')
|
||||
&& (file_exists(_PS_PROD_IMG_DIR_.$ids.($type ? '-'.$type : '').'.jpg')))
|
||||
|| strpos($ids, 'default') !== false)
|
||||
{
|
||||
if ($this->allow == 1)
|
||||
$uri_path = __PS_BASE_URI__.$ids.($type ? '-'.$type : '').'/'.$name.'.jpg';
|
||||
|
||||
@@ -261,7 +261,6 @@ class LocalizationPackCore
|
||||
$county_behavior = (int)$rule_attributes['county_behavior'];
|
||||
}
|
||||
|
||||
|
||||
// Creation
|
||||
$tr = new TaxRule();
|
||||
$tr->id_tax_rules_group = $trg->id;
|
||||
@@ -283,7 +282,7 @@ class LocalizationPackCore
|
||||
{
|
||||
if (isset($xml->currencies->currency))
|
||||
{
|
||||
if (!$feed = @simplexml_load_file('http://www.prestashop.com/xml/currencies.xml') AND !$feed = @simplexml_load_file(dirname(__FILE__).'/../localization/currencies.xml'))
|
||||
if (!$feed = Tools::simplexml_load_file('http://www.prestashop.com/xml/currencies.xml') AND !$feed = @simplexml_load_file(dirname(__FILE__).'/../localization/currencies.xml'))
|
||||
{
|
||||
$this->_errors[] = Tools::displayError('Cannot parse the currencies XML feed.');
|
||||
return false;
|
||||
@@ -342,7 +341,9 @@ class LocalizationPackCore
|
||||
foreach ($native_lang AS $lang)
|
||||
$native_iso_code[] = $lang['iso_code'];
|
||||
if ((in_array((string)$attributes['iso_code'], $native_iso_code) AND !$install_mode) OR !in_array((string)$attributes['iso_code'], $native_iso_code))
|
||||
if(@fsockopen('www.prestashop.com', 80, $errno = 0, $errstr = '', 10))
|
||||
$errno = 0;
|
||||
$errstr = '';
|
||||
if(@fsockopen('www.prestashop.com', 80, $errno, $errstr, 10))
|
||||
{
|
||||
if ($lang_pack = Tools::jsonDecode(Tools::file_get_contents('http://www.prestashop.com/download/lang_packs/get_language_pack.php?version='._PS_VERSION_.'&iso_lang='.$attributes['iso_code'])))
|
||||
{
|
||||
|
||||
+2
-2
@@ -77,7 +77,7 @@ class LoggerCore extends ObjectModel
|
||||
return $fields;
|
||||
}
|
||||
|
||||
static public function sendByMail($log)
|
||||
public static function sendByMail($log)
|
||||
{
|
||||
/* Send e-mail to the shop owner only if the minimal severity level has been reached */
|
||||
if (intval(Configuration::get('PS_LOGS_BY_EMAIL')) <= intval($log->severity))
|
||||
@@ -95,7 +95,7 @@ class LoggerCore extends ObjectModel
|
||||
* @param boolean $allowDuplicate if set to true, can log several time the same information (not recommended)
|
||||
* @return boolean true if succeed
|
||||
*/
|
||||
static public function addLog($message, $severity = 1, $errorCode = NULL, $objectType = NULL, $objectId = NULL, $allowDuplicate = false)
|
||||
public static function addLog($message, $severity = 1, $errorCode = NULL, $objectType = NULL, $objectId = NULL, $allowDuplicate = false)
|
||||
{
|
||||
$log = new Logger();
|
||||
$log->severity = intval($severity);
|
||||
|
||||
+46
-18
@@ -32,7 +32,7 @@ include_once(_PS_SWIFT_DIR_.'Swift/Plugin/Decorator.php');
|
||||
|
||||
class MailCore
|
||||
{
|
||||
static public function Send($id_lang, $template, $subject, $templateVars, $to, $toName = NULL, $from = NULL, $fromName = NULL, $fileAttachment = NULL, $modeSMTP = NULL, $templatePath = _PS_MAIL_DIR_)
|
||||
public static function Send($id_lang, $template, $subject, $templateVars, $to, $toName = NULL, $from = NULL, $fromName = NULL, $fileAttachment = NULL, $modeSMTP = NULL, $templatePath = _PS_MAIL_DIR_, $die = false)
|
||||
{
|
||||
$configuration = Configuration::getMultiple(array('PS_SHOP_EMAIL', 'PS_MAIL_METHOD', 'PS_MAIL_SERVER', 'PS_MAIL_USER', 'PS_MAIL_PASSWD', 'PS_SHOP_NAME', 'PS_MAIL_SMTP_ENCRYPTION', 'PS_MAIL_SMTP_PORT', 'PS_MAIL_METHOD', 'PS_MAIL_TYPE'));
|
||||
if(!isset($configuration['PS_MAIL_SMTP_ENCRYPTION'])) $configuration['PS_MAIL_SMTP_ENCRYPTION'] = 'off';
|
||||
@@ -42,26 +42,42 @@ class MailCore
|
||||
if (!isset($fromName)) $fromName = $configuration['PS_SHOP_NAME'];
|
||||
|
||||
if (!empty($from) AND !Validate::isEmail($from))
|
||||
die(Tools::displayError('Error: parameter "from" is corrupted'));
|
||||
|
||||
{
|
||||
Tools::dieOrLog(Tools::displayError('Error: parameter "from" is corrupted'), $die);
|
||||
return false;
|
||||
}
|
||||
if (!empty($fromName) AND !Validate::isMailName($fromName))
|
||||
die(Tools::displayError('Error: parameter "fromName" is corrupted'));
|
||||
|
||||
{
|
||||
Tools::dieOrLog(Tools::displayError('Error: parameter "fromName" is corrupted'), $die);
|
||||
return false;
|
||||
}
|
||||
if (!is_array($to) AND !Validate::isEmail($to))
|
||||
die(Tools::displayError('Error: parameter "to" is corrupted'));
|
||||
{
|
||||
Tools::dieOrLog(Tools::displayError('Error: parameter "to" is corrupted'), $die);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!is_array($templateVars))
|
||||
die(Tools::displayError('Error: parameter "templateVars" is not an array'));
|
||||
{
|
||||
Tools::dieOrLog(Tools::displayError('Error: parameter "templateVars" is not an array'), $die);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Do not crash for this error, that may be a complicated customer name
|
||||
if (!empty($toName) AND !Validate::isMailName($toName))
|
||||
$toName = NULL;
|
||||
|
||||
if (!Validate::isTplName($template))
|
||||
die(Tools::displayError('Error: invalid email template'));
|
||||
{
|
||||
Tools::dieOrLog(Tools::displayError('Error: invalid email template'), $die);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Validate::isMailSubject($subject))
|
||||
die(Tools::displayError('Error: invalid email subject'));
|
||||
{
|
||||
Tools::dieOrLog(Tools::displayError('Error: invalid email subject'), $die);
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Construct multiple recipients list if needed */
|
||||
if (is_array($to))
|
||||
@@ -72,7 +88,10 @@ class MailCore
|
||||
$to_name = NULL;
|
||||
$addr = trim($addr);
|
||||
if (!Validate::isEmail($addr))
|
||||
die(Tools::displayError('Error: invalid email address'));
|
||||
{
|
||||
Tools::dieOrLog(Tools::displayError('Error: invalid email address'), $die);
|
||||
return false;
|
||||
}
|
||||
if ($toName AND is_array($toName) AND Validate::isGenericName($toName[$key]))
|
||||
$to_name = $toName[$key];
|
||||
$to_list->addTo($addr, $to_name);
|
||||
@@ -89,8 +108,10 @@ class MailCore
|
||||
if ($configuration['PS_MAIL_METHOD'] == 2)
|
||||
{
|
||||
if (empty($configuration['PS_MAIL_SERVER']) OR empty($configuration['PS_MAIL_SMTP_PORT']))
|
||||
die(Tools::displayError('Error: invalid SMTP server or SMTP port'));
|
||||
|
||||
{
|
||||
Tools::dieOrLog(Tools::displayError('Error: invalid SMTP server or SMTP port'), $die);
|
||||
return false;
|
||||
}
|
||||
$connection = new Swift_Connection_SMTP($configuration['PS_MAIL_SERVER'], $configuration['PS_MAIL_SMTP_PORT'], ($configuration['PS_MAIL_SMTP_ENCRYPTION'] == "ssl") ? Swift_Connection_SMTP::ENC_SSL : (($configuration['PS_MAIL_SMTP_ENCRYPTION'] == "tls") ? Swift_Connection_SMTP::ENC_TLS : Swift_Connection_SMTP::ENC_OFF));
|
||||
$connection->setTimeout(4);
|
||||
if (!$connection)
|
||||
@@ -109,7 +130,10 @@ class MailCore
|
||||
/* Get templates content */
|
||||
$iso = Language::getIsoById((int)($id_lang));
|
||||
if (!$iso)
|
||||
die (Tools::displayError('Error - No ISO code for email'));
|
||||
{
|
||||
Tools::dieOrLog(Tools::displayError('Error - No ISO code for email'), $die);
|
||||
return false;
|
||||
}
|
||||
$template = $iso.'/'.$template;
|
||||
|
||||
$moduleName = false;
|
||||
@@ -128,8 +152,10 @@ class MailCore
|
||||
$overrideMail = true;
|
||||
}
|
||||
elseif (!file_exists($templatePath.$template.'.txt') OR !file_exists($templatePath.$template.'.html'))
|
||||
die(Tools::displayError('Error - The following email template is missing:').' '.$templatePath.$template.'.txt');
|
||||
|
||||
{
|
||||
Tools::dieOrLog(Tools::displayError('Error - The following email template is missing:').' '.$templatePath.$template.'.txt', $die);
|
||||
return false;
|
||||
}
|
||||
$templateHtml = file_get_contents($templatePath.$template.'.html');
|
||||
$templateTxt = strip_tags(html_entity_decode(file_get_contents($templatePath.$template.'.txt'), NULL, 'utf-8'));
|
||||
|
||||
@@ -161,7 +187,7 @@ class MailCore
|
||||
catch (Swift_ConnectionException $e) { return false; }
|
||||
}
|
||||
|
||||
static public function sendMailTest($smtpChecked, $smtpServer, $content, $subject, $type, $to, $from, $smtpLogin, $smtpPassword, $smtpPort = 25, $smtpEncryption)
|
||||
public static function sendMailTest($smtpChecked, $smtpServer, $content, $subject, $type, $to, $from, $smtpLogin, $smtpPassword, $smtpPort = 25, $smtpEncryption)
|
||||
{
|
||||
$swift = NULL;
|
||||
$result = NULL;
|
||||
@@ -201,13 +227,15 @@ class MailCore
|
||||
*
|
||||
* @param string $string raw sentence (write directly in file)
|
||||
*/
|
||||
static public function l($string, Context $context = null)
|
||||
static public function l($string, $id_lang = null, Context $context = null)
|
||||
{
|
||||
global $_LANGMAIL;
|
||||
if (!$context)
|
||||
$context = Context::getContext();
|
||||
|
||||
|
||||
$key = str_replace('\'', '\\\'', $string);
|
||||
if ($id_lang == null)
|
||||
$id_lang = (!isset($context->language) OR !is_object($context->language)) ? (int)Configuration::get('PS_LANG_DEFAULT') : (int)$context->language->id;
|
||||
|
||||
$file_core = _PS_ROOT_DIR_.'/mails/'.$context->language->iso_code.'/lang.php';
|
||||
if (Tools::file_exists_cache($file_core) && empty($_LANGMAIL))
|
||||
|
||||
+17
-10
@@ -77,6 +77,7 @@ class ManufacturerCore extends ObjectModel
|
||||
|
||||
protected $webserviceParameters = array(
|
||||
'fields' => array(
|
||||
'active' => array(),
|
||||
'link_rewrite' => array('getter' => 'getLink', 'setter' => false),
|
||||
),
|
||||
'associations' => array(
|
||||
@@ -229,7 +230,7 @@ class ManufacturerCore extends ObjectModel
|
||||
$manufacturers[$i]['link_rewrite'] = 0;
|
||||
return $manufacturers;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return name from id
|
||||
*
|
||||
@@ -237,7 +238,7 @@ class ManufacturerCore extends ObjectModel
|
||||
* @return string name
|
||||
*/
|
||||
static protected $cacheName = array();
|
||||
static public function getNameById($id_manufacturer)
|
||||
public static function getNameById($id_manufacturer)
|
||||
{
|
||||
if (!isset(self::$cacheName[$id_manufacturer]))
|
||||
self::$cacheName[$id_manufacturer] = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
||||
@@ -245,7 +246,7 @@ class ManufacturerCore extends ObjectModel
|
||||
return self::$cacheName[$id_manufacturer];
|
||||
}
|
||||
|
||||
static public function getIdByName($name)
|
||||
public static function getIdByName($name)
|
||||
{
|
||||
$result = Db::getInstance()->getRow('
|
||||
SELECT `id_manufacturer`
|
||||
@@ -261,7 +262,7 @@ class ManufacturerCore extends ObjectModel
|
||||
return Tools::link_rewrite($this->name, false);
|
||||
}
|
||||
|
||||
static public function getProducts($id_manufacturer, $id_lang, $p, $n, $orderBy = NULL, $orderWay = NULL, $getTotal = false, $active = true, Context $context = null)
|
||||
static public function getProducts($id_manufacturer, $id_lang, $p, $n, $orderBy = NULL, $orderWay = NULL, $getTotal = false, $active = true, $active_category = true, Context $context = null)
|
||||
{
|
||||
if (!$context)
|
||||
$context = Context::getContext();
|
||||
@@ -287,7 +288,8 @@ class ManufacturerCore extends ObjectModel
|
||||
AND p.`id_product` IN (
|
||||
SELECT cp.`id_product`
|
||||
FROM `'._DB_PREFIX_.'category_group` cg
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`)'.
|
||||
($active_category ? ' INNER JOIN `'._DB_PREFIX_.'category` ca ON cp.`id_category` = ca.`id_category` AND ca.`active` = 1' : '').'
|
||||
WHERE cg.`id_group` '.$sqlGroups.'
|
||||
)';
|
||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql);
|
||||
@@ -312,11 +314,13 @@ class ManufacturerCore extends ObjectModel
|
||||
AND p.`id_product` IN (
|
||||
SELECT cp.`id_product`
|
||||
FROM `'._DB_PREFIX_.'category_group` cg
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`)'.
|
||||
($active_category ? ' INNER JOIN `'._DB_PREFIX_.'category` ca ON cp.`id_category` = ca.`id_category` AND ca.`active` = 1' : '').'
|
||||
WHERE cg.`id_group` '.$sqlGroups.'
|
||||
)
|
||||
ORDER BY '.(($orderBy == 'id_product') ? 'p.' : '').'`'.pSQL($orderBy).'` '.pSQL($orderWay).'
|
||||
LIMIT '.(((int)$p - 1) * (int)$n).','.(int)$n;
|
||||
|
||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql);
|
||||
if (!$result)
|
||||
return false;
|
||||
@@ -339,7 +343,7 @@ class ManufacturerCore extends ObjectModel
|
||||
* @param $id_manufacturer Manufacturer id
|
||||
* @return boolean
|
||||
*/
|
||||
static public function manufacturerExists($id_manufacturer)
|
||||
public static function manufacturerExists($id_manufacturer)
|
||||
{
|
||||
$row = Db::getInstance()->getRow('
|
||||
SELECT `id_manufacturer`
|
||||
@@ -374,16 +378,19 @@ class ManufacturerCore extends ObjectModel
|
||||
$ids = array();
|
||||
foreach ($id_addresses as $id)
|
||||
$ids[] = (int)$id['id'];
|
||||
Db::getInstance()->ExecuteS('
|
||||
$result1 = (Db::getInstance()->ExecuteS('
|
||||
UPDATE `'._DB_PREFIX_.'address`
|
||||
SET id_manufacturer = 0
|
||||
WHERE id_manufacturer = '.(int)$this->id.'
|
||||
AND deleted = 0');
|
||||
return (Db::getInstance()->ExecuteS('
|
||||
AND deleted = 0') !== false);
|
||||
$result2 = true;
|
||||
if (count($ids))
|
||||
$result2 = (Db::getInstance()->ExecuteS('
|
||||
UPDATE `'._DB_PREFIX_.'address`
|
||||
SET id_customer = 0, id_supplier = 0, id_manufacturer = '.(int)$this->id.'
|
||||
WHERE id_address IN('.implode(',', $ids).')
|
||||
AND deleted = 0') !== false);
|
||||
return ($result1 && $result2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -80,7 +80,7 @@ class MessageCore extends ObjectModel
|
||||
* @param integer $id_cart Cart ID
|
||||
* @return array Message
|
||||
*/
|
||||
static public function getMessageByCartId($id_cart)
|
||||
public static function getMessageByCartId($id_cart)
|
||||
{
|
||||
$db = Db::getInstance();
|
||||
$result = $db->getRow('
|
||||
@@ -151,7 +151,7 @@ class MessageCore extends ObjectModel
|
||||
* @param integer $id_message Message ID
|
||||
* @param integer $id_emplyee Employee ID
|
||||
*/
|
||||
static public function markAsReaded($id_message, $id_employee)
|
||||
public static function markAsReaded($id_message, $id_employee)
|
||||
{
|
||||
if (!Validate::isUnsignedId($id_message) OR !Validate::isUnsignedId($id_employee))
|
||||
die(Tools::displayError());
|
||||
|
||||
+5
-5
@@ -58,7 +58,7 @@ class MetaCore extends ObjectModel
|
||||
return parent::getTranslationsFields(array('title', 'description', 'keywords', 'url_rewrite'));
|
||||
}
|
||||
|
||||
static public function getPages($excludeFilled = false, $addPage = false)
|
||||
public static function getPages($excludeFilled = false, $addPage = false)
|
||||
{
|
||||
$selectedPages = array();
|
||||
if (!$files = scandir(_PS_ROOT_DIR_.'/controllers'))
|
||||
@@ -74,7 +74,7 @@ class MetaCore extends ObjectModel
|
||||
if ($excludeFilled)
|
||||
{
|
||||
$metas = self::getMetas();
|
||||
foreach ($metas as $k => $meta)
|
||||
foreach ($metas as $meta)
|
||||
if (in_array($meta['page'], $selectedPages))
|
||||
unset($selectedPages[array_search($meta['page'], $selectedPages)]);
|
||||
}
|
||||
@@ -87,7 +87,7 @@ class MetaCore extends ObjectModel
|
||||
return $selectedPages;
|
||||
}
|
||||
|
||||
static public function getMetas()
|
||||
public static function getMetas()
|
||||
{
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
||||
SELECT *
|
||||
@@ -109,7 +109,7 @@ class MetaCore extends ObjectModel
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql);
|
||||
|
||||
}
|
||||
|
||||
|
||||
static public function getMetaByPage($page, $id_lang, Context $context = null)
|
||||
{
|
||||
if (!$context)
|
||||
@@ -177,7 +177,7 @@ class MetaCore extends ObjectModel
|
||||
);
|
||||
}
|
||||
|
||||
static public function getEquivalentUrlRewrite($new_id_lang, $id_lang, $url_rewrite)
|
||||
public static function getEquivalentUrlRewrite($new_id_lang, $id_lang, $url_rewrite)
|
||||
{
|
||||
return Db::getInstance()->getValue('
|
||||
SELECT url_rewrite
|
||||
|
||||
+40
-25
@@ -72,7 +72,7 @@ abstract class ModuleCore
|
||||
|
||||
protected $identifier = 'id_module';
|
||||
|
||||
static public $_db;
|
||||
public static $_db;
|
||||
|
||||
/** @var array to store the limited country */
|
||||
public $limited_countries = array();
|
||||
@@ -456,6 +456,8 @@ abstract class ModuleCore
|
||||
*/
|
||||
public static function getModuleNameFromClass($currentClass)
|
||||
{
|
||||
global $cookie;
|
||||
|
||||
// Module can now define AdminTab keeping the module translations method,
|
||||
// i.e. in modules/[module name]/[iso_code].php
|
||||
if (!isset(self::$classInModule[$currentClass]))
|
||||
@@ -485,7 +487,7 @@ abstract class ModuleCore
|
||||
* @param string $moduleName Module name
|
||||
* @return Module instance
|
||||
*/
|
||||
static public function getInstanceByName($moduleName)
|
||||
public static function getInstanceByName($moduleName)
|
||||
{
|
||||
if (!Tools::file_exists_cache(_PS_MODULE_DIR_.$moduleName.'/'.$moduleName.'.php'))
|
||||
return false;
|
||||
@@ -523,6 +525,11 @@ abstract class ModuleCore
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function configXmlStringFormat($string)
|
||||
{
|
||||
return str_replace('\'', '\\\'', Tools::htmlentitiesDecodeUTF8($string));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return available modules
|
||||
*
|
||||
@@ -567,12 +574,12 @@ abstract class ModuleCore
|
||||
$item->warning = '';
|
||||
foreach ($xml_module as $k => $v)
|
||||
$item->$k = (string) $v;
|
||||
$item->displayName = Module::findTranslation($xml_module->name, $xml_module->displayName, (string)$xml_module->name);
|
||||
$item->description = Module::findTranslation($xml_module->name, $xml_module->description, (string)$xml_module->name);
|
||||
$item->author = Module::findTranslation($xml_module->name, $xml_module->author, (string)$xml_module->name);
|
||||
$item->displayName = Module::findTranslation($xml_module->name, self::configXmlStringFormat($xml_module->displayName), (string)$xml_module->name);
|
||||
$item->description = Module::findTranslation($xml_module->name, self::configXmlStringFormat($xml_module->description), (string)$xml_module->name);
|
||||
$item->author = Module::findTranslation($xml_module->name, self::configXmlStringFormat($xml_module->author), (string)$xml_module->name);
|
||||
|
||||
if (isset($xml_module->confirmUninstall))
|
||||
$item->confirmUninstall = Module::findTranslation($xml_module->name, $xml_module->confirmUninstall, (string)$xml_module->name);
|
||||
$item->confirmUninstall = Module::findTranslation($xml_module->name, self::configXmlStringFormat($xml_module->confirmUninstall), (string)$xml_module->name);
|
||||
|
||||
$item->active = 0;
|
||||
$moduleList[$moduleListCursor] = $item;
|
||||
@@ -641,7 +648,7 @@ abstract class ModuleCore
|
||||
$modules = scandir(_PS_MODULE_DIR_);
|
||||
foreach ($modules AS $name)
|
||||
{
|
||||
if (Tools::file_exists_cache($moduleFile = _PS_MODULE_DIR_.$name.'/'.$name.'.php'))
|
||||
if (is_dir(_PS_MODULE_DIR_.$name) && Tools::file_exists_cache(_PS_MODULE_DIR_.$name.'/'.$name.'.php'))
|
||||
{
|
||||
if (!Validate::isModuleName($name))
|
||||
die(Tools::displayError().' (Module '.$name.')');
|
||||
@@ -660,7 +667,6 @@ abstract class ModuleCore
|
||||
public static function getNonNativeModuleList()
|
||||
{
|
||||
$db = Db::getInstance();
|
||||
$modulesDirOnDisk = Module::getModulesDirOnDisk();
|
||||
|
||||
$module_list_xml = _PS_ROOT_DIR_.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'modules_list.xml';
|
||||
$nativeModules = simplexml_load_file($module_list_xml);
|
||||
@@ -766,7 +772,7 @@ abstract class ModuleCore
|
||||
$hookArgs['altern'] = ++$altern;
|
||||
|
||||
$display = call_user_func(array($moduleInstance, 'hook'.$hook_name), $hookArgs);
|
||||
if ($array['live_edit'] && ((Tools::isSubmit('live_edit') AND $ad = Tools::getValue('ad') AND (Tools::getValue('liveToken') == sha1(Tools::getValue('ad')._COOKIE_KEY_)))))
|
||||
if ($array['live_edit'] && ((Tools::isSubmit('live_edit') AND Tools::getValue('ad') AND (Tools::getValue('liveToken') == sha1(Tools::getValue('ad')._COOKIE_KEY_)))))
|
||||
{
|
||||
$live_edit = true;
|
||||
$output .= '<script type="text/javascript"> modules_list.push(\''.$moduleInstance->name.'\');</script>
|
||||
@@ -792,8 +798,24 @@ abstract class ModuleCore
|
||||
{
|
||||
$context = Context::getContext();
|
||||
$hookArgs = array('cookie' => $context->cookie, 'cart' => $context->cart);
|
||||
$billing = new Address((int)($context->cart->id_address_invoice));
|
||||
$output = '';
|
||||
|
||||
$result = self::getPaymentModules();
|
||||
|
||||
if ($result)
|
||||
foreach ($result AS $module)
|
||||
if (($moduleInstance = Module::getInstanceByName($module['name'])) AND is_callable(array($moduleInstance, 'hookpayment')))
|
||||
if (!$moduleInstance->currencies OR ($moduleInstance->currencies AND sizeof(Currency::checkPaymentCurrencies($moduleInstance->id))))
|
||||
$output .= call_user_func(array($moduleInstance, 'hookpayment'), $hookArgs);
|
||||
return $output;
|
||||
}
|
||||
|
||||
public static function getPaymentModules()
|
||||
{
|
||||
$context = Context::getContext();
|
||||
$id_customer = $context->customer->id;
|
||||
$billing = new Address((int)$context->cart->id_address_invoice);
|
||||
|
||||
$list = Context::getContext()->shop->getListOfID();
|
||||
$sql = 'SELECT DISTINCT h.`id_hook`, m.`name`, hm.`position`
|
||||
FROM `'._DB_PREFIX_.'module_country` mc
|
||||
@@ -811,12 +833,8 @@ abstract class ModuleCore
|
||||
GROUP BY hm.id_hook, hm.id_module
|
||||
ORDER BY hm.`position`, m.`name` DESC';
|
||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql);
|
||||
if ($result)
|
||||
foreach ($result AS $k => $module)
|
||||
if (($moduleInstance = Module::getInstanceByName($module['name'])) AND is_callable(array($moduleInstance, 'hookpayment')))
|
||||
if (!$moduleInstance->currencies OR ($moduleInstance->currencies AND sizeof(Currency::checkPaymentCurrencies($moduleInstance->id))))
|
||||
$output .= call_user_func(array($moduleInstance, 'hookpayment'), $hookArgs);
|
||||
return $output;
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -869,14 +887,17 @@ abstract class ModuleCore
|
||||
* @param boolean|string $specific filename to use in translation key
|
||||
* @return string Translation
|
||||
*/
|
||||
public function l($string, $specific = false)
|
||||
public function l($string, $specific = false, $id_lang = null)
|
||||
{
|
||||
if (self::$_generateConfigXmlMode)
|
||||
return $string;
|
||||
|
||||
global $_MODULES, $_MODULE;
|
||||
|
||||
if ($id_lang == null)
|
||||
$id_lang = (!isset($cookie) OR !is_object($cookie)) ? (int)(Configuration::get('PS_LANG_DEFAULT')) : (int)($cookie->id_lang);
|
||||
$file = _PS_MODULE_DIR_.$this->name.'/'.Context::getContext()->language->iso_code.'.php';
|
||||
|
||||
if (Tools::file_exists_cache($file) AND include_once($file))
|
||||
$_MODULES = !empty($_MODULES) ? array_merge($_MODULES, $_MODULE) : $_MODULE;
|
||||
|
||||
@@ -1115,13 +1136,7 @@ abstract class ModuleCore
|
||||
|
||||
protected function _clearCache($template, $cacheId = NULL, $compileId = NULL)
|
||||
{
|
||||
$context = Context::getContext();
|
||||
/* Use Smarty 3 API calls */
|
||||
if (!Configuration::get('PS_FORCE_SMARTY_2')) /* PHP version > 5.1.2 */
|
||||
return $context->smarty->clearCache($template ? $this->_getApplicableTemplateDir($template).$template : NULL, $cacheId, $compileId);
|
||||
/* or keep a backward compatibility if PHP version < 5.1.2 */
|
||||
else
|
||||
return $context->smarty->clear_cache($template ? $this->_getApplicableTemplateDir($template).$template : NULL, $cacheId, $compileId);
|
||||
Tools::clearCache(Context::getContext()->smarty);
|
||||
}
|
||||
|
||||
protected function _generateConfigXml()
|
||||
@@ -1138,7 +1153,7 @@ abstract class ModuleCore
|
||||
<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>' : '').'
|
||||
</module>';
|
||||
if (is_writable(_PS_MODULE_DIR_.$this->name.'/'))
|
||||
file_put_contents(_PS_MODULE_DIR_.$this->name.'/config.xml', utf8_encode($xml));
|
||||
file_put_contents(_PS_MODULE_DIR_.$this->name.'/config.xml', $xml);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+12
-7
@@ -47,7 +47,7 @@ class MySQLCore extends Db
|
||||
|
||||
return $this->_link;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see DbCore::disconnect()
|
||||
*/
|
||||
@@ -137,11 +137,19 @@ class MySQLCore extends Db
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DbCore::tryToConnect()
|
||||
* tryToConnect return 0 if the connection succeed and the database can be selected.
|
||||
* @since 1.4.4.0, the parameter $newDbLink (default true) has been added.
|
||||
*
|
||||
* @param string $server mysql server name
|
||||
* @param string $user mysql user
|
||||
* @param string $pwd mysql user password
|
||||
* @param string $db mysql database name
|
||||
* @param boolean $newDbLink if set to true, the function will not create a new link if one already exists.
|
||||
* @return integer
|
||||
*/
|
||||
static public function tryToConnect($server, $user, $pwd, $db)
|
||||
public static function tryToConnect($server, $user, $pwd, $db, $newDbLink = true)
|
||||
{
|
||||
if (!$link = @mysql_connect($server, $user, $pwd))
|
||||
if (!$link = @mysql_connect($server, $user, $pwd, $newDbLink))
|
||||
return 1;
|
||||
if (!@mysql_select_db($db, $link))
|
||||
return 2;
|
||||
@@ -149,9 +157,6 @@ class MySQLCore extends Db
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DbCore::tryUTF8()
|
||||
*/
|
||||
static public function tryUTF8($server, $user, $pwd)
|
||||
{
|
||||
$link = @mysql_connect($server, $user, $pwd);
|
||||
|
||||
@@ -86,7 +86,7 @@ abstract class ObjectModelCore
|
||||
* @param string $className Child class name for static use (optional)
|
||||
* @return array Validation rules (fields validity)
|
||||
*/
|
||||
static public function getValidationRules($className = __CLASS__)
|
||||
public static function getValidationRules($className = __CLASS__)
|
||||
{
|
||||
$object = new $className();
|
||||
return array(
|
||||
@@ -231,7 +231,7 @@ abstract class ObjectModelCore
|
||||
if ($fields AND is_array($fields))
|
||||
foreach ($fields AS &$field)
|
||||
{
|
||||
foreach ($field AS $key => $value)
|
||||
foreach (array_keys($field) AS $key)
|
||||
if (!Validate::isTableOrIdentifier($key))
|
||||
die(Tools::displayError());
|
||||
$field[$this->identifier] = (int)$this->id;
|
||||
@@ -291,7 +291,7 @@ abstract class ObjectModelCore
|
||||
{
|
||||
foreach ($fields as $field)
|
||||
{
|
||||
foreach ($field as $key => $value)
|
||||
foreach (array_keys($field) as $key)
|
||||
if (!Validate::isTableOrIdentifier($key))
|
||||
die(Tools::displayError());
|
||||
|
||||
@@ -408,7 +408,7 @@ abstract class ObjectModelCore
|
||||
$fields = array();
|
||||
|
||||
if($this->id_lang == NULL)
|
||||
foreach (Language::getLanguages() as $language)
|
||||
foreach (Language::getLanguages(false) as $language)
|
||||
$this->makeTranslationFields($fields, $fieldsArray, $language['id_lang']);
|
||||
else
|
||||
$this->makeTranslationFields($fields, $fieldsArray, $this->id_lang);
|
||||
|
||||
+43
-28
@@ -165,8 +165,8 @@ class OrderCore extends ObjectModel
|
||||
'id_carrier' => array('xlink_resource'=> 'carriers'),
|
||||
'module' => array('required' => true),
|
||||
'invoice_number' => array(),
|
||||
'delivery_number' => array(),
|
||||
'invoice_date' => array(),
|
||||
'delivery_number' => array(),
|
||||
'delivery_date' => array(),
|
||||
'valid' => array(),
|
||||
'current_state' => array('getter' => 'getCurrentState', 'setter' => 'setCurrentState', 'xlink_resource'=> 'order_states'),
|
||||
@@ -254,7 +254,7 @@ class OrderCore extends ObjectModel
|
||||
/* Does NOT delete a product but "cancel" it (which means return/refund/delete it depending of the case) */
|
||||
public function deleteProduct($order, $orderDetail, $quantity)
|
||||
{
|
||||
if (!$currentStatus = (int)($this->getCurrentState()))
|
||||
if (!(int)($this->getCurrentState()))
|
||||
return false;
|
||||
|
||||
if ($this->hasBeenDelivered())
|
||||
@@ -293,7 +293,14 @@ class OrderCore extends ObjectModel
|
||||
/* Update order */
|
||||
$shippingDiff = $this->total_shipping - $cart->getOrderShippingCost();
|
||||
$this->total_products -= $productPriceWithoutTax;
|
||||
|
||||
// After upgrading from old version
|
||||
// total_products_wt is null
|
||||
// removing a product made order total negative
|
||||
// and don't recalculating totals (on getTotalProductsWithTaxes)
|
||||
if ($this->total_products_wt != 0)
|
||||
$this->total_products_wt -= $productPrice;
|
||||
|
||||
$this->total_shipping = $cart->getOrderShippingCost();
|
||||
|
||||
/* It's temporary fix for 1.3 version... */
|
||||
@@ -331,7 +338,7 @@ class OrderCore extends ObjectModel
|
||||
{
|
||||
$history = new OrderHistory();
|
||||
$history->id_order = (int)($this->id);
|
||||
$history->changeIdOrderState(_PS_OS_CANCELED_, (int)($this->id));
|
||||
$history->changeIdOrderState(Configuration::get('PS_OS_CANCELED'), (int)($this->id));
|
||||
if (!$history->addWithemail())
|
||||
return false;
|
||||
}
|
||||
@@ -342,7 +349,7 @@ class OrderCore extends ObjectModel
|
||||
|
||||
public function deleteCustomization($id_customization, $quantity, $orderDetail)
|
||||
{
|
||||
if (!$currentStatus = (int)($this->getCurrentState()))
|
||||
if (!(int)($this->getCurrentState()))
|
||||
return false;
|
||||
|
||||
if ($this->hasBeenDelivered())
|
||||
@@ -456,7 +463,7 @@ class OrderCore extends ObjectModel
|
||||
if (!$products)
|
||||
$products = $this->getProductsDetail();
|
||||
$resultArray = array();
|
||||
foreach ($products AS $k => $row)
|
||||
foreach ($products AS $row)
|
||||
{
|
||||
// Change qty if selected
|
||||
if ($selectedQty)
|
||||
@@ -539,7 +546,7 @@ class OrderCore extends ObjectModel
|
||||
WHERE od.`id_order` = '.(int)($this->id));
|
||||
}
|
||||
|
||||
static public function getDiscountsCustomer($id_customer, $id_discount)
|
||||
public static function getDiscountsCustomer($id_customer, $id_discount)
|
||||
{
|
||||
return Db::getInstance()->getValue('
|
||||
SELECT COUNT(*) FROM `'._DB_PREFIX_.'orders` o
|
||||
@@ -579,22 +586,22 @@ class OrderCore extends ObjectModel
|
||||
|
||||
public function hasBeenDelivered()
|
||||
{
|
||||
return sizeof($this->getHistory((int)($this->id_lang), _PS_OS_DELIVERED_));
|
||||
return sizeof($this->getHistory((int)($this->id_lang), Configuration::get('PS_OS_DELIVERED')));
|
||||
}
|
||||
|
||||
public function hasBeenPaid()
|
||||
{
|
||||
return sizeof($this->getHistory((int)($this->id_lang), _PS_OS_PAYMENT_));
|
||||
return sizeof($this->getHistory((int)($this->id_lang), Configuration::get('PS_OS_PAYMENT')));
|
||||
}
|
||||
|
||||
public function hasBeenShipped()
|
||||
{
|
||||
return sizeof($this->getHistory((int)($this->id_lang), _PS_OS_SHIPPING_));
|
||||
return sizeof($this->getHistory((int)($this->id_lang), Configuration::get('PS_OS_SHIPPING')));
|
||||
}
|
||||
|
||||
public function isInPreparation()
|
||||
{
|
||||
return sizeof($this->getHistory((int)($this->id_lang), _PS_OS_PREPARATION_));
|
||||
return sizeof($this->getHistory((int)($this->id_lang), Configuration::get('PS_OS_PREPARATION')));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -634,7 +641,7 @@ class OrderCore extends ObjectModel
|
||||
return $res;
|
||||
}
|
||||
|
||||
static public function getOrdersIdByDate($date_from, $date_to, $id_customer = NULL, $type = NULL)
|
||||
public static function getOrdersIdByDate($date_from, $date_to, $id_customer = NULL, $type = NULL)
|
||||
{
|
||||
$sql = 'SELECT `id_order`
|
||||
FROM `'._DB_PREFIX_.'orders`
|
||||
@@ -673,7 +680,7 @@ class OrderCore extends ObjectModel
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql);
|
||||
}
|
||||
|
||||
static public function getOrdersIdInvoiceByDate($date_from, $date_to, $id_customer = NULL, $type = NULL)
|
||||
public static function getOrdersIdInvoiceByDate($date_from, $date_to, $id_customer = NULL, $type = NULL)
|
||||
{
|
||||
$sql = 'SELECT `id_order`
|
||||
FROM `'._DB_PREFIX_.'orders`
|
||||
@@ -690,7 +697,7 @@ class OrderCore extends ObjectModel
|
||||
return $orders;
|
||||
}
|
||||
|
||||
static public function getOrderIdsByStatus($id_order_state)
|
||||
public static function getOrderIdsByStatus($id_order_state)
|
||||
{
|
||||
$sql = 'SELECT id_order
|
||||
FROM '._DB_PREFIX_.'orders o
|
||||
@@ -735,7 +742,7 @@ class OrderCore extends ObjectModel
|
||||
$products = $this->getProductsDetail();
|
||||
|
||||
$return = 0;
|
||||
foreach ($products AS $k => $row)
|
||||
foreach ($products AS $row)
|
||||
{
|
||||
$price = Tools::ps_round($row['product_price'] * (1 + $row['tax_rate'] / 100), 2);
|
||||
if ($row['reduction_percent'])
|
||||
@@ -761,7 +768,7 @@ class OrderCore extends ObjectModel
|
||||
* @param integer $id_customer Customer id
|
||||
* @return array Customer orders number
|
||||
*/
|
||||
static public function getCustomerNbOrders($id_customer)
|
||||
public static function getCustomerNbOrders($id_customer)
|
||||
{
|
||||
$sql = 'SELECT COUNT(`id_order`) AS nb
|
||||
FROM `'._DB_PREFIX_.'orders`
|
||||
@@ -778,7 +785,7 @@ class OrderCore extends ObjectModel
|
||||
* @param integer $id_cart Cart id
|
||||
* @return array Order details
|
||||
*/
|
||||
static public function getOrderByCartId($id_cart)
|
||||
public static function getOrderByCartId($id_cart)
|
||||
{
|
||||
$sql = 'SELECT `id_order`
|
||||
FROM `'._DB_PREFIX_.'orders`
|
||||
@@ -818,12 +825,12 @@ class OrderCore extends ObjectModel
|
||||
|
||||
public function isReturnable()
|
||||
{
|
||||
$payment = $this->getHistory((int)($this->id_lang), _PS_OS_PAYMENT_);
|
||||
$delivred = $this->getHistory((int)($this->id_lang), _PS_OS_DELIVERED_);
|
||||
$payment = $this->getHistory((int)($this->id_lang), Configuration::get('PS_OS_PAYMENT'));
|
||||
$delivred = $this->getHistory((int)($this->id_lang), Configuration::get('PS_OS_DELIVERED'));
|
||||
if ($payment AND $delivred AND strtotime($delivred[0]['date_add']) < strtotime($payment[0]['date_add']))
|
||||
return ((int)(Configuration::get('PS_ORDER_RETURN')) == 1 AND $this->getNumberOfDays());
|
||||
else
|
||||
return ((int)(Configuration::get('PS_ORDER_RETURN')) == 1 AND (int)($this->getCurrentState()) == _PS_OS_DELIVERED_ AND $this->getNumberOfDays());
|
||||
return ((int)(Configuration::get('PS_ORDER_RETURN')) == 1 AND (int)($this->getCurrentState()) == Configuration::get('PS_OS_DELIVERED') AND $this->getNumberOfDays());
|
||||
}
|
||||
|
||||
|
||||
@@ -837,19 +844,20 @@ class OrderCore extends ObjectModel
|
||||
public function setInvoice()
|
||||
{
|
||||
$number = (int)Configuration::get('PS_INVOICE_START_NUMBER');
|
||||
|
||||
if ($number)
|
||||
Configuration::updateValue('PS_INVOICE_START_NUMBER', false);
|
||||
else
|
||||
$number = Order::getLastInvoiceNumber() + 1;
|
||||
|
||||
$number = '(SELECT `invoice_number`
|
||||
FROM (
|
||||
SELECT MAX(`invoice_number`) + 1 AS `invoice_number`
|
||||
FROM `'._DB_PREFIX_.'orders`)
|
||||
tmp )';
|
||||
// a way to avoid duplicate invoice number
|
||||
Db::getInstance()->Execute('
|
||||
UPDATE `'._DB_PREFIX_.'orders`
|
||||
SET `invoice_number` = '.$number.', `invoice_date` = \''.date('Y-m-d H:i:s').'\'
|
||||
WHERE `id_order` = '.(int)$this->id
|
||||
);
|
||||
|
||||
$res = Db::getInstance()->getRow('
|
||||
SELECT `invoice_number`, `invoice_date`
|
||||
FROM `'._DB_PREFIX_.'orders`
|
||||
@@ -876,7 +884,7 @@ class OrderCore extends ObjectModel
|
||||
$this->update();
|
||||
}
|
||||
|
||||
static public function printPDFIcons($id_order, $tr)
|
||||
public static function printPDFIcons($id_order, $tr)
|
||||
{
|
||||
$order = new Order($id_order);
|
||||
$orderState = OrderHistory::getLastOrderState($id_order);
|
||||
@@ -896,7 +904,7 @@ class OrderCore extends ObjectModel
|
||||
echo '</span>';
|
||||
}
|
||||
|
||||
static public function getByDelivery($id_delivery)
|
||||
public static function getByDelivery($id_delivery)
|
||||
{
|
||||
$sql = 'SELECT id_order
|
||||
FROM `'._DB_PREFIX_.'orders`
|
||||
@@ -916,7 +924,7 @@ class OrderCore extends ObjectModel
|
||||
return (float)($result['weight']);
|
||||
}
|
||||
|
||||
static public function getInvoice($id_invoice)
|
||||
public static function getInvoice($id_invoice)
|
||||
{
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
||||
SELECT `invoice_number`, `id_order`
|
||||
@@ -943,7 +951,7 @@ class OrderCore extends ObjectModel
|
||||
* @param int $id_customer optionnal
|
||||
* @return int id_cart
|
||||
*/
|
||||
static public function getCartIdStatic($id_order, $id_customer = 0)
|
||||
public static function getCartIdStatic($id_order, $id_customer = 0)
|
||||
{
|
||||
return (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
||||
SELECT `id_cart`
|
||||
@@ -968,6 +976,13 @@ class OrderCore extends ObjectModel
|
||||
$history = new OrderHistory();
|
||||
$history->id_order = (int)($this->id);
|
||||
$history->changeIdOrderState((int)$id_order_state, (int)($this->id));
|
||||
$res = Db::getInstance()->getRow('SELECT `invoice_number`, `invoice_date`, `delivery_number`, `delivery_date`
|
||||
FROM `'._DB_PREFIX_.'orders`
|
||||
WHERE `id_order` = '.(int)$this->id);
|
||||
$this->invoice_date = $res['invoice_date'];
|
||||
$this->invoice_number = $res['invoice_number'];
|
||||
$this->delivery_date = $res['delivery_date'];
|
||||
$this->delivery_number = $res['delivery_number'];
|
||||
$history->addWithemail();
|
||||
}
|
||||
|
||||
@@ -975,7 +990,7 @@ class OrderCore extends ObjectModel
|
||||
{
|
||||
$paymentModule = Module::getInstanceByName($this->module);
|
||||
$customer = new Customer($this->id_customer);
|
||||
$paymentModule->validateOrder($this->id_cart, _PS_OS_WS_PAYEMENT_, $this->total_paid, $this->payment, NULL, array(), null, false, $customer->secure_key);
|
||||
$paymentModule->validateOrder($this->id_cart, Configuration::get('PS_OS_WS_PAYMENT'), $this->total_paid, $this->payment, NULL, array(), null, false, $customer->secure_key);
|
||||
$this->id = $paymentModule->currentOrder;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -193,7 +193,7 @@ class OrderDetailCore extends ObjectModel
|
||||
return $fields;
|
||||
}
|
||||
|
||||
static public function getDownloadFromHash($hash)
|
||||
public static function getDownloadFromHash($hash)
|
||||
{
|
||||
if ($hash == '') return false;
|
||||
$sql = 'SELECT *
|
||||
@@ -204,7 +204,7 @@ class OrderDetailCore extends ObjectModel
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
|
||||
}
|
||||
|
||||
static public function incrementDownload($id_order_detail, $increment=1)
|
||||
public static function incrementDownload($id_order_detail, $increment=1)
|
||||
{
|
||||
$sql = 'UPDATE `'._DB_PREFIX_.'order_detail`
|
||||
SET `download_nb` = `download_nb` + '.(int)($increment).'
|
||||
|
||||
@@ -91,7 +91,7 @@ class OrderHistoryCore extends ObjectModel
|
||||
/* If becoming unlogable => removing sale */
|
||||
elseif (!$newOS->logable AND ($oldOrderStatus AND $oldOrderStatus->logable))
|
||||
ProductSale::removeProductSale($product['id_product'], $product['cart_quantity']);
|
||||
if (!$isValidated AND $newOS->logable AND isset($oldOrderStatus) AND $oldOrderStatus AND $oldOrderStatus->id == _PS_OS_ERROR_)
|
||||
if (!$isValidated AND $newOS->logable AND isset($oldOrderStatus) AND $oldOrderStatus AND $oldOrderStatus->id == Configuration::get('PS_OS_ERROR'))
|
||||
{
|
||||
Product::updateQuantity($product);
|
||||
}
|
||||
@@ -115,7 +115,7 @@ class OrderHistoryCore extends ObjectModel
|
||||
}
|
||||
}
|
||||
|
||||
static public function getLastOrderState($id_order)
|
||||
public static function getLastOrderState($id_order)
|
||||
{
|
||||
$id_order_state = Db::getInstance()->getValue('
|
||||
SELECT `id_order_state`
|
||||
@@ -180,12 +180,11 @@ class OrderHistoryCore extends ObjectModel
|
||||
$links = $context->smarty->fetch(_PS_MAIL_DIR_.$iso.'/download-product.tpl');
|
||||
$tmpArray = array('{nbProducts}' => count($virtualProducts), '{virtualProducts}' => $links);
|
||||
$data = array_merge ($data, $tmpArray);
|
||||
global $_LANGMAIL;
|
||||
Mail::Send((int)($order->id_lang), 'download_product', Mail::l('Virtual product to download'), $data, $result['email'], $result['firstname'].' '.$result['lastname']);
|
||||
Mail::Send((int)$order->id_lang, 'download_product', Mail::l('Virtual product to download', $order->id_lang), $data, $result['email'], $result['firstname'].' '.$result['lastname']);
|
||||
}
|
||||
|
||||
if (Validate::isLoadedObject($order))
|
||||
Mail::Send((int)($order->id_lang), $result['template'], $topic, $data, $result['email'], $result['firstname'].' '.$result['lastname']);
|
||||
Mail::Send((int)$order->id_lang, $result['template'], $topic, $data, $result['email'], $result['firstname'].' '.$result['lastname']);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -67,7 +67,7 @@ class OrderMessageCore extends ObjectModel
|
||||
return parent::getTranslationsFields(array('name', 'message'));
|
||||
}
|
||||
|
||||
static public function getOrderMessages($id_lang)
|
||||
public static function getOrderMessages($id_lang)
|
||||
{
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
||||
SELECT om.id_order_message, oml.name, oml.message
|
||||
|
||||
@@ -100,7 +100,7 @@ class OrderReturnCore extends ObjectModel
|
||||
}
|
||||
/* Quantity check */
|
||||
if ($orderDetailList)
|
||||
foreach ($orderDetailList AS $key => $orderDetail)
|
||||
foreach (array_keys($orderDetailList) AS $key)
|
||||
if ($qty = (int)($productQtyList[$key]))
|
||||
if ($products[$key]['product_quantity'] - $qty < 0)
|
||||
return false;
|
||||
@@ -108,7 +108,7 @@ class OrderReturnCore extends ObjectModel
|
||||
if ($customizationIds)
|
||||
{
|
||||
$orderedCustomizations = Customization::getOrderedCustomizations((int)($order->id_cart));
|
||||
foreach ($customizationIds AS $productId => $customizations)
|
||||
foreach ($customizationIds AS $customizations)
|
||||
foreach ($customizations AS $customizationId)
|
||||
{
|
||||
$customizationId = (int)($customizationId);
|
||||
@@ -131,7 +131,7 @@ class OrderReturnCore extends ObjectModel
|
||||
return false;
|
||||
return (int)($data['total']);
|
||||
}
|
||||
|
||||
|
||||
static public function getOrdersReturn($customer_id, $order_id = false, $no_denied = false, Context $context = null)
|
||||
{
|
||||
if (!$context)
|
||||
@@ -151,7 +151,7 @@ class OrderReturnCore extends ObjectModel
|
||||
return $data;
|
||||
}
|
||||
|
||||
static public function getOrdersReturnDetail($id_order_return)
|
||||
public static function getOrdersReturnDetail($id_order_return)
|
||||
{
|
||||
return Db::getInstance()->ExecuteS('
|
||||
SELECT *
|
||||
@@ -159,7 +159,7 @@ class OrderReturnCore extends ObjectModel
|
||||
WHERE `id_order_return` = '.(int)($id_order_return));
|
||||
}
|
||||
|
||||
static public function getOrdersReturnProducts($orderReturnId, $order)
|
||||
public static function getOrdersReturnProducts($orderReturnId, $order)
|
||||
{
|
||||
$productsRet = self::getOrdersReturnDetail($orderReturnId);
|
||||
$products = $order->getProducts();
|
||||
@@ -180,7 +180,7 @@ class OrderReturnCore extends ObjectModel
|
||||
return $resTab;
|
||||
}
|
||||
|
||||
static public function getReturnedCustomizedProducts($id_order)
|
||||
public static function getReturnedCustomizedProducts($id_order)
|
||||
{
|
||||
$returns = Customization::getReturnedCustomizations($id_order);
|
||||
$order = new Order((int)($id_order));
|
||||
@@ -197,7 +197,7 @@ class OrderReturnCore extends ObjectModel
|
||||
return $returns;
|
||||
}
|
||||
|
||||
static public function deleteOrderReturnDetail($id_order_return, $id_order_detail, $id_customization = 0)
|
||||
public static function deleteOrderReturnDetail($id_order_return, $id_order_detail, $id_customization = 0)
|
||||
{
|
||||
return Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'order_return_detail` WHERE `id_order_detail` = '.(int)($id_order_detail).' AND `id_order_return` = '.(int)($id_order_return).' AND `id_customization` = '.(int)($id_customization));
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ class OrderReturnStateCore extends ObjectModel
|
||||
* @param integer $id_lang Language id for state name
|
||||
* @return array Order states
|
||||
*/
|
||||
static public function getOrderReturnStates($id_lang)
|
||||
public static function getOrderReturnStates($id_lang)
|
||||
{
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
||||
SELECT *
|
||||
|
||||
@@ -78,7 +78,7 @@ class OrderSlipCore extends ObjectModel
|
||||
}
|
||||
}
|
||||
|
||||
static public function getOrdersSlip($customer_id, $order_id = false)
|
||||
public static function getOrdersSlip($customer_id, $order_id = false)
|
||||
{
|
||||
return Db::getInstance()->ExecuteS('
|
||||
SELECT *
|
||||
@@ -88,7 +88,7 @@ class OrderSlipCore extends ObjectModel
|
||||
ORDER BY `date_add` DESC');
|
||||
}
|
||||
|
||||
static public function getOrdersSlipDetail($id_order_slip = true, $id_order_detail = false)
|
||||
public static function getOrdersSlipDetail($id_order_slip = true, $id_order_detail = false)
|
||||
{
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(
|
||||
($id_order_detail ? 'SELECT SUM(`product_quantity`) AS `total`' : 'SELECT *').
|
||||
@@ -97,7 +97,7 @@ class OrderSlipCore extends ObjectModel
|
||||
.($id_order_detail ? ' WHERE `id_order_detail` = '.(int)($id_order_detail) : ''));
|
||||
}
|
||||
|
||||
static public function getOrdersSlipProducts($orderSlipId, $order)
|
||||
public static function getOrdersSlipProducts($orderSlipId, $order)
|
||||
{
|
||||
$discounts = $order->getDiscounts(true);
|
||||
$productsRet = self::getOrdersSlipDetail($orderSlipId);
|
||||
@@ -147,7 +147,7 @@ class OrderSlipCore extends ObjectModel
|
||||
return $products;
|
||||
}
|
||||
|
||||
static public function getSlipsIdByDate($dateFrom, $dateTo)
|
||||
public static function getSlipsIdByDate($dateFrom, $dateTo)
|
||||
{
|
||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
||||
SELECT `id_order_slip`
|
||||
@@ -161,7 +161,7 @@ class OrderSlipCore extends ObjectModel
|
||||
return $slips;
|
||||
}
|
||||
|
||||
static public function createOrderSlip($order, $productList, $qtyList, $shipping_cost = false)
|
||||
public static function createOrderSlip($order, $productList, $qtyList, $shipping_cost = false)
|
||||
{
|
||||
$currency = new Currency($order->id_currency);
|
||||
$orderSlip = new OrderSlip();
|
||||
|
||||
@@ -99,7 +99,7 @@ class OrderStateCore extends ObjectModel
|
||||
* @param integer $id_lang Language id for state name
|
||||
* @return array Order states
|
||||
*/
|
||||
static public function getOrderStates($id_lang)
|
||||
public static function getOrderStates($id_lang)
|
||||
{
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
||||
SELECT *
|
||||
@@ -114,7 +114,7 @@ class OrderStateCore extends ObjectModel
|
||||
* @param integer $id_order_state State ID
|
||||
* @return boolean availability
|
||||
*/
|
||||
static public function invoiceAvailable($id_order_state)
|
||||
public static function invoiceAvailable($id_order_state)
|
||||
{
|
||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
||||
SELECT `invoice` AS ok
|
||||
|
||||
+22
-9
@@ -191,7 +191,7 @@ class PDFCore extends PDF_PageGroupCore
|
||||
$footerText;
|
||||
|
||||
// If the country is USA
|
||||
if ($conf['PS_SHOP_COUNTRY_ID'] == 21)
|
||||
if (Country::getIsoById(Configuration::get('PS_COUNTRY_DEFAULT')) == 'US')
|
||||
{
|
||||
$completeAddressShop = $this->_getCompleteUSAddressFormat($conf);
|
||||
|
||||
@@ -431,7 +431,7 @@ class PDFCore extends PDF_PageGroupCore
|
||||
{
|
||||
$maxY = 0;
|
||||
$pdf->setY($pdf->GetY() + 5);
|
||||
foreach($addressType as $type => $idNameAttribute)
|
||||
foreach(array_keys($addressType) as $type)
|
||||
{
|
||||
$currentY = $pdf->GetY();
|
||||
|
||||
@@ -449,9 +449,17 @@ class PDFCore extends PDF_PageGroupCore
|
||||
$tmp = '';
|
||||
foreach($patternsList as $pattern)
|
||||
if (!in_array($pattern, $patternRules['avoid']))
|
||||
{
|
||||
if ($pattern == 'State:name' &&
|
||||
Country::getIsoById(Configuration::get('PS_COUNTRY_DEFAULT')) == 'US')
|
||||
{
|
||||
$state = &$addressType[$type]['addressFormatedValues'][$pattern];
|
||||
$state = strtoupper(substr($state, 0, 2));
|
||||
}
|
||||
$tmp .= ((isset($addressType[$type]['addressFormatedValues'][$pattern]) &&
|
||||
!empty($addressType[$type]['addressFormatedValues'][$pattern])) ?
|
||||
(Tools::iconv('utf-8', self::encoding(), $addressType[$type]['addressFormatedValues'][$pattern]).' ') : '');
|
||||
}
|
||||
$tmp = trim($tmp);
|
||||
$addressType[$type]['displayed'] .= (!empty($tmp)) ? $tmp."\n" : '';
|
||||
}
|
||||
@@ -547,7 +555,7 @@ class PDFCore extends PDF_PageGroupCore
|
||||
$carrier->name = Configuration::get('PS_SHOP_NAME');
|
||||
$history = self::$order->getHistory(self::$order->id_lang);
|
||||
foreach($history as $h)
|
||||
if ($h['id_order_state'] == _PS_OS_SHIPPING_)
|
||||
if ($h['id_order_state'] == Configuration::get('PS_OS_SHIPPING'))
|
||||
$shipping_date = $h['date_add'];
|
||||
$pdf->Ln(12);
|
||||
$pdf->SetFillColor(240, 240, 240);
|
||||
@@ -557,8 +565,11 @@ class PDFCore extends PDF_PageGroupCore
|
||||
$pdf->Cell(0, 6, self::l('SLIP #').' '.sprintf('%06d', self::$orderSlip->id).' '.self::l('from') . ' ' .Tools::displayDate(self::$orderSlip->date_upd, self::$order->id_lang), 1, 2, 'L', 1);
|
||||
elseif (self::$delivery)
|
||||
$pdf->Cell(0, 6, self::l('DELIVERY SLIP #').Tools::iconv('utf-8', self::encoding(), Configuration::get('PS_DELIVERY_PREFIX', $context->language->id)).sprintf('%06d', self::$delivery).' '.self::l('from') . ' ' .Tools::displayDate(self::$order->delivery_date, self::$order->id_lang), 1, 2, 'L', 1);
|
||||
elseif ((int)self::$order->invoice_date)
|
||||
$pdf->Cell(0, 6, self::l('INVOICE #').' '.Tools::iconv('utf-8', self::encoding(), Configuration::get('PS_INVOICE_PREFIX', (int)($cookie->id_lang))).sprintf('%06d', self::$order->invoice_number).' '.self::l('from') . ' ' .Tools::displayDate(self::$order->invoice_date, self::$order->id_lang), 1, 2, 'L', 1);
|
||||
else
|
||||
$pdf->Cell(0, 6, self::l('INVOICE #').' '.Tools::iconv('utf-8', self::encoding(), Configuration::get('PS_INVOICE_PREFIX', $context->language->id)).sprintf('%06d', self::$order->invoice_number).' '.self::l('from') . ' ' .Tools::displayDate(self::$order->invoice_date, self::$order->id_lang), 1, 2, 'L', 1);
|
||||
$pdf->Cell(0, 6, self::l('Invoice draft'), 1, 2, 'L', 1);
|
||||
|
||||
$pdf->Cell(55, 6, self::l('Order #').' '.sprintf('%06d', self::$order->id), 'L', 0);
|
||||
$pdf->Cell(70, 6, self::l('Carrier:').($order->gift ? ' '.Tools::iconv('utf-8', self::encoding(), $carrier->name) : ''), 'L');
|
||||
$pdf->Cell(0, 6, self::l('Payment method:'), 'LR');
|
||||
@@ -894,6 +905,8 @@ class PDFCore extends PDF_PageGroupCore
|
||||
$taxes[$product['tax_rate']] = 0;
|
||||
if (!isset($priceBreakDown['totalsProductsWithTaxAndReduction'][$product['tax_rate']]))
|
||||
$priceBreakDown['totalsProductsWithTaxAndReduction'][$product['tax_rate']] = 0;
|
||||
if (!isset($priceBreakDown['totalsProductsWithoutTaxAndReduction'][$product['tax_rate']]))
|
||||
$priceBreakDown['totalsProductsWithoutTaxAndReduction'][$product['tax_rate']] = 0;
|
||||
|
||||
|
||||
/* Without tax */
|
||||
@@ -927,7 +940,7 @@ class PDFCore extends PDF_PageGroupCore
|
||||
$vat = $priceWithTaxAndReduction - Tools::ps_round($priceWithTaxAndReduction / $product['product_quantity'] / (((float)($product['tax_rate']) / 100) + 1), 2) * $product['product_quantity'];
|
||||
$priceBreakDown['totalsWithoutTax'][$product['tax_rate']] += $product['priceWithoutTax'] ;
|
||||
$priceBreakDown['totalsProductsWithoutTax'][$product['tax_rate']] += $product['priceWithoutTax'];
|
||||
$priceBreakDown['totalsProductsWithoutTaxAndReduction'][$product['tax_rate']] = Tools::ps_round($product['priceWithoutTax'] - (float)$discountAmountWithoutTax, 2);
|
||||
$priceBreakDown['totalsProductsWithoutTaxAndReduction'][$product['tax_rate']] += Tools::ps_round($product['priceWithoutTax'] - (float)$discountAmountWithoutTax, 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1022,7 +1035,7 @@ class PDFCore extends PDF_PageGroupCore
|
||||
$nb_tax = 0;
|
||||
|
||||
// Display product tax
|
||||
foreach ($priceBreakDown['taxes'] AS $tax_rate => $vat)
|
||||
foreach (array_keys($priceBreakDown['taxes']) AS $tax_rate)
|
||||
{
|
||||
if ($tax_rate != '0.00' AND $priceBreakDown['totalsProductsWithTax'][$tax_rate] != '0.00')
|
||||
{
|
||||
@@ -1101,17 +1114,17 @@ class PDFCore extends PDF_PageGroupCore
|
||||
return (Tools::iconv('utf-8', self::encoding(), $str));
|
||||
}
|
||||
|
||||
static public function encoding()
|
||||
public static function encoding()
|
||||
{
|
||||
return (isset(self::$_pdfparams[self::$_iso]) AND is_array(self::$_pdfparams[self::$_iso]) AND self::$_pdfparams[self::$_iso]['encoding']) ? self::$_pdfparams[self::$_iso]['encoding'] : 'iso-8859-1';
|
||||
}
|
||||
|
||||
static public function embedfont()
|
||||
public static function embedfont()
|
||||
{
|
||||
return (((isset(self::$_pdfparams[self::$_iso]) AND is_array(self::$_pdfparams[self::$_iso]) AND self::$_pdfparams[self::$_iso]['font']) AND !in_array(self::$_pdfparams[self::$_iso]['font'], self::$_fpdf_core_fonts)) ? self::$_pdfparams[self::$_iso]['font'] : false);
|
||||
}
|
||||
|
||||
static public function fontname()
|
||||
public static function fontname()
|
||||
{
|
||||
$font = self::embedfont();
|
||||
if (in_array(self::$_pdfparams[self::$_iso]['font'], self::$_fpdf_core_fonts))
|
||||
|
||||
+11
-11
@@ -105,7 +105,7 @@ abstract class PaymentModuleCore extends Module
|
||||
$order->id_customer = (int)($cart->id_customer);
|
||||
$order->id_address_invoice = (int)($cart->id_address_invoice);
|
||||
$order->id_address_delivery = (int)($cart->id_address_delivery);
|
||||
$vat_address = new Address((int)($order->id_address_delivery));
|
||||
$vat_address = new Address((int)($order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}));
|
||||
$order->id_currency = ($currency_special ? (int)($currency_special) : (int)($cart->id_currency));
|
||||
$order->id_lang = (int)($cart->id_lang);
|
||||
$order->id_cart = (int)($cart->id);
|
||||
@@ -139,7 +139,7 @@ abstract class PaymentModuleCore extends Module
|
||||
// if ($order->total_paid != $order->total_paid_real)
|
||||
// We use number_format in order to compare two string
|
||||
if (number_format($order->total_paid, 2) != number_format($order->total_paid_real, 2))
|
||||
$id_order_state = _PS_OS_ERROR_;
|
||||
$id_order_state = Configuration::get('PS_OS_ERROR');
|
||||
// Creating order
|
||||
if ($cart->OrderExists() == false)
|
||||
$result = $order->add();
|
||||
@@ -184,7 +184,7 @@ abstract class PaymentModuleCore extends Module
|
||||
{
|
||||
$productQuantity = (int)(Product::getQuantity((int)($product['id_product']), ($product['id_product_attribute'] ? (int)($product['id_product_attribute']) : NULL)));
|
||||
$quantityInStock = ($productQuantity - (int)($product['cart_quantity']) < 0) ? $productQuantity : (int)($product['cart_quantity']);
|
||||
if ($id_order_state != _PS_OS_CANCELED_ AND $id_order_state != _PS_OS_ERROR_)
|
||||
if ($id_order_state != Configuration::get('PS_OS_CANCELED') AND $id_order_state != Configuration::get('PS_OS_ERROR'))
|
||||
{
|
||||
if (Product::updateQuantity($product, (int)$order->id))
|
||||
$product['stock_quantity'] -= $product['cart_quantity'];
|
||||
@@ -300,9 +300,9 @@ abstract class PaymentModuleCore extends Module
|
||||
if ($objDiscount->id_discount_type == 2 AND in_array($objDiscount->behavior_not_exhausted, array(1,2)))
|
||||
$shrunk = true;
|
||||
|
||||
if ($shrunk AND ($total_discount_value + $value) > ($order->total_products + $order->total_shipping + $order->total_wrapping))
|
||||
if ($shrunk AND ($total_discount_value + $value) > ($order->total_products_wt + $order->total_shipping + $order->total_wrapping))
|
||||
{
|
||||
$amount_to_add = ($order->total_products + $order->total_shipping + $order->total_wrapping) - $total_discount_value;
|
||||
$amount_to_add = ($order->total_products_wt + $order->total_shipping + $order->total_wrapping) - $total_discount_value;
|
||||
if ($objDiscount->id_discount_type == 2 AND $objDiscount->behavior_not_exhausted == 2)
|
||||
{
|
||||
$voucher = new Discount();
|
||||
@@ -320,7 +320,7 @@ abstract class PaymentModuleCore extends Module
|
||||
$amount_to_add = $value;
|
||||
$order->addDiscount($objDiscount->id, $objDiscount->name, $amount_to_add);
|
||||
$total_discount_value += $amount_to_add;
|
||||
if ($id_order_state != _PS_OS_ERROR_ AND $id_order_state != _PS_OS_CANCELED_)
|
||||
if ($id_order_state != Configuration::get('PS_OS_ERROR') AND $id_order_state != Configuration::get('PS_OS_CANCELED'))
|
||||
$objDiscount->quantity = $objDiscount->quantity - 1;
|
||||
$objDiscount->update();
|
||||
|
||||
@@ -354,7 +354,7 @@ abstract class PaymentModuleCore extends Module
|
||||
{
|
||||
$history = new OrderHistory();
|
||||
$history->id_order = (int)$order->id;
|
||||
$history->changeIdOrderState(_PS_OS_OUTOFSTOCK_, (int)$order->id);
|
||||
$history->changeIdOrderState(Configuration::get('PS_OS_OUTOFSTOCK'), (int)$order->id);
|
||||
$history->addWithemail();
|
||||
}
|
||||
|
||||
@@ -369,7 +369,7 @@ abstract class PaymentModuleCore extends Module
|
||||
$order = new Order($order->id);
|
||||
|
||||
// Send an e-mail to customer
|
||||
if ($id_order_state != _PS_OS_ERROR_ AND $id_order_state != _PS_OS_CANCELED_ AND $customer->id)
|
||||
if ($id_order_state != Configuration::get('PS_OS_ERROR') AND $id_order_state != Configuration::get('PS_OS_CANCELED') AND $customer->id)
|
||||
{
|
||||
$invoice = new Address((int)($order->id_address_invoice));
|
||||
$delivery = new Address((int)($order->id_address_delivery));
|
||||
@@ -440,9 +440,9 @@ abstract class PaymentModuleCore extends Module
|
||||
$fileAttachment = NULL;
|
||||
|
||||
if (Validate::isEmail($customer->email))
|
||||
Mail::Send((int)($order->id_lang), 'order_conf', Mail::l('Order confirmation'), $data, $customer->email, $customer->firstname.' '.$customer->lastname, NULL, NULL, $fileAttachment);
|
||||
Mail::Send((int)$order->id_lang, 'order_conf', Mail::l('Order confirmation', $order->id_lang), $data, $customer->email, $customer->firstname.' '.$customer->lastname, NULL, NULL, $fileAttachment);
|
||||
}
|
||||
$this->currentOrder = (int)($order->id);
|
||||
$this->currentOrder = (int)$order->id;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
@@ -467,7 +467,7 @@ abstract class PaymentModuleCore extends Module
|
||||
private function _getTxtFormatedAddress($the_address)
|
||||
{
|
||||
$out = '';
|
||||
$adr_fields = AddressFormat::getOrderedAddressFields($the_address->id_country);
|
||||
$adr_fields = AddressFormat::getOrderedAddressFields($the_address->id_country, false, true);
|
||||
$r_values = array();
|
||||
foreach($adr_fields as $fields_line)
|
||||
{
|
||||
|
||||
+96
-40
@@ -263,7 +263,7 @@ class ProductCore extends ObjectModel
|
||||
'out_of_stock' => array('required' => true),
|
||||
'new' => array(),
|
||||
'cache_default_attribute' => array(),
|
||||
'id_default_image' => array('getter' => 'getCoverWs', 'setter' => false, 'xlink_resource' => array('resourceName' => 'images', 'subResourceName' => 'products')),
|
||||
'id_default_image' => array('getter' => 'getCoverWs', 'setter' => 'setCoverWs', 'xlink_resource' => array('resourceName' => 'images', 'subResourceName' => 'products')),
|
||||
'id_default_combination' => array('getter' => 'getWsDefaultCombination', 'setter' => 'setWsDefaultCombination', 'xlink_resource' => array('resourceName' => 'combinations')),
|
||||
'position_in_category' => array('getter' => 'getWsPositionInCategory', 'setter' => false),
|
||||
'manufacturer_name' => array('getter' => 'getWsManufacturerName', 'setter' => false),
|
||||
@@ -285,6 +285,10 @@ class ProductCore extends ObjectModel
|
||||
'id' => array('required' => true),
|
||||
'id_feature_value' => array('required' => true, 'xlink_resource' => 'product_feature_values'),
|
||||
)),
|
||||
'tags' => array('resource' => 'tag',
|
||||
'fields' => array(
|
||||
'id' => array('required' => true),
|
||||
)),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -486,7 +490,7 @@ class ProductCore extends ObjectModel
|
||||
$sizeof = sizeof($result);
|
||||
|
||||
for ($i = 0; $i < $sizeof; $i++)
|
||||
$return &= Db::getInstance()->Execute($sql='
|
||||
$return &= Db::getInstance()->Execute('
|
||||
UPDATE `'._DB_PREFIX_.'category_product`
|
||||
SET `position` = '.(int)($i).'
|
||||
WHERE `id_category` = '.(int)($id_category).'
|
||||
@@ -507,7 +511,7 @@ class ProductCore extends ObjectModel
|
||||
' WHERE pa.default_on = 1 '
|
||||
.($minimumQuantity > 0 ? ' AND stock.quantity >= '.(int)$minimumQuantity : '').
|
||||
' AND pa.id_product = '.(int)$id_product;
|
||||
$result = Db::getInstance()->getRow($sql);
|
||||
$result = Db::getInstance()->getValue($sql);
|
||||
|
||||
if (!$result)
|
||||
{
|
||||
@@ -516,17 +520,26 @@ class ProductCore extends ObjectModel
|
||||
.($minimumQuantity > 0 ? Product::sqlStock('pa', 'pa') : '').
|
||||
' WHERE pa.id_product = '.(int)$id_product
|
||||
.($minimumQuantity > 0 ? ' AND stock.quantity >= '.(int)$minimumQuantity : '');
|
||||
$result = Db::getInstance()->getRow($sql);
|
||||
$result = Db::getInstance()->getValue($sql);
|
||||
}
|
||||
|
||||
|
||||
if (!$result)
|
||||
{
|
||||
$sql = 'SELECT id_product_attribute
|
||||
FROM '._DB_PREFIX_.'product_attribute
|
||||
WHERE `default_on` = 1
|
||||
AND id_product = '.(int)$id_product;
|
||||
$result = Db::getInstance()->getValue($sql);
|
||||
}
|
||||
|
||||
if (!$result)
|
||||
{
|
||||
$sql = 'SELECT id_product_attribute
|
||||
FROM '._DB_PREFIX_.'product_attribute
|
||||
WHERE id_product = '.(int)$id_product;
|
||||
$result = Db::getInstance()->getRow($sql);
|
||||
$result = Db::getInstance()->getValue($sql);
|
||||
}
|
||||
return $result['id_product_attribute'];
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function updateDefaultAttribute($id_product)
|
||||
@@ -606,7 +619,8 @@ class ProductCore extends ObjectModel
|
||||
$currentCategories = $this->getCategories();
|
||||
|
||||
// for new categ, put product at last position
|
||||
$resCategNewPos = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql='SELECT id_category, MAX(position)+1 newPos
|
||||
$resCategNewPos = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
||||
SELECT id_category, MAX(position)+1 newPos
|
||||
FROM `'._DB_PREFIX_.'category_product`
|
||||
WHERE `id_category` IN('.implode(',', array_map('intval', $categories)).')
|
||||
GROUP BY id_category');
|
||||
@@ -643,7 +657,7 @@ class ProductCore extends ObjectModel
|
||||
{
|
||||
if (empty($categories))
|
||||
return false;
|
||||
$positions = array();
|
||||
|
||||
// get max position in each categories
|
||||
$result = Db::getInstance()->ExecuteS('SELECT `id_category`
|
||||
FROM `'._DB_PREFIX_.'category_product`
|
||||
@@ -1091,18 +1105,9 @@ class ProductCore extends ObjectModel
|
||||
*/
|
||||
public function deleteAttachments()
|
||||
{
|
||||
$attachments = Db::getInstance()->ExecuteS('SELECT id_attachment FROM `'._DB_PREFIX_.'product_attachment` WHERE `id_product` = '.(int)($this->id));
|
||||
$result = true;
|
||||
foreach ($attachments AS $attachment)
|
||||
{
|
||||
$attachmentObj = new Attachment((int)($attachment['id_attachment']));
|
||||
if (Validate::isLoadedObject($attachmentObj))
|
||||
$result &= $attachmentObj->delete();
|
||||
return Db::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'product_attachment WHERE id_product = '.(int)($this->id));
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete product customizations
|
||||
*
|
||||
@@ -1228,26 +1233,26 @@ class ProductCore extends ObjectModel
|
||||
public function deleteFeatures()
|
||||
{
|
||||
// List products features
|
||||
$result1 = Db::getInstance()->ExecuteS('
|
||||
$features = Db::getInstance()->ExecuteS('
|
||||
SELECT p.*, f.*
|
||||
FROM `'._DB_PREFIX_.'feature_product` as p
|
||||
LEFT JOIN `'._DB_PREFIX_.'feature_value` as f ON (f.`id_feature_value` = p.`id_feature_value`)
|
||||
WHERE `id_product` = '.(int)($this->id));
|
||||
foreach ($result1 as $tab)
|
||||
foreach ($features as $tab)
|
||||
// Delete product custom features
|
||||
if ($tab['custom']) {
|
||||
$result2 = Db::getInstance()->Execute('
|
||||
Db::getInstance()->Execute('
|
||||
DELETE FROM `'._DB_PREFIX_.'feature_value`
|
||||
WHERE `id_feature_value` = '.(int)($tab['id_feature_value']));
|
||||
$result3 = Db::getInstance()->Execute('
|
||||
Db::getInstance()->Execute('
|
||||
DELETE FROM `'._DB_PREFIX_.'feature_value_lang`
|
||||
WHERE `id_feature_value` = '.(int)($tab['id_feature_value']));
|
||||
}
|
||||
// Delete product features
|
||||
$result4 = Db::getInstance()->Execute('
|
||||
$result = Db::getInstance()->Execute('
|
||||
DELETE FROM `'._DB_PREFIX_.'feature_product`
|
||||
WHERE `id_product` = '.(int)($this->id));
|
||||
return ($result4);
|
||||
return ($result);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1546,9 +1551,19 @@ class ProductCore extends ObjectModel
|
||||
WHERE `id_product` = '.(int)$id_product)
|
||||
)
|
||||
foreach ($row as $val)
|
||||
{
|
||||
$ret[] = $val['id_category'];
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public static function getProductCategoriesFull($id_product = '', $id_lang)
|
||||
{
|
||||
$ret = array();
|
||||
$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
||||
SELECT cp.`id_category`, cl.`name`, cl.`link_rewrite` FROM `'._DB_PREFIX_.'category_product` cp
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (cp.`id_category` = cl.`id_category`)
|
||||
WHERE cp.`id_product` = '.(int)$id_product);
|
||||
foreach ($row as $val)
|
||||
$ret[$val['id_category']] = $val;
|
||||
return $ret;
|
||||
}
|
||||
|
||||
@@ -1573,7 +1588,7 @@ class ProductCore extends ObjectModel
|
||||
if (!$context)
|
||||
$context = Context::getContext();
|
||||
|
||||
$sql = 'SELECT i.`cover`, i.`id_image`, il.`legend`
|
||||
$sql = 'SELECT i.`cover`, i.`id_image`, il.`legend`, i.`position`
|
||||
FROM `'._DB_PREFIX_.'image` i
|
||||
'.$context->shop->sqlAsso('image', 'i').'
|
||||
LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.')
|
||||
@@ -1611,7 +1626,7 @@ class ProductCore extends ObjectModel
|
||||
* @param boolean $only_reduc Returns only the reduction amount
|
||||
* @param boolean $usereduc Set if the returned amount will include reduction
|
||||
* @param integer $quantity Required for quantity discount application (default value: 1)
|
||||
* @param boolean $forceAssociatedTax Force to apply the associated tax. Only works when the parameter $usetax is true
|
||||
* @param boolean $forceAssociatedTax DEPRECATED - NOT USED Force to apply the associated tax. Only works when the parameter $usetax is true
|
||||
* @param integer $id_customer Customer ID (for customer group reduction)
|
||||
* @param integer $id_cart Cart ID. Required when the cookie is not accessible (e.g., inside a payment module, a cron task...)
|
||||
* @param integer $id_address Customer address ID. Required for price (tax included) calculation regarding the guest localization
|
||||
@@ -1726,8 +1741,6 @@ class ProductCore extends ObjectModel
|
||||
else
|
||||
$product_attribute_label = ($id_product_attribute === false ? 'false' : $id_product_attribute);
|
||||
$cacheId = $id_product.'-'.$id_shop.'-'.$id_currency.'-'.$id_country.'-'.$id_state.'-'.$id_county.'-'.$id_group.'-'.$quantity.'-'.$product_attribute_label.'-'.($use_tax?'1':'0').'-'.$decimals.'-'.($only_reduc?'1':'0').'-'.($use_reduc?'1':'0').'-'.$with_ecotax;
|
||||
// Cache for specific prices
|
||||
$cacheId3 = $id_product.'-'.$id_shop.'-'.$id_currency.'-'.$id_country.'-'.$id_group.'-'.$quantity;
|
||||
|
||||
// reference parameter is filled before any returns
|
||||
$specific_price = SpecificPrice::getSpecificPrice((int)($id_product), $id_shop, $id_currency, $id_country, $id_group, $quantity);
|
||||
@@ -1802,7 +1815,7 @@ class ProductCore extends ObjectModel
|
||||
{
|
||||
$ecotax = $result['ecotax'];
|
||||
if (isset($result['attribute_ecotax']) && $result['attribute_ecotax'] > 0)
|
||||
$ecotax = $result['ecotax'];
|
||||
$ecotax = $result['attribute_ecotax'];
|
||||
|
||||
if ($id_currency)
|
||||
$ecotax = Tools::convertPrice($ecotax, $id_currency);
|
||||
@@ -1911,6 +1924,13 @@ class ProductCore extends ObjectModel
|
||||
return Tools::displayPrice($params['price'], $smarty->ps_currency);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert price with currency
|
||||
*
|
||||
* @param array $params
|
||||
* @param object $smarty DEPRECATED
|
||||
* @return Ambigous <string, mixed, Ambigous <number, string>>
|
||||
*/
|
||||
static function convertPriceWithCurrency($params, &$smarty)
|
||||
{
|
||||
if (!isset($params['convert']))
|
||||
@@ -1923,6 +1943,13 @@ class ProductCore extends ObjectModel
|
||||
return Tools::displayPrice($params['p'], $smarty->ps_currency);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display WT price with currency
|
||||
*
|
||||
* @param array $params
|
||||
* @param object DEPRECATED $smarty
|
||||
* @return Ambigous <string, mixed, Ambigous <number, string>>
|
||||
*/
|
||||
static function displayWtPriceWithCurrency($params, &$smarty)
|
||||
{
|
||||
return Tools::displayPrice($params['price'], $params['currency'], false);
|
||||
@@ -2426,7 +2453,7 @@ class ProductCore extends ObjectModel
|
||||
return false;
|
||||
|
||||
$resultsArray = array();
|
||||
foreach ($result AS $k => $row)
|
||||
foreach ($result AS $row)
|
||||
{
|
||||
$row['price'] = Product::getPriceStatic($row['id_product'], true, NULL, 2);
|
||||
$row['quantity'] = Product::getQuantity($row['id_product'], NULL, $row['cache_is_pack']);
|
||||
@@ -3040,22 +3067,19 @@ class ProductCore extends ObjectModel
|
||||
{
|
||||
if (!$id_customer)
|
||||
{
|
||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
||||
return (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
||||
SELECT ctg.`id_group`
|
||||
FROM `'._DB_PREFIX_.'category_product` cp
|
||||
INNER JOIN `'._DB_PREFIX_.'category_group` ctg ON (ctg.`id_category` = cp.`id_category`)
|
||||
WHERE cp.`id_product` = '.(int)($this->id).' AND ctg.`id_group` = 1');
|
||||
WHERE cp.`id_product` = '.(int)$this->id.' AND ctg.`id_group` = 1');
|
||||
} else {
|
||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
||||
return (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
||||
SELECT cg.`id_group`
|
||||
FROM `'._DB_PREFIX_.'category_product` cp
|
||||
INNER JOIN `'._DB_PREFIX_.'category_group` ctg ON (ctg.`id_category` = cp.`id_category`)
|
||||
INNER JOIN `'._DB_PREFIX_.'customer_group` cg ON (cg.`id_group` = ctg.`id_group`)
|
||||
WHERE cp.`id_product` = '.(int)($this->id).' AND cg.`id_customer` = '.(int)($id_customer));
|
||||
WHERE cp.`id_product` = '.(int)$this->id.' AND cg.`id_customer` = '.(int)$id_customer);
|
||||
}
|
||||
if ($result AND isset($result['id_group']) AND $result['id_group'])
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3282,7 +3306,7 @@ class ProductCore extends ObjectModel
|
||||
|
||||
// Delete rows
|
||||
if (count($toDelete) > 0)
|
||||
$result = Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'product_attribute` WHERE `id_product_attribute` IN ('.implode(',', $toDelete).')');
|
||||
Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'product_attribute` WHERE `id_product_attribute` IN ('.implode(',', $toDelete).')');
|
||||
|
||||
foreach ($toAdd as $id)
|
||||
{
|
||||
@@ -3336,6 +3360,21 @@ class ProductCore extends ObjectModel
|
||||
return $result['id_image'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Webservice setter : set virtual field id_default_image in category
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function setCoverWs($id_image)
|
||||
{
|
||||
Db::getInstance()->ExecuteS('UPDATE `'._DB_PREFIX_.'image`
|
||||
SET `cover` = 0 WHERE `id_product` = '.(int)($this->id).'
|
||||
');
|
||||
Db::getInstance()->ExecuteS('UPDATE `'._DB_PREFIX_.'image`
|
||||
SET `cover` = 1 WHERE `id_product` = '.(int)($this->id).' AND `id_image` = '.(int)$id_image);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Webservice getter : get image ids of current product for association
|
||||
*
|
||||
@@ -3350,8 +3389,25 @@ class ProductCore extends ObjectModel
|
||||
ORDER BY `position`');
|
||||
}
|
||||
|
||||
public function getWsTags()
|
||||
{
|
||||
return Db::getInstance()->ExecuteS('
|
||||
SELECT `id_tag` as id
|
||||
FROM `'._DB_PREFIX_.'product_tag`
|
||||
WHERE `id_product` = '.(int)($this->id));
|
||||
}
|
||||
|
||||
|
||||
public function getWsManufacturerName()
|
||||
{
|
||||
return Manufacturer::getNameById((int)$this->id_manufacturer);
|
||||
}
|
||||
|
||||
public static function resetEcoTax()
|
||||
{
|
||||
Db::getInstance()->Execute('
|
||||
UPDATE `'._DB_PREFIX_.'product`
|
||||
SET ecotax = 0
|
||||
');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ class ProductDownloadCore extends ObjectModel
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
static public function checkWritableDir()
|
||||
public static function checkWritableDir()
|
||||
{
|
||||
return is_writable(_PS_DOWNLOAD_DIR_);
|
||||
}
|
||||
@@ -157,12 +157,10 @@ class ProductDownloadCore extends ObjectModel
|
||||
if (array_key_exists($id_product, self::$_productIds))
|
||||
return self::$_productIds[$id_product];
|
||||
|
||||
$data = Db::getInstance()->getRow('
|
||||
self::$_productIds[$id_product] = (int)Db::getInstance()->getValue('
|
||||
SELECT `id_product_download`
|
||||
FROM `'._DB_PREFIX_.'product_download`
|
||||
WHERE `id_product` = '.(int)($id_product).' AND `active` = 1');
|
||||
|
||||
self::$_productIds[$id_product] = isset($data['id_product_download']) ? (int)($data['id_product_download']) : false;
|
||||
WHERE `id_product` = '.(int)$id_product.' AND `active` = 1');
|
||||
|
||||
return self::$_productIds[$id_product];
|
||||
}
|
||||
@@ -175,12 +173,11 @@ class ProductDownloadCore extends ObjectModel
|
||||
*/
|
||||
public static function getFilenameFromIdProduct($id_product)
|
||||
{
|
||||
$data = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
||||
SELECT `physically_filename`
|
||||
FROM `'._DB_PREFIX_.'product_download`
|
||||
WHERE `id_product` = '.(int)($id_product).'
|
||||
WHERE `id_product` = '.(int)$id_product.'
|
||||
AND `active` = 1');
|
||||
return $data['physically_filename'];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -259,7 +256,7 @@ class ProductDownloadCore extends ObjectModel
|
||||
*
|
||||
* @return string Sha1 unique filename
|
||||
*/
|
||||
static public function getNewFilename()
|
||||
public static function getNewFilename()
|
||||
{
|
||||
$ret = sha1(microtime());
|
||||
if (file_exists(_PS_DOWNLOAD_DIR_.$ret))
|
||||
|
||||
@@ -31,7 +31,7 @@ class ProductSaleCore
|
||||
** Fill the `product_sale` SQL table with data from `order_detail`
|
||||
** @return bool True on success
|
||||
*/
|
||||
static public function fillProductSales()
|
||||
public static function fillProductSales()
|
||||
{
|
||||
return Db::getInstance()->Execute('
|
||||
REPLACE INTO '._DB_PREFIX_.'product_sale
|
||||
@@ -148,7 +148,7 @@ class ProductSaleCore
|
||||
ORDER BY sales DESC
|
||||
LIMIT '.(int)($pageNumber * $nbProducts).', '.(int)$nbProducts;
|
||||
if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql))
|
||||
return $result;
|
||||
return false;
|
||||
|
||||
foreach ($result AS &$row)
|
||||
{
|
||||
@@ -158,7 +158,7 @@ class ProductSaleCore
|
||||
return $result;
|
||||
}
|
||||
|
||||
static public function addProductSale($product_id, $qty = 1)
|
||||
public static function addProductSale($product_id, $qty = 1)
|
||||
{
|
||||
return Db::getInstance()->Execute('
|
||||
INSERT INTO '._DB_PREFIX_.'product_sale
|
||||
@@ -167,7 +167,7 @@ class ProductSaleCore
|
||||
ON DUPLICATE KEY UPDATE `quantity` = `quantity` + '.(int)($qty).', `sale_nbr` = `sale_nbr` + 1, `date_upd` = NOW()');
|
||||
}
|
||||
|
||||
static public function getNbrSales($id_product)
|
||||
public static function getNbrSales($id_product)
|
||||
{
|
||||
$result = Db::getInstance()->getRow('SELECT `sale_nbr` FROM '._DB_PREFIX_.'product_sale WHERE `id_product` = '.(int)($id_product));
|
||||
if (!$result OR empty($result) OR !key_exists('sale_nbr', $result))
|
||||
@@ -175,7 +175,7 @@ class ProductSaleCore
|
||||
return (int)($result['sale_nbr']);
|
||||
}
|
||||
|
||||
static public function removeProductSale($id_product, $qty = 1)
|
||||
public static function removeProductSale($id_product, $qty = 1)
|
||||
{
|
||||
$nbrSales = self::getNbrSales($id_product);
|
||||
if ($nbrSales > 1)
|
||||
|
||||
+2
-2
@@ -58,7 +58,7 @@ class ProfileCore extends ObjectModel
|
||||
*
|
||||
* @return array Profiles
|
||||
*/
|
||||
static public function getProfiles($id_lang)
|
||||
public static function getProfiles($id_lang)
|
||||
{
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
||||
SELECT p.`id_profile`, `name`
|
||||
@@ -72,7 +72,7 @@ class ProfileCore extends ObjectModel
|
||||
*
|
||||
* @return string Profile
|
||||
*/
|
||||
static public function getProfile($id_profile, $id_lang = NULL)
|
||||
public static function getProfile($id_profile, $id_lang = NULL)
|
||||
{
|
||||
if ($id_lang == NULL)
|
||||
$id_lang = Configuration::get('PS_LANG_DEFAULT');
|
||||
|
||||
@@ -70,7 +70,7 @@ class QuickAccessCore extends ObjectModel
|
||||
*
|
||||
* @return array QuickAccesses
|
||||
*/
|
||||
static public function getQuickAccesses($id_lang)
|
||||
public static function getQuickAccesses($id_lang)
|
||||
{
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
||||
SELECT *
|
||||
|
||||
+2
-2
@@ -239,7 +239,7 @@ class SceneCore extends ObjectModel
|
||||
* @param integer $id_scene Scene id
|
||||
* @return array Categories where scene is indexed
|
||||
*/
|
||||
static public function getIndexedCategories($id_scene)
|
||||
public static function getIndexedCategories($id_scene)
|
||||
{
|
||||
return Db::getInstance()->ExecuteS('
|
||||
SELECT `id_category`
|
||||
@@ -253,7 +253,7 @@ class SceneCore extends ObjectModel
|
||||
* @param string $name Scene name
|
||||
* @return string Name without position
|
||||
*/
|
||||
static public function hideScenePosition($name)
|
||||
public static function hideScenePosition($name)
|
||||
{
|
||||
return preg_replace('/^[0-9]+\./', '', $name);
|
||||
}
|
||||
|
||||
+10
-3
@@ -330,10 +330,13 @@ class SearchCore
|
||||
return $features;
|
||||
}
|
||||
|
||||
public static function indexation($full = false)
|
||||
public static function indexation($full = false, $id_product = false)
|
||||
{
|
||||
$db = Db::getInstance();
|
||||
$dropIndex = false;
|
||||
|
||||
if ($id_product)
|
||||
$full = false;
|
||||
|
||||
if ($full)
|
||||
{
|
||||
@@ -344,7 +347,11 @@ class SearchCore
|
||||
}
|
||||
else
|
||||
{
|
||||
$products = $db->ExecuteS('SELECT id_product FROM '._DB_PREFIX_.'product WHERE indexed = 0');
|
||||
// Do it even if you already know the product id on order to be sure that it exists
|
||||
$products = $db->ExecuteS('
|
||||
SELECT id_product
|
||||
FROM '._DB_PREFIX_.'product
|
||||
WHERE '.($id_product ? 'id_product = '.(int)$id_product : 'indexed = 0'));
|
||||
|
||||
$ids = array();
|
||||
if ($products)
|
||||
@@ -594,4 +601,4 @@ class SearchCore
|
||||
|
||||
return Product::getProductsProperties((int)$id_lang, $result);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,7 +50,7 @@ class SearchEngineCore extends ObjectModel
|
||||
if (!isset($parsedUrl['host']) OR !isset($parsedUrl['query']))
|
||||
return false;
|
||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('SELECT `server`, `getvar` FROM `'._DB_PREFIX_.'search_engine`');
|
||||
foreach ($result as $index => $row)
|
||||
foreach ($result as $row)
|
||||
{
|
||||
$host =& $row['server'];
|
||||
$varname =& $row['getvar'];
|
||||
|
||||
+35
-16
@@ -65,14 +65,14 @@ class SpecificPriceCore extends ObjectModel
|
||||
return $fields;
|
||||
}
|
||||
|
||||
static public function getByProductId($id_product)
|
||||
public static function getByProductId($id_product)
|
||||
{
|
||||
return Db::getInstance()->ExecuteS('
|
||||
SELECT * FROM `'._DB_PREFIX_.'specific_price` WHERE `id_product` = '.(int)($id_product)
|
||||
);
|
||||
}
|
||||
|
||||
static public function getIdsByProductId($id_product)
|
||||
public static function getIdsByProductId($id_product)
|
||||
{
|
||||
return Db::getInstance()->ExecuteS('
|
||||
SELECT `id_specific_price` FROM `'._DB_PREFIX_.'specific_price` WHERE `id_product` = '.(int)$id_product.'
|
||||
@@ -112,7 +112,7 @@ class SpecificPriceCore extends ObjectModel
|
||||
return preg_split('/;/', $priority);
|
||||
}
|
||||
|
||||
static public function getSpecificPrice($id_product, $id_shop, $id_currency, $id_country, $id_group, $quantity)
|
||||
public static function getSpecificPrice($id_product, $id_shop, $id_currency, $id_country, $id_group, $quantity)
|
||||
{
|
||||
/*
|
||||
** The date is not taken into account for the cache, but this is for the better because it keeps the consistency for the whole script.
|
||||
@@ -132,13 +132,18 @@ class SpecificPriceCore extends ObjectModel
|
||||
AND `id_country` IN (0, '.(int)$id_country.')
|
||||
AND `id_group` IN (0, '.(int)$id_group.')
|
||||
AND `from_quantity` <= '.(int)$quantity.'
|
||||
AND (`from` = \'0000-00-00 00:00:00\' OR (\''.$now.'\' >= `from` AND \''.$now.'\' <= `to`))
|
||||
AND
|
||||
(
|
||||
(`from` = \'0000-00-00 00:00:00\' OR \''.$now.'\' >= `from`)
|
||||
AND
|
||||
(`to` = \'0000-00-00 00:00:00\' OR \''.$now.'\' <= `to`)
|
||||
)
|
||||
ORDER BY `score` DESC, `from_quantity` DESC');
|
||||
}
|
||||
return self::$_specificPriceCache[$key];
|
||||
}
|
||||
|
||||
static public function setPriorities($priorities)
|
||||
public static function setPriorities($priorities)
|
||||
{
|
||||
$value = '';
|
||||
foreach ($priorities as $priority)
|
||||
@@ -156,9 +161,8 @@ class SpecificPriceCore extends ObjectModel
|
||||
');
|
||||
}
|
||||
|
||||
static public function setSpecificPriority($id_product, $priorities)
|
||||
public static function setSpecificPriority($id_product, $priorities)
|
||||
{
|
||||
$fields = '';
|
||||
$value = '';
|
||||
foreach ($priorities as $priority)
|
||||
$value .= pSQL($priority).';';
|
||||
@@ -170,7 +174,7 @@ class SpecificPriceCore extends ObjectModel
|
||||
');
|
||||
}
|
||||
|
||||
static public function getQuantityDiscounts($id_product, $id_shop, $id_currency, $id_country, $id_group)
|
||||
public static function getQuantityDiscounts($id_product, $id_shop, $id_currency, $id_country, $id_group)
|
||||
{
|
||||
$now = date('Y-m-d H:i:s');
|
||||
$res = Db::getInstance()->ExecuteS('
|
||||
@@ -181,8 +185,13 @@ class SpecificPriceCore extends ObjectModel
|
||||
`id_shop` IN(0, '.(int)($id_shop).') AND
|
||||
`id_currency` IN(0, '.(int)($id_currency).') AND
|
||||
`id_country` IN(0, '.(int)($id_country).') AND
|
||||
`id_group` IN(0, '.(int)($id_group).') AND
|
||||
(`from` = \'0000-00-00 00:00:00\' OR (\''.$now.'\' >= `from` AND \''.$now.'\' <= `to`))
|
||||
`id_group` IN(0, '.(int)($id_group).')
|
||||
AND
|
||||
(
|
||||
(`from` = \'0000-00-00 00:00:00\' OR \''.$now.'\' >= `from`)
|
||||
AND
|
||||
(`to` = \'0000-00-00 00:00:00\' OR \''.$now.'\' <= `to`)
|
||||
)
|
||||
ORDER BY `score` DESC, `from_quantity` DESC
|
||||
');
|
||||
|
||||
@@ -203,7 +212,7 @@ class SpecificPriceCore extends ObjectModel
|
||||
return $targeted_prices;
|
||||
}
|
||||
|
||||
static public function getQuantityDiscount($id_product, $id_shop, $id_currency, $id_country, $id_group, $quantity)
|
||||
public static function getQuantityDiscount($id_product, $id_shop, $id_currency, $id_country, $id_group, $quantity)
|
||||
{
|
||||
$now = date('Y-m-d H:i:s');
|
||||
return Db::getInstance()->getRow('
|
||||
@@ -215,13 +224,18 @@ class SpecificPriceCore extends ObjectModel
|
||||
`id_currency` IN(0, '.(int)($id_currency).') AND
|
||||
`id_country` IN(0, '.(int)($id_country).') AND
|
||||
`id_group` IN(0, '.(int)($id_group).') AND
|
||||
`from_quantity` >= '.(int)($quantity).' AND
|
||||
(`from` = \'0000-00-00 00:00:00\' OR (\''.$now.'\' >= `from` AND \''.$now.'\' <= `to`))
|
||||
`from_quantity` >= '.(int)($quantity).'
|
||||
AND
|
||||
(
|
||||
(`from` = \'0000-00-00 00:00:00\' OR \''.$now.'\' >= `from`)
|
||||
AND
|
||||
(`to` = \'0000-00-00 00:00:00\' OR \''.$now.'\' <= `to`)
|
||||
)
|
||||
ORDER BY `score` DESC, `from_quantity` DESC
|
||||
');
|
||||
}
|
||||
|
||||
static public function getProductIdByDate($id_shop, $id_currency, $id_country, $id_group, $beginning, $ending)
|
||||
public static function getProductIdByDate($id_shop, $id_currency, $id_country, $id_group, $beginning, $ending)
|
||||
{
|
||||
$resource = Db::getInstance()->ExecuteS('
|
||||
SELECT `id_product`
|
||||
@@ -231,7 +245,12 @@ class SpecificPriceCore extends ObjectModel
|
||||
`id_country` IN(0, '.(int)($id_country).') AND
|
||||
`id_group` IN(0, '.(int)($id_group).') AND
|
||||
`from_quantity` = 1 AND
|
||||
(`from` = \'0000-00-00 00:00:00\' OR (\''.$beginning.'\' >= `from` AND \''.$ending.'\' <= `to`)) AND
|
||||
(
|
||||
(`from` = \'0000-00-00 00:00:00\' OR \''.$beginning.'\' >= `from`)
|
||||
AND
|
||||
(`to` = \'0000-00-00 00:00:00\' OR \''.$ending.'\' <= `to`)
|
||||
)
|
||||
AND
|
||||
`reduction` > 0
|
||||
', false);
|
||||
$ids_product = array();
|
||||
@@ -240,7 +259,7 @@ class SpecificPriceCore extends ObjectModel
|
||||
return $ids_product;
|
||||
}
|
||||
|
||||
static public function deleteByProductId($id_product)
|
||||
public static function deleteByProductId($id_product)
|
||||
{
|
||||
return Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'specific_price` WHERE `id_product` = '.(int)($id_product));
|
||||
}
|
||||
|
||||
+3
-3
@@ -82,7 +82,7 @@ class StateCore extends ObjectModel
|
||||
* @param integer $id_state Country ID
|
||||
* @return string State name
|
||||
*/
|
||||
static public function getNameById($id_state)
|
||||
public static function getNameById($id_state)
|
||||
{
|
||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
||||
SELECT `name`
|
||||
@@ -98,7 +98,7 @@ class StateCore extends ObjectModel
|
||||
* @param string $id_state Country ID
|
||||
* @return integer state id
|
||||
*/
|
||||
static public function getIdByName($state)
|
||||
public static function getIdByName($state)
|
||||
{
|
||||
$result = Db::getInstance()->getRow('
|
||||
SELECT `id_state`
|
||||
@@ -114,7 +114,7 @@ class StateCore extends ObjectModel
|
||||
* @param string $iso_code Iso code
|
||||
* @return integer state id
|
||||
*/
|
||||
static public function getIdByIso($iso_code)
|
||||
public static function getIdByIso($iso_code)
|
||||
{
|
||||
return Db::getInstance()->getValue('
|
||||
SELECT `id_state`
|
||||
|
||||
@@ -63,7 +63,7 @@ class StockMvtReasonCore extends ObjectModel
|
||||
return parent::getTranslationsFields(array('name'));
|
||||
}
|
||||
|
||||
static public function getStockMvtReasons($id_lang)
|
||||
public static function getStockMvtReasons($id_lang)
|
||||
{
|
||||
$sql = 'SELECT smrl.name, smr.id_stock_mvt_reason, smr.sign
|
||||
FROM '._DB_PREFIX_.'stock_mvt_reason smr
|
||||
|
||||
@@ -43,7 +43,7 @@ class SubDomainCore extends ObjectModel
|
||||
return $fields;
|
||||
}
|
||||
|
||||
static public function getSubDomains()
|
||||
public static function getSubDomains()
|
||||
{
|
||||
if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('SELECT `name` FROM `'._DB_PREFIX_.'subdomain`'))
|
||||
return false;
|
||||
|
||||
+10
-7
@@ -111,7 +111,7 @@ class SupplierCore extends ObjectModel
|
||||
*
|
||||
* @return array Suppliers
|
||||
*/
|
||||
static public function getSuppliers($getNbProducts = false, $id_lang = 0, $active = true, $p = false, $n = false, $all_groups = false)
|
||||
public static function getSuppliers($getNbProducts = false, $id_lang = 0, $active = true, $p = false, $n = false, $all_groups = false)
|
||||
{
|
||||
if (!$id_lang)
|
||||
$id_lang = Configuration::get('PS_LANG_DEFAULT');
|
||||
@@ -165,14 +165,14 @@ class SupplierCore extends ObjectModel
|
||||
* @return string name
|
||||
*/
|
||||
static protected $cacheName = array();
|
||||
static public function getNameById($id_supplier)
|
||||
public static function getNameById($id_supplier)
|
||||
{
|
||||
if (!isset(self::$cacheName[$id_supplier]))
|
||||
self::$cacheName[$id_supplier] = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
||||
SELECT `name` FROM `'._DB_PREFIX_.'supplier` WHERE `id_supplier` = '.(int)($id_supplier));
|
||||
return self::$cacheName[$id_supplier];
|
||||
}
|
||||
static public function getIdByName($name)
|
||||
public static function getIdByName($name)
|
||||
{
|
||||
$result = Db::getInstance()->getRow('
|
||||
SELECT `id_supplier`
|
||||
@@ -183,7 +183,7 @@ class SupplierCore extends ObjectModel
|
||||
return false;
|
||||
}
|
||||
|
||||
static public function getProducts($id_supplier, $id_lang, $p, $n, $orderBy = NULL, $orderWay = NULL, $getTotal = false, $active = true)
|
||||
public static function getProducts($id_supplier, $id_lang, $p, $n, $orderBy = NULL, $orderWay = NULL, $getTotal = false, $active = true, $active_category = true)
|
||||
{
|
||||
if ($p < 1) $p = 1;
|
||||
if (empty($orderBy) OR $orderBy == 'position') $orderBy = 'name';
|
||||
@@ -206,7 +206,8 @@ class SupplierCore extends ObjectModel
|
||||
AND p.`id_product` IN (
|
||||
SELECT cp.`id_product`
|
||||
FROM `'._DB_PREFIX_.'category_group` cg
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`)'.
|
||||
($active_category ? ' INNER JOIN `'._DB_PREFIX_.'category` ca ON cp.`id_category` = ca.`id_category` AND ca.`active` = 1' : '').'
|
||||
WHERE cg.`id_group` '.$sqlGroups.'
|
||||
)';
|
||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql);
|
||||
@@ -231,11 +232,13 @@ class SupplierCore extends ObjectModel
|
||||
AND p.`id_product` IN (
|
||||
SELECT cp.`id_product`
|
||||
FROM `'._DB_PREFIX_.'category_group` cg
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`)'.
|
||||
($active_category ? ' INNER JOIN `'._DB_PREFIX_.'category` ca ON cp.`id_category` = ca.`id_category` AND ca.`active` = 1' : '').'
|
||||
WHERE cg.`id_group` '.$sqlGroups.'
|
||||
)
|
||||
ORDER BY '.(($orderBy == 'id_product') ? 'p.' : '').'`'.pSQL($orderBy).'` '.pSQL($orderWay).'
|
||||
LIMIT '.(((int)($p) - 1) * (int)($n)).','.(int)($n);
|
||||
|
||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql);
|
||||
if (!$result)
|
||||
return false;
|
||||
@@ -258,7 +261,7 @@ class SupplierCore extends ObjectModel
|
||||
* @param $id_supplier Supplier id
|
||||
* @return boolean
|
||||
*/
|
||||
static public function supplierExists($id_supplier)
|
||||
public static function supplierExists($id_supplier)
|
||||
{
|
||||
$row = Db::getInstance()->getRow('
|
||||
SELECT `id_supplier`
|
||||
|
||||
+7
-7
@@ -77,7 +77,7 @@ class TabCore extends ObjectModel
|
||||
return self::initAccess($this->id);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
static public function initAccess($id_tab, Context $context = null)
|
||||
{
|
||||
if (!$context)
|
||||
@@ -110,7 +110,7 @@ class TabCore extends ObjectModel
|
||||
*
|
||||
* @return integer tab id
|
||||
*/
|
||||
static public function getCurrentTabId()
|
||||
public static function getCurrentTabId()
|
||||
{
|
||||
return self::getIdFromClassName(Tools::getValue('tab'));
|
||||
}
|
||||
@@ -120,7 +120,7 @@ class TabCore extends ObjectModel
|
||||
*
|
||||
* @return integer tab parent id
|
||||
*/
|
||||
static public function getCurrentParentId()
|
||||
public static function getCurrentParentId()
|
||||
{
|
||||
if ($result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('SELECT `id_parent` FROM `'._DB_PREFIX_.'tab` WHERE LOWER(class_name) = \''.pSQL(Tools::strtolower(Tools::getValue('tab'))).'\''))
|
||||
return $result['id_parent'];
|
||||
@@ -132,7 +132,7 @@ class TabCore extends ObjectModel
|
||||
*
|
||||
* @return array tab
|
||||
*/
|
||||
static public function getTab($id_lang, $id_tab)
|
||||
public static function getTab($id_lang, $id_tab)
|
||||
{
|
||||
/* Tabs selection */
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
||||
@@ -148,7 +148,7 @@ class TabCore extends ObjectModel
|
||||
* @return array tabs
|
||||
*/
|
||||
static $_cache_tabs = array();
|
||||
static public function getTabs($id_lang, $id_parent = NULL)
|
||||
public static function getTabs($id_lang, $id_parent = NULL)
|
||||
{
|
||||
if (!isset(self::$_cache_tabs[$id_lang]))
|
||||
{
|
||||
@@ -181,7 +181,7 @@ class TabCore extends ObjectModel
|
||||
* @param string class_name
|
||||
* @return int id_tab
|
||||
*/
|
||||
static public function getIdFromClassName($class_name)
|
||||
public static function getIdFromClassName($class_name)
|
||||
{
|
||||
if (self::$_getIdFromClassName === null)
|
||||
{
|
||||
@@ -193,7 +193,7 @@ class TabCore extends ObjectModel
|
||||
return (isset(self::$_getIdFromClassName[$class_name]) ? (int)self::$_getIdFromClassName[$class_name] : false);
|
||||
}
|
||||
|
||||
static public function getNbTabs($id_parent = NULL)
|
||||
public static function getNbTabs($id_parent = NULL)
|
||||
{
|
||||
return (int)Db::getInstance()->getValue('
|
||||
SELECT COUNT(*)
|
||||
|
||||
+4
-4
@@ -91,7 +91,7 @@ class TagCore extends ObjectModel
|
||||
*
|
||||
* @return boolean Operation success
|
||||
*/
|
||||
static public function addTags($id_lang, $id_product, $string)
|
||||
public static function addTags($id_lang, $id_product, $string)
|
||||
{
|
||||
if (!Validate::isUnsignedId($id_lang) OR !Validate::isTagsList($string))
|
||||
return false;
|
||||
@@ -124,7 +124,7 @@ class TagCore extends ObjectModel
|
||||
VALUES '.$data);
|
||||
}
|
||||
|
||||
static public function getMainTags($id_lang, $nb = 10)
|
||||
public static function getMainTags($id_lang, $nb = 10)
|
||||
{
|
||||
$groups = FrontController::getCurrentCustomerGroups();
|
||||
$sqlGroups = (count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1');
|
||||
@@ -147,7 +147,7 @@ class TagCore extends ObjectModel
|
||||
LIMIT 0, '.(int)($nb));
|
||||
}
|
||||
|
||||
static public function getProductTags($id_product)
|
||||
public static function getProductTags($id_product)
|
||||
{
|
||||
if (!$tmp = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
||||
SELECT t.`id_lang`, t.`name`
|
||||
@@ -195,7 +195,7 @@ class TagCore extends ObjectModel
|
||||
return $result;
|
||||
}
|
||||
|
||||
static public function deleteTagsForProduct($id_product)
|
||||
public static function deleteTagsForProduct($id_product)
|
||||
{
|
||||
return Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'product_tag` WHERE `id_product` = '.(int)($id_product));
|
||||
}
|
||||
|
||||
+3
-3
@@ -79,7 +79,7 @@ class TaxCore extends ObjectModel
|
||||
*
|
||||
* @return array Taxes
|
||||
*/
|
||||
static public function getTaxes($id_lang = false, $active = 1)
|
||||
public static function getTaxes($id_lang = false, $active = 1)
|
||||
{
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
||||
SELECT t.id_tax, t.rate'.((int)($id_lang) ? ', tl.name, tl.id_lang ' : '').'
|
||||
@@ -89,12 +89,12 @@ class TaxCore extends ObjectModel
|
||||
ORDER BY `name` ASC' : ''));
|
||||
}
|
||||
|
||||
static public function excludeTaxeOption()
|
||||
public static function excludeTaxeOption()
|
||||
{
|
||||
return !Configuration::get('PS_TAX');
|
||||
}
|
||||
|
||||
public static function getTaxIdByName($tax_name, $active =1)
|
||||
public static function getTaxIdByName($tax_name, $active = 1)
|
||||
{
|
||||
$tax = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
||||
SELECT t.`id_tax`
|
||||
|
||||
+106
-31
@@ -134,7 +134,7 @@ class ToolsCore
|
||||
*
|
||||
* @param boolean $http
|
||||
* @param boolean $entities
|
||||
* @return void
|
||||
* @return string host
|
||||
*/
|
||||
public static function getHttpHost($http = false, $entities = false)
|
||||
{
|
||||
@@ -147,11 +147,11 @@ class ToolsCore
|
||||
}
|
||||
|
||||
/**
|
||||
* getShopDomain return domain name according to configuration
|
||||
* getShopDomain returns domain name according to configuration and ignoring ssl
|
||||
*
|
||||
* @param boolean $http if true, return domain name with protocol
|
||||
* @param boolean $entities if true,
|
||||
* @return void
|
||||
* @return string domain
|
||||
*/
|
||||
public static function getShopDomain($http = false, $entities = false)
|
||||
{
|
||||
@@ -164,6 +164,13 @@ class ToolsCore
|
||||
return $domain;
|
||||
}
|
||||
|
||||
/**
|
||||
* getShopDomainSsl returns domain name according to configuration and depending on ssl activation
|
||||
*
|
||||
* @param boolean $http if true, return domain name with protocol
|
||||
* @param boolean $entities if true,
|
||||
* @return string domain
|
||||
*/
|
||||
public static function getShopDomainSsl($http = false, $entities = false)
|
||||
{
|
||||
if (!$domain = ShopUrl::getMainShopDomainSSL())
|
||||
@@ -178,7 +185,7 @@ class ToolsCore
|
||||
/**
|
||||
* Get the server variable SERVER_NAME
|
||||
*
|
||||
* @param string $referrer URL referrer
|
||||
* @return string server name
|
||||
*/
|
||||
static function getServerName()
|
||||
{
|
||||
@@ -210,6 +217,8 @@ class ToolsCore
|
||||
|
||||
/**
|
||||
* Check if the current page use SSL connection on not
|
||||
*
|
||||
* @return bool uses SSL
|
||||
*/
|
||||
public static function usingSecureMode()
|
||||
{
|
||||
@@ -217,11 +226,13 @@ class ToolsCore
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current url prefix protocole (https/http)
|
||||
* Get the current url prefix protocol (https/http)
|
||||
*
|
||||
* @return string protocol
|
||||
*/
|
||||
public static function getCurrentUrlProtocolPrefix()
|
||||
{
|
||||
if(Tools::usingSecureMode())
|
||||
if(self::usingSecureMode())
|
||||
return 'https://';
|
||||
else
|
||||
return 'http://';
|
||||
@@ -231,6 +242,7 @@ class ToolsCore
|
||||
* Secure an URL referrer
|
||||
*
|
||||
* @param string $referrer URL referrer
|
||||
* @return secured referrer
|
||||
*/
|
||||
public static function secureReferrer($referrer)
|
||||
{
|
||||
@@ -267,6 +279,8 @@ class ToolsCore
|
||||
|
||||
/**
|
||||
* Change language in cookie while clicking on a flag
|
||||
*
|
||||
* @return string iso code
|
||||
*/
|
||||
public static function setCookieLanguage($cookie)
|
||||
{
|
||||
@@ -307,6 +321,9 @@ class ToolsCore
|
||||
return $iso;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set cookie id_lang
|
||||
*/
|
||||
public static function switchLanguage(Context $context = null)
|
||||
{
|
||||
if (!$context)
|
||||
@@ -315,6 +332,11 @@ class ToolsCore
|
||||
$context->cookie->id_lang = $id_lang;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set cookie currency from POST or default currency
|
||||
*
|
||||
* @return Currency object
|
||||
*/
|
||||
public static function setCurrency($cookie)
|
||||
{
|
||||
if (self::isSubmit('SubmitCurrency'))
|
||||
@@ -603,7 +625,7 @@ class ToolsCore
|
||||
{
|
||||
global $maintenance;
|
||||
|
||||
if (!(isset($maintenance) AND (!in_array(Tools::getRemoteAddr(), explode(',', Configuration::get('PS_MAINTENANCE_IP'))))))
|
||||
if (!(isset($maintenance) AND (!in_array(self::getRemoteAddr(), explode(',', Configuration::get('PS_MAINTENANCE_IP'))))))
|
||||
{
|
||||
/* Products specifics meta tags */
|
||||
if ($id_product = self::getValue('id_product'))
|
||||
@@ -771,6 +793,7 @@ class ToolsCore
|
||||
{
|
||||
return !empty($string) ? self::encrypt($string) : false;
|
||||
}
|
||||
|
||||
public static function getAdminTokenLite($tab, Context $context = null)
|
||||
{
|
||||
if (!$context)
|
||||
@@ -1072,9 +1095,9 @@ class ToolsCore
|
||||
{
|
||||
$method = (int)(Configuration::get('PS_PRICE_ROUND_MODE'));
|
||||
if ($method == PS_ROUND_UP)
|
||||
return Tools::ceilf($value, $precision);
|
||||
return self::ceilf($value, $precision);
|
||||
elseif ($method == PS_ROUND_DOWN)
|
||||
return Tools::floorf($value, $precision);
|
||||
return self::floorf($value, $precision);
|
||||
return round($value, $precision);
|
||||
}
|
||||
|
||||
@@ -1134,6 +1157,18 @@ class ToolsCore
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function simplexml_load_file($url, $class_name = null)
|
||||
{
|
||||
if (in_array(ini_get('allow_url_fopen'), array('On', 'on', '1')))
|
||||
return simplexml_load_file($url, $class_name);
|
||||
elseif (function_exists('curl_init'))
|
||||
{
|
||||
return simplexml_load_string(Tools::file_get_contents($url), $class_name);
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function minifyHTML($html_content)
|
||||
{
|
||||
if (strlen($html_content) > 0)
|
||||
@@ -1176,9 +1211,11 @@ class ToolsCore
|
||||
* Translates a string with underscores into camel case (e.g. first_name -> firstName)
|
||||
* @prototype string public static function toCamelCase(string $str[, bool $capitaliseFirstChar = false])
|
||||
*/
|
||||
public static function toCamelCase($str, $capitaliseFirstChar = false) {
|
||||
public static function toCamelCase($str, $capitaliseFirstChar = false)
|
||||
{
|
||||
$str = strtolower($str);
|
||||
if($capitaliseFirstChar)
|
||||
$str[0] = strtoupper($str[0]);
|
||||
$str = ucfirst($str);
|
||||
return preg_replace_callback('/_([a-z])/', create_function('$c', 'return strtoupper($c[1]);'), $str);
|
||||
}
|
||||
|
||||
@@ -1204,10 +1241,18 @@ class ToolsCore
|
||||
{
|
||||
if (strlen($html_content) > 0)
|
||||
{
|
||||
$htmlContentCopy = $html_content;
|
||||
$html_content = preg_replace_callback(
|
||||
'/\\s*(<script\\b[^>]*?>)([\\s\\S]*?)(<\\/script>)\\s*/i'
|
||||
,array('Tools', '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 ) {
|
||||
error_log('ERROR: PREG_BACKTRACK_LIMIT_ERROR in function packJSinHTML');
|
||||
return $htmlContentCopy;
|
||||
}
|
||||
return $html_content;
|
||||
}
|
||||
return false;
|
||||
@@ -1275,17 +1320,17 @@ class ToolsCore
|
||||
{
|
||||
global $current_css_file;
|
||||
|
||||
$protocolLink = Tools::getCurrentUrlProtocolPrefix();
|
||||
$protocol_link = self::getCurrentUrlProtocolPrefix();
|
||||
|
||||
if (array_key_exists(1, $matches))
|
||||
{
|
||||
$tmp = dirname($current_css_file).'/'.$matches[1];
|
||||
return 'url(\''.$protocolLink.Tools::getMediaServer($tmp).$tmp.'\')';
|
||||
return 'url(\''.$protocol_link.self::getMediaServer($tmp).$tmp.'\')';
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* addJS load a javascript file in the header
|
||||
*
|
||||
* @deprecated as of 1.5 use FrontController->addJS()
|
||||
@@ -1326,7 +1371,7 @@ class ToolsCore
|
||||
$compressed_css_files = array();
|
||||
$compressed_css_files_not_found = array();
|
||||
$compressed_css_files_infos = array();
|
||||
$protocolLink = Tools::getCurrentUrlProtocolPrefix();
|
||||
$protocolLink = self::getCurrentUrlProtocolPrefix();
|
||||
|
||||
// group css files by media
|
||||
foreach ($css_files as $filename => $media)
|
||||
@@ -1337,7 +1382,7 @@ class ToolsCore
|
||||
$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_.self::str_replace_once(__PS_BASE_URI__, '/', $url_data['path']);
|
||||
$css_files_by_media[$media]['files'][] = $infos;
|
||||
if (!array_key_exists('date', $css_files_by_media[$media]))
|
||||
$css_files_by_media[$media]['date'] = 0;
|
||||
@@ -1371,7 +1416,7 @@ class ToolsCore
|
||||
foreach ($media_infos['files'] as $file_infos)
|
||||
{
|
||||
if (file_exists($file_infos['path']))
|
||||
$compressed_css_files[$media] .= Tools::minifyCSS(file_get_contents($file_infos['path']), $file_infos['uri']);
|
||||
$compressed_css_files[$media] .= self::minifyCSS(file_get_contents($file_infos['path']), $file_infos['uri']);
|
||||
else
|
||||
$compressed_css_files_not_found[] = $file_infos['path'];
|
||||
}
|
||||
@@ -1392,7 +1437,7 @@ class ToolsCore
|
||||
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[$protocolLink.self::getMediaServer($url).$url] = $media;
|
||||
}
|
||||
return $css_files;
|
||||
}
|
||||
@@ -1412,7 +1457,7 @@ class ToolsCore
|
||||
$compressed_js_file_date = 0;
|
||||
$compressed_js_filename = '';
|
||||
$js_external_files = array();
|
||||
$protocolLink = Tools::getCurrentUrlProtocolPrefix();
|
||||
$protocolLink = self::getCurrentUrlProtocolPrefix();
|
||||
|
||||
// get js files infos
|
||||
foreach ($js_files as $filename)
|
||||
@@ -1426,7 +1471,7 @@ class ToolsCore
|
||||
$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_.self::str_replace_once(__PS_BASE_URI__, '/', $url_data['path']);
|
||||
$js_files_infos[] = $infos;
|
||||
|
||||
$js_files_date = max(
|
||||
@@ -1454,7 +1499,7 @@ class ToolsCore
|
||||
else
|
||||
$compressed_js_files_not_found[] = $file_infos['path'];
|
||||
}
|
||||
$content = Tools::packJS($content);
|
||||
$content = self::packJS($content);
|
||||
|
||||
if (!empty($compressed_js_files_not_found))
|
||||
$content = '/* WARNING ! file(s) not found : "'.
|
||||
@@ -1467,8 +1512,8 @@ class ToolsCore
|
||||
|
||||
// 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);
|
||||
|
||||
}
|
||||
|
||||
private static $_cache_nb_media_servers = null;
|
||||
@@ -1488,10 +1533,10 @@ class ToolsCore
|
||||
|
||||
if (self::$_cache_nb_media_servers AND ($id_media_server = (abs(crc32($filename)) % self::$_cache_nb_media_servers + 1)))
|
||||
return constant('_MEDIA_SERVER_'.$id_media_server.'_');
|
||||
return Tools::getHttpHost();
|
||||
return self::getHttpHost();
|
||||
}
|
||||
|
||||
public static function generateHtaccess($path, $rewrite_settings, $cache_control, $specific = '')
|
||||
public static function generateHtaccess($path, $rewrite_settings, $cache_control, $specific = '', $disableMuliviews = false)
|
||||
{
|
||||
if (!$writeFd = @fopen($path, 'w'))
|
||||
return false;
|
||||
@@ -1530,8 +1575,8 @@ class ToolsCore
|
||||
$tab['RewriteRule'][$domain]['content']['^'.ltrim($uri['uri'], '/').'([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*\.jpg$'] = _PS_PROD_IMG_.'$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7.jpg [L]';
|
||||
$tab['RewriteRule'][$domain]['content']['^'.ltrim($uri['uri'], '/').'([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*\.jpg$'] = _PS_PROD_IMG_.'$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8.jpg [L]';
|
||||
$tab['RewriteRule'][$domain]['content']['^'.ltrim($uri['uri'], '/').'([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*\.jpg$'] = _PS_PROD_IMG_.'$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9.jpg [L]';
|
||||
|
||||
$tab['RewriteRule'][$domain]['content']['^'.ltrim($uri['uri'], '/').'c/([0-9]+)(\-[_a-zA-Z0-9-]*)/[_a-zA-Z0-9-]*\.jpg$'] = 'img/c/$1$2.jpg [L]';
|
||||
$tab['RewriteRule'][$domain]['content']['^'.ltrim($uri['uri'], '/').'c/([a-zA-Z-]+)/[a-zA-Z0-9-]+\.jpg$'] = 'img/c/$1.jpg [L]';
|
||||
|
||||
if ($multilang)
|
||||
{
|
||||
@@ -1591,9 +1636,13 @@ class ToolsCore
|
||||
fwrite($writeFd, $specific);
|
||||
// RewriteEngine
|
||||
fwrite($writeFd, "\n<IfModule mod_rewrite.c>\n");
|
||||
fwrite($writeFd, "\nRewriteEngine on\n\n");
|
||||
// fwrite($writeFd, $tab['RewriteRule']['comment']."\n");
|
||||
// Webservice needs apache_mod_rewrite in order to work
|
||||
|
||||
if ($disableMuliviews)
|
||||
fwrite($writeFd, "\n# Disable Multiviews\nOptions -Multiviews\n\n");
|
||||
|
||||
fwrite($writeFd, $tab['RewriteEngine']['comment']."\nRewriteEngine on\n\n");
|
||||
fwrite($writeFd, $tab['RewriteRule']['comment']."\n");
|
||||
// Webservice
|
||||
fwrite($writeFd, 'RewriteRule ^api/?(.*)$ '.__PS_BASE_URI__."webservice/dispatcher.php?url=$1 [QSA,L]\n");
|
||||
|
||||
fwrite($writeFd, "RewriteCond %{REQUEST_FILENAME} -s [OR]\nRewriteCond %{REQUEST_FILENAME} -l [OR]\nRewriteCond %{REQUEST_FILENAME} -d\nRewriteRule ^.*$ - [NC,L]\nRewriteRule ^.*\$ index.php [NC,L]\n");
|
||||
@@ -1704,7 +1753,7 @@ FileETag INode MTime Size
|
||||
$callee = next($backtrace);
|
||||
trigger_error('Function <strong>'.$callee['function'].'()</strong> is deprecated in <strong>'.$callee['file'].'</strong> on line <strong>'.$callee['line'].'</strong><br />', E_USER_WARNING);
|
||||
|
||||
$message = Tools::displayError('The function').' '.$callee['function'].' ('.Tools::displayError('Line').' '.$callee['line'].') '.Tools::displayError('is deprecated and will be removed in the next major version.');
|
||||
$message = self::displayError('The function').' '.$callee['function'].' ('.self::displayError('Line').' '.$callee['line'].') '.self::displayError('is deprecated and will be removed in the next major version.');
|
||||
|
||||
Logger::addLog($message, 3, $callee['class']);
|
||||
}
|
||||
@@ -1718,7 +1767,7 @@ FileETag INode MTime Size
|
||||
$backtrace = debug_backtrace();
|
||||
$callee = next($backtrace);
|
||||
$error = 'Parameter <strong>'.$parameter.'</strong> in function <strong>'.$callee['function'].'()</strong> is deprecated in <strong>'.$callee['file'].'</strong> on line <strong>'.$callee['Line'].'</strong><br />';
|
||||
$message = Tools::displayError('The parameter').' '.$parameter.' '.Tools::displayError(' in function ').' '.$callee['function'].' ('.Tools::displayError('Line').' '.$callee['Line'].') '.Tools::displayError('is deprecated and will be removed in the next major version.');
|
||||
$message = self::displayError('The parameter').' '.$parameter.' '.self::displayError(' in function ').' '.$callee['function'].' ('.self::displayError('Line').' '.$callee['Line'].') '.self::displayError('is deprecated and will be removed in the next major version.');
|
||||
|
||||
self::throwDeprecated($error, $message, $callee['class']);
|
||||
}
|
||||
@@ -1818,7 +1867,6 @@ FileETag INode MTime Size
|
||||
public static function checkPhpVersion()
|
||||
{
|
||||
$version = null;
|
||||
$length = null;
|
||||
|
||||
if(defined('PHP_VERSION'))
|
||||
$version = PHP_VERSION;
|
||||
@@ -1979,6 +2027,20 @@ FileETag INode MTime Size
|
||||
{
|
||||
return $begin.((strpos($begin, '?') !== false) ? '&' : '?').$end;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display error and dies or silently log the error.
|
||||
*
|
||||
* @param string $msg
|
||||
* @param bool $die
|
||||
* @return success of logging
|
||||
*/
|
||||
public static function dieOrLog($msg, $die = true)
|
||||
{
|
||||
if ($die || (defined('_PS_MODE_DEV_') && _PS_MODE_DEV_))
|
||||
die($msg);
|
||||
return Logger::addLog($msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert \n and \r\n and \r to <br />
|
||||
@@ -1990,6 +2052,19 @@ FileETag INode MTime Size
|
||||
{
|
||||
return str_replace(array("\r\n", "\r", "\n"), '<br />', $str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear cache for Smarty
|
||||
*
|
||||
* @param objet $smarty
|
||||
*/
|
||||
public static function clearCache($smarty)
|
||||
{
|
||||
if (!Configuration::get('PS_FORCE_SMARTY_2'))
|
||||
$smarty->clearAllCache();
|
||||
else
|
||||
$smarty->clear_all_cache();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2011 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/osl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2011 PrestaShop SA
|
||||
* @version Release: $Revision$
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
class UpgraderCore{
|
||||
const DEFAULT_CHECK_VERSION_DELAY_HOURS = 24;
|
||||
/**
|
||||
* link contains hte url where to download the file
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $needUpgrade = false;
|
||||
private $noRefresh = false;
|
||||
|
||||
public $version_name;
|
||||
public $version_num;
|
||||
public $link;
|
||||
public $autoupgrade;
|
||||
|
||||
public function __get($var)
|
||||
{
|
||||
if($var == 'needUpgrade')
|
||||
return $this->isLastVersion();
|
||||
}
|
||||
/**
|
||||
* we need to checkPSVersion when we use that class
|
||||
* @param boolean noRefresh if true, checkPSVersion will not refresh its information
|
||||
* @return object Upgrader
|
||||
*/
|
||||
public function __construct($noRefresh = false)
|
||||
{
|
||||
$this->noRefresh = (bool)$noRefresh;
|
||||
}
|
||||
|
||||
/**
|
||||
* downloadLast download the last version of PrestaShop and save it in $dest/$filename
|
||||
*
|
||||
* @param string $dest directory where to save the file
|
||||
* @param string $filename new filename
|
||||
* @return boolean
|
||||
*
|
||||
* @TODO ftp if copy is not possible (safe_mode for example)
|
||||
*/
|
||||
public function downloadLast($dest, $filename = 'prestashop.zip')
|
||||
{
|
||||
if (empty($this->link))
|
||||
$this->checkPSVersion();
|
||||
|
||||
if (@copy($this->link, realpath($dest).DIRECTORY_SEPARATOR.$filename))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
public function isLastVersion()
|
||||
{
|
||||
if (empty($this->link))
|
||||
$this->checkPSVersion();
|
||||
|
||||
return $this->needUpgrade;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* checkPSVersion ask to prestashop.com if there is a new version. return an array if yes, false otherwise
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function checkPSVersion($force = false)
|
||||
{
|
||||
if (empty($this->link))
|
||||
{
|
||||
$lastCheck = Configuration::get('PS_LAST_VERSION_CHECK');
|
||||
// if we use the autoupgrade process, we will never refresh it
|
||||
// except if no check has been done before
|
||||
if (!($this->autoUpgrade AND $lastCheck) AND ($force OR ($lastCheck < time() - (3600 * Upgrader::DEFAULT_CHECK_VERSION_DELAY_HOURS))) )
|
||||
{
|
||||
libxml_set_streams_context(stream_context_create(array('http' => array('timeout' => 3))));
|
||||
if ($feed = @simplexml_load_file('http://www.prestashop.com/xml/version.xml'))
|
||||
{
|
||||
$this->version_name = (string)$feed->version->name;
|
||||
$this->version_num = (string)$feed->version->num;
|
||||
$this->link = (string)$feed->download->link;
|
||||
$this->autoupgrade = (int)$feed->autoupgrade;
|
||||
$configLastVersion = array(
|
||||
'name' => $this->version_name,
|
||||
'num' => $this->version_num,
|
||||
'link' => $this->link,
|
||||
'autoupgrade' => $this->autoupgrade
|
||||
);
|
||||
Configuration::updateValue('PS_LAST_VERSION',serialize($configLastVersion));
|
||||
Configuration::updateValue('PS_LAST_VERSION_CHECK',time());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$lastVersionCheck = unserialize(Configuration::get('PS_LAST_VERSION'));
|
||||
$this->version_name = $lastVersionCheck['name'];
|
||||
$this->version_num = $lastVersionCheck['num'];
|
||||
$this->link = $lastVersionCheck['link'];
|
||||
$this->autoupgrade = $lastVersionCheck['autoupgrade'];
|
||||
}
|
||||
}
|
||||
// retro-compatibility :
|
||||
// return array(name,link) if you don't use the last version
|
||||
// false otherwise
|
||||
if (version_compare(_PS_VERSION_, $this->version_num, '<'))
|
||||
{
|
||||
$this->needUpgrade = true;
|
||||
return array('name' => $this->version_name, 'link' => $this->link);
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
+88
-88
@@ -27,12 +27,12 @@
|
||||
|
||||
class ValidateCore
|
||||
{
|
||||
static public function isIp2Long($ip)
|
||||
public static function isIp2Long($ip)
|
||||
{
|
||||
return preg_match('#^-?[0-9]+$#', (string)$ip);
|
||||
}
|
||||
|
||||
static public function isAnything($data)
|
||||
public static function isAnything($data)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -43,7 +43,7 @@ class ValidateCore
|
||||
* @param string $email e-mail address to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isEmail($email)
|
||||
public static function isEmail($email)
|
||||
{
|
||||
return empty($email) OR preg_match('/^[a-z0-9!#$%&\'*+\/=?^`{}|~_-]+[.a-z0-9!#$%&\'*+\/=?^`{}|~_-]*@[a-z0-9]+[._a-z0-9-]*\.[a-z0-9]+$/ui', $email);
|
||||
}
|
||||
@@ -55,7 +55,7 @@ class ValidateCore
|
||||
* @param array $errors Reference array for catching errors
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isModuleUrl($url, &$errors)
|
||||
public static function isModuleUrl($url, &$errors)
|
||||
{
|
||||
if (!$url OR $url == 'http://')
|
||||
$errors[] = Tools::displayError('Please specify module URL');
|
||||
@@ -80,7 +80,7 @@ class ValidateCore
|
||||
* @param string $md5 MD5 string to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isMd5($md5)
|
||||
public static function isMd5($md5)
|
||||
{
|
||||
return preg_match('/^[a-f0-9A-F]{32}$/', $md5);
|
||||
}
|
||||
@@ -91,7 +91,7 @@ class ValidateCore
|
||||
* @param string $sha1 SHA1 string to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isSha1($sha1)
|
||||
public static function isSha1($sha1)
|
||||
{
|
||||
return preg_match('/^[a-fA-F0-9]{40}$/', $sha1);
|
||||
}
|
||||
@@ -102,12 +102,12 @@ class ValidateCore
|
||||
* @param float $float Float number to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isFloat($float)
|
||||
public static function isFloat($float)
|
||||
{
|
||||
return strval((float)($float)) == strval($float);
|
||||
}
|
||||
|
||||
static public function isUnsignedFloat($float)
|
||||
public static function isUnsignedFloat($float)
|
||||
{
|
||||
return strval((float)($float)) == strval($float) AND $float >= 0;
|
||||
}
|
||||
@@ -118,7 +118,7 @@ class ValidateCore
|
||||
* @param float $float Float number to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isOptFloat($float)
|
||||
public static function isOptFloat($float)
|
||||
{
|
||||
return empty($float) OR self::isFloat($float);
|
||||
}
|
||||
@@ -129,7 +129,7 @@ class ValidateCore
|
||||
* @param string $name Carrier name to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isCarrierName($name)
|
||||
public static function isCarrierName($name)
|
||||
{
|
||||
return empty($name) OR preg_match('/^[^<>;=#{}]*$/u', $name);
|
||||
}
|
||||
@@ -140,7 +140,7 @@ class ValidateCore
|
||||
* @param string $size Image size to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isImageSize($size)
|
||||
public static function isImageSize($size)
|
||||
{
|
||||
return preg_match('/^[0-9]{1,4}$/', $size);
|
||||
}
|
||||
@@ -151,7 +151,7 @@ class ValidateCore
|
||||
* @param string $name Name to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isName($name)
|
||||
public static function isName($name)
|
||||
{
|
||||
return preg_match('/^[^0-9!<>,;?=+()@#"°{}_$%:]*$/u', stripslashes($name));
|
||||
}
|
||||
@@ -162,7 +162,7 @@ class ValidateCore
|
||||
* @param string $hook Hook name to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isHookName($hook)
|
||||
public static function isHookName($hook)
|
||||
{
|
||||
return preg_match('/^[a-zA-Z0-9_-]+$/', $hook);
|
||||
}
|
||||
@@ -173,7 +173,7 @@ class ValidateCore
|
||||
* @param string $mailName Sender name to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isMailName($mailName)
|
||||
public static function isMailName($mailName)
|
||||
{
|
||||
return preg_match('/^[^<>;=#{}]*$/u', $mailName);
|
||||
}
|
||||
@@ -184,9 +184,9 @@ class ValidateCore
|
||||
* @param string $mailSubject e-mail subject to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isMailSubject($mailSubject)
|
||||
public static function isMailSubject($mailSubject)
|
||||
{
|
||||
return preg_match('/^[^<>{}]*$/u', $mailSubject);
|
||||
return preg_match('/^[^<>]*$/u', $mailSubject);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -195,7 +195,7 @@ class ValidateCore
|
||||
* @param string $moduleName Module name to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isModuleName($moduleName)
|
||||
public static function isModuleName($moduleName)
|
||||
{
|
||||
return preg_match('/^[a-zA-Z0-9_-]+$/', $moduleName);
|
||||
}
|
||||
@@ -206,7 +206,7 @@ class ValidateCore
|
||||
* @param string $tplName Template name to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isTplName($tplName)
|
||||
public static function isTplName($tplName)
|
||||
{
|
||||
return preg_match('/^[a-zA-Z0-9_-]+$/', $tplName);
|
||||
}
|
||||
@@ -217,7 +217,7 @@ class ValidateCore
|
||||
* @param string $type Image type name to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isImageTypeName($type)
|
||||
public static function isImageTypeName($type)
|
||||
{
|
||||
return preg_match('/^[a-zA-Z0-9_ -]+$/', $type);
|
||||
}
|
||||
@@ -228,7 +228,7 @@ class ValidateCore
|
||||
* @param string $price Price to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isPrice($price)
|
||||
public static function isPrice($price)
|
||||
{
|
||||
return preg_match('/^[0-9]{1,10}(\.[0-9]{1,9})?$/', $price);
|
||||
}
|
||||
@@ -239,22 +239,22 @@ class ValidateCore
|
||||
* @param string $isoCode Language code (ISO) to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isLanguageIsoCode($isoCode)
|
||||
public static function isLanguageIsoCode($isoCode)
|
||||
{
|
||||
return preg_match('/^[a-zA-Z]{2,3}$/', $isoCode);
|
||||
}
|
||||
|
||||
static public function isLanguageCode($s)
|
||||
public static function isLanguageCode($s)
|
||||
{
|
||||
return preg_match('/^[a-zA-Z]{2}(-[a-zA-Z]{2})?$/', $s);
|
||||
}
|
||||
|
||||
static public function isStateIsoCode($isoCode)
|
||||
public static function isStateIsoCode($isoCode)
|
||||
{
|
||||
return preg_match('/^[a-zA-Z0-9]{2,3}((-)[a-zA-Z0-9]{1,3})?$/', $isoCode);
|
||||
}
|
||||
|
||||
static public function isNumericIsoCode($isoCode)
|
||||
public static function isNumericIsoCode($isoCode)
|
||||
{
|
||||
return preg_match('/^[0-9]{2,3}$/', $isoCode);
|
||||
}
|
||||
@@ -265,7 +265,7 @@ class ValidateCore
|
||||
* @param string $discountName Discount coupon name to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isDiscountName($discountName)
|
||||
public static function isDiscountName($discountName)
|
||||
{
|
||||
return preg_match('/^[^!<>,;?=+()@"°{}_$%:]{3,32}$/u', $discountName);
|
||||
}
|
||||
@@ -276,7 +276,7 @@ class ValidateCore
|
||||
* @param string $name Product or category name to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isCatalogName($name)
|
||||
public static function isCatalogName($name)
|
||||
{
|
||||
return preg_match('/^[^<>;=#{}]*$/u', $name);
|
||||
}
|
||||
@@ -287,7 +287,7 @@ class ValidateCore
|
||||
* @param string $message Message to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isMessage($message)
|
||||
public static function isMessage($message)
|
||||
{
|
||||
return preg_match('/^([^<>{}]|<br \/>)*$/i', $message);
|
||||
}
|
||||
@@ -298,7 +298,7 @@ class ValidateCore
|
||||
* @param string $name Country name to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isCountryName($name)
|
||||
public static function isCountryName($name)
|
||||
{
|
||||
return preg_match('/^[a-zA-Z -]+$/', $name);
|
||||
}
|
||||
@@ -309,7 +309,7 @@ class ValidateCore
|
||||
* @param string $link Link to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isLinkRewrite($link)
|
||||
public static function isLinkRewrite($link)
|
||||
{
|
||||
return (boolean)preg_match('/^[_a-zA-Z0-9-]+$/', $link);
|
||||
}
|
||||
@@ -320,7 +320,7 @@ class ValidateCore
|
||||
* @param string $address Address to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isAddress($address)
|
||||
public static function isAddress($address)
|
||||
{
|
||||
return empty($address) OR preg_match('/^[^!<>?=+@{}_$%]*$/u', $address);
|
||||
}
|
||||
@@ -331,7 +331,7 @@ class ValidateCore
|
||||
* @param string $city City name to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isCityName($city)
|
||||
public static function isCityName($city)
|
||||
{
|
||||
return preg_match('/^[^!<>;?=+@#"°{}_$%]*$/u', $city);
|
||||
}
|
||||
@@ -342,7 +342,7 @@ class ValidateCore
|
||||
* @param string $search Query to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isValidSearch($search)
|
||||
public static function isValidSearch($search)
|
||||
{
|
||||
return preg_match('/^[^<>;=#{}]{0,64}$/u', $search);
|
||||
}
|
||||
@@ -353,7 +353,7 @@ class ValidateCore
|
||||
* @param string $name Name to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isGenericName($name)
|
||||
public static function isGenericName($name)
|
||||
{
|
||||
return empty($name) OR preg_match('/^[^<>;=#{}]*$/u', $name);
|
||||
}
|
||||
@@ -364,7 +364,7 @@ class ValidateCore
|
||||
* @param string $html HTML field to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isCleanHtml($html)
|
||||
public static function isCleanHtml($html)
|
||||
{
|
||||
$jsEvent = 'onmousedown|onmousemove|onmmouseup|onmouseover|onmouseout|onload|onunload|onfocus|onblur|onchange|onsubmit|ondblclick|onclick|onkeydown|onkeyup|onkeypress|onmouseenter|onmouseleave';
|
||||
return (!preg_match('/<[ \t\n]*script/i', $html) && !preg_match('/<?.*('.$jsEvent.')[ \t\n]*=/i', $html) && !preg_match('/.*script\:/i', $html));
|
||||
@@ -376,7 +376,7 @@ class ValidateCore
|
||||
* @param string $reference Product reference to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isReference($reference)
|
||||
public static function isReference($reference)
|
||||
{
|
||||
return preg_match('/^[^<>;={}]*$/u', $reference);
|
||||
}
|
||||
@@ -387,12 +387,12 @@ class ValidateCore
|
||||
* @param string $passwd Password to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isPasswd($passwd, $size = 5)
|
||||
public static function isPasswd($passwd, $size = 5)
|
||||
{
|
||||
return preg_match('/^[.a-zA-Z_0-9-!@#$%\^&*()]{'.(int)$size.',32}$/', $passwd);
|
||||
}
|
||||
|
||||
static public function isPasswdAdmin($passwd)
|
||||
public static function isPasswdAdmin($passwd)
|
||||
{
|
||||
return self::isPasswd($passwd, 8);
|
||||
}
|
||||
@@ -403,7 +403,7 @@ class ValidateCore
|
||||
* @param string $configName Configuration key to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isConfigName($configName)
|
||||
public static function isConfigName($configName)
|
||||
{
|
||||
return preg_match('/^[a-zA-Z_0-9-]+$/', $configName);
|
||||
}
|
||||
@@ -414,7 +414,7 @@ class ValidateCore
|
||||
* @param string $date Date to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isDateFormat($date)
|
||||
public static function isDateFormat($date)
|
||||
{
|
||||
return (bool)preg_match('/^([0-9]{4})-((0?[0-9])|(1[0-2]))-((0?[1-9])|([0-2][0-9])|(3[01]))( [0-9]{2}:[0-9]{2}:[0-9]{2})?$/', $date);
|
||||
}
|
||||
@@ -425,7 +425,7 @@ class ValidateCore
|
||||
* @param string $date Date to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isDate($date)
|
||||
public static function isDate($date)
|
||||
{
|
||||
if (!preg_match('/^([0-9]{4})-((0?[1-9])|(1[0-2]))-((0?[1-9])|([1-2][0-9])|(3[01]))( [0-9]{2}:[0-9]{2}:[0-9]{2})?$/', $date, $matches))
|
||||
return false;
|
||||
@@ -438,7 +438,7 @@ class ValidateCore
|
||||
* @param string $date birthdate to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isBirthDate($date)
|
||||
public static function isBirthDate($date)
|
||||
{
|
||||
if (empty($date) || $date == '0000-00-00')
|
||||
return true;
|
||||
@@ -456,7 +456,7 @@ class ValidateCore
|
||||
* @param boolean $bool Boolean to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isBool($bool)
|
||||
public static function isBool($bool)
|
||||
{
|
||||
return is_null($bool) OR is_bool($bool) OR preg_match('/^0|1$/', $bool);
|
||||
}
|
||||
@@ -467,7 +467,7 @@ class ValidateCore
|
||||
* @param string $phoneNumber Phone number to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isPhoneNumber($phoneNumber)
|
||||
public static function isPhoneNumber($phoneNumber)
|
||||
{
|
||||
return preg_match('/^[+0-9. ()-]*$/', $phoneNumber);
|
||||
}
|
||||
@@ -478,7 +478,7 @@ class ValidateCore
|
||||
* @param string $ean13 Barcode to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isEan13($ean13)
|
||||
public static function isEan13($ean13)
|
||||
{
|
||||
return !$ean13 OR preg_match('/^[0-9]{0,13}$/', $ean13);
|
||||
}
|
||||
@@ -489,7 +489,7 @@ class ValidateCore
|
||||
* @param string $upc Barcode to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isUpc($upc)
|
||||
public static function isUpc($upc)
|
||||
{
|
||||
return !$upc OR preg_match('/^[0-9]{0,12}$/', $upc);
|
||||
}
|
||||
@@ -500,7 +500,7 @@ class ValidateCore
|
||||
* @param string $postcode Postal code to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isPostCode($postcode)
|
||||
public static function isPostCode($postcode)
|
||||
{
|
||||
return empty($postcode) OR preg_match('/^[a-zA-Z 0-9-]+$/', $postcode);
|
||||
}
|
||||
@@ -511,7 +511,7 @@ class ValidateCore
|
||||
* @param string $zip_code zip code format to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isZipCodeFormat($zip_code)
|
||||
public static function isZipCodeFormat($zip_code)
|
||||
{
|
||||
if (!empty($zip_code))
|
||||
return preg_match('/^[NLCnlc -]+$/', $zip_code);
|
||||
@@ -525,7 +525,7 @@ class ValidateCore
|
||||
* @param string $orderWay Keyword to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isOrderWay($orderWay)
|
||||
public static function isOrderWay($orderWay)
|
||||
{
|
||||
return ($orderWay === 'ASC' | $orderWay === 'DESC' | $orderWay === 'asc' | $orderWay === 'desc');
|
||||
}
|
||||
@@ -537,7 +537,7 @@ class ValidateCore
|
||||
* @param string $orderBy Field to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isOrderBy($orderBy)
|
||||
public static function isOrderBy($orderBy)
|
||||
{
|
||||
return preg_match('/^[a-zA-Z0-9_-]+$/', $orderBy);
|
||||
}
|
||||
@@ -549,7 +549,7 @@ class ValidateCore
|
||||
* @param string $table Table/identifier to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isTableOrIdentifier($table)
|
||||
public static function isTableOrIdentifier($table)
|
||||
{
|
||||
return preg_match('/^[a-zA-Z0-9_-]+$/', $table);
|
||||
}
|
||||
@@ -561,7 +561,7 @@ class ValidateCore
|
||||
* @param string $list List to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isValuesList($list)
|
||||
public static function isValuesList($list)
|
||||
{
|
||||
return true;
|
||||
/* For history reason, we keep this line */
|
||||
@@ -574,7 +574,7 @@ class ValidateCore
|
||||
* @param string $list List to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isTagsList($list)
|
||||
public static function isTagsList($list)
|
||||
{
|
||||
return preg_match('/^[^!<>;?=+#"°{}_$%]*$/u', $list);
|
||||
}
|
||||
@@ -585,7 +585,7 @@ class ValidateCore
|
||||
* @param integer $id Integer to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isInt($value)
|
||||
public static function isInt($value)
|
||||
{
|
||||
return ((string)(int)$value === (string)$value OR $value === false);
|
||||
}
|
||||
@@ -596,7 +596,7 @@ class ValidateCore
|
||||
* @param integer $id Integer to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isUnsignedInt($value)
|
||||
public static function isUnsignedInt($value)
|
||||
{
|
||||
return (preg_match('#^[0-9]+$#', (string)$value) AND $value < 4294967296 AND $value >= 0);
|
||||
}
|
||||
@@ -608,12 +608,12 @@ class ValidateCore
|
||||
* @param integer $id Integer to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isUnsignedId($id)
|
||||
public static function isUnsignedId($id)
|
||||
{
|
||||
return self::isUnsignedInt($id); /* Because an id could be equal to zero when there is no association */
|
||||
}
|
||||
|
||||
static public function isNullOrUnsignedId($id)
|
||||
public static function isNullOrUnsignedId($id)
|
||||
{
|
||||
return is_null($id) OR self::isUnsignedId($id);
|
||||
}
|
||||
@@ -624,7 +624,7 @@ class ValidateCore
|
||||
* @param integer $object Object to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isLoadedObject($object)
|
||||
public static function isLoadedObject($object)
|
||||
{
|
||||
return is_object($object) AND $object->id;
|
||||
}
|
||||
@@ -635,7 +635,7 @@ class ValidateCore
|
||||
* @param integer $object Object to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isColor($color)
|
||||
public static function isColor($color)
|
||||
{
|
||||
return preg_match('/^(#[0-9a-fA-F]{6}|[a-zA-Z0-9-]*)$/', $color);
|
||||
}
|
||||
@@ -646,9 +646,9 @@ class ValidateCore
|
||||
* @param string $url Url to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isUrl($url)
|
||||
public static function isUrl($url)
|
||||
{
|
||||
return preg_match('/^[~:#%&_=\(\)\.\? \+\-@\/a-zA-Z0-9]+$/', $url);
|
||||
return preg_match('/^[~:#,%&_=\(\)\.\? \+\-@\/a-zA-Z0-9]+$/', $url);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -657,7 +657,7 @@ class ValidateCore
|
||||
* @param string $url Url to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isUrlOrEmpty($url)
|
||||
public static function isUrlOrEmpty($url)
|
||||
{
|
||||
return empty($url) || self::isUrl($url);
|
||||
}
|
||||
@@ -668,7 +668,7 @@ class ValidateCore
|
||||
* @param integer $object Object to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isAbsoluteUrl($url)
|
||||
public static function isAbsoluteUrl($url)
|
||||
{
|
||||
if (!empty($url))
|
||||
return preg_match('/^https?:\/\/[,:#%&_=\(\)\.\? \+\-@\/a-zA-Z0-9]+$/', $url);
|
||||
@@ -681,7 +681,7 @@ class ValidateCore
|
||||
* @param string $name Name to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isFileName($name)
|
||||
public static function isFileName($name)
|
||||
{
|
||||
return preg_match('/^[a-zA-Z0-9_.-]*$/', $name);
|
||||
}
|
||||
@@ -692,38 +692,38 @@ class ValidateCore
|
||||
* @param string $name Name to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isTabName($name)
|
||||
public static function isTabName($name)
|
||||
{
|
||||
return preg_match('/^[a-zA-Z0-9_-]*$/', $name);
|
||||
}
|
||||
|
||||
static public function isWeightUnit($unit)
|
||||
public static function isWeightUnit($unit)
|
||||
{
|
||||
return preg_match('/^[a-zA-Z]{1,3}$/', $unit);
|
||||
}
|
||||
|
||||
static public function isDistanceUnit($unit)
|
||||
public static function isDistanceUnit($unit)
|
||||
{
|
||||
return preg_match('/^[a-zA-Z]{1,2}$/', $unit);
|
||||
}
|
||||
|
||||
static public function isSubDomainName($subDomainName)
|
||||
public static function isSubDomainName($subDomainName)
|
||||
{
|
||||
return preg_match('/^[a-zA-Z0-9-_]*$/', $subDomainName);
|
||||
}
|
||||
|
||||
static public function isVoucherDescription($text)
|
||||
public static function isVoucherDescription($text)
|
||||
{
|
||||
return preg_match('/^([^<>{}]|<br \/>)*$/i', $text);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if the value is a sort direction value (DESC/ASC)
|
||||
*
|
||||
* @param char $value
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function IsSortDirection($value)
|
||||
public static function IsSortDirection($value)
|
||||
{
|
||||
return (!is_null($value) AND ($value === 'ASC' OR $value === 'DESC'));
|
||||
}
|
||||
@@ -734,7 +734,7 @@ class ValidateCore
|
||||
* @param integer $object Object to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isLabel($label)
|
||||
public static function isLabel($label)
|
||||
{
|
||||
return (preg_match('/^[^{}<>]*$/u', $label));
|
||||
}
|
||||
@@ -745,7 +745,7 @@ class ValidateCore
|
||||
* @param integer $data Data to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isPriceDisplayMethod($data)
|
||||
public static function isPriceDisplayMethod($data)
|
||||
{
|
||||
return ($data == PS_TAX_EXC OR $data == PS_TAX_INC);
|
||||
}
|
||||
@@ -754,18 +754,18 @@ class ValidateCore
|
||||
* @param string $dni to validate
|
||||
* @return bool
|
||||
*/
|
||||
static public function isDniLite($dni)
|
||||
public static function isDniLite($dni)
|
||||
{
|
||||
return empty($dni) OR (bool)preg_match('/^[0-9A-Za-z-.]{1,16}$/U', $dni);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if $data is a PrestaShop cookie object
|
||||
*
|
||||
* @param mixed $data to validate
|
||||
* @return bool
|
||||
*/
|
||||
static public function isCookie($data)
|
||||
* Check if $data is a PrestaShop cookie object
|
||||
*
|
||||
* @param mixed $data to validate
|
||||
* @return bool
|
||||
*/
|
||||
public static function isCookie($data)
|
||||
{
|
||||
return (is_object($data) AND get_class($data) == 'Cookie');
|
||||
}
|
||||
@@ -776,7 +776,7 @@ class ValidateCore
|
||||
* @param string $data Data to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isString($data)
|
||||
public static function isString($data)
|
||||
{
|
||||
return is_string($data);
|
||||
}
|
||||
@@ -787,7 +787,7 @@ class ValidateCore
|
||||
* @param string $data Data to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isReductionType($data)
|
||||
public static function isReductionType($data)
|
||||
{
|
||||
return ($data === 'amount' || $data === 'percentage');
|
||||
}
|
||||
@@ -798,7 +798,7 @@ class ValidateCore
|
||||
* @param string $ids
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isBool_Id($ids)
|
||||
public static function isBool_Id($ids)
|
||||
{
|
||||
return (bool)preg_match('#^[01]_[0-9]+$#', $ids);
|
||||
}
|
||||
@@ -809,7 +809,7 @@ class ValidateCore
|
||||
* @param string $data Localization pack to check
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isLocalizationPackSelection($data)
|
||||
public static function isLocalizationPackSelection($data)
|
||||
{
|
||||
return ($data === 'states' OR $data === 'taxes' OR $data === 'currencies' OR $data === 'languages' OR $data === 'units');
|
||||
}
|
||||
@@ -820,7 +820,7 @@ class ValidateCore
|
||||
* @param string $data Serialized data to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isSerializedArray($data)
|
||||
public static function isSerializedArray($data)
|
||||
{
|
||||
return ($data == NULL) OR (bool)(is_string($data) AND preg_match('/^a:[0-9]+:{.*;}$/s', $data));
|
||||
}
|
||||
@@ -831,7 +831,7 @@ class ValidateCore
|
||||
* @param string $data Coordinate to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isCoordinate($data)
|
||||
public static function isCoordinate($data)
|
||||
{
|
||||
return ($data == NULL) OR (bool)(preg_match('/^\-?[0-9]{1,6}\.[0-9]{1,6}$/s', $data));
|
||||
}
|
||||
@@ -842,7 +842,7 @@ class ValidateCore
|
||||
* @param string $iso_code
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isLangIsoCode($iso_code)
|
||||
public static function isLangIsoCode($iso_code)
|
||||
{
|
||||
return (bool)(preg_match('/^[a-zA-Z]{2,3}$/s', $iso_code));
|
||||
}
|
||||
@@ -853,7 +853,7 @@ class ValidateCore
|
||||
* @param string $file_name
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
static public function isLanguageFileName($file_name)
|
||||
public static function isLanguageFileName($file_name)
|
||||
{
|
||||
return (bool)(preg_match('/^[a-zA-Z]{2,3}\.gzip$/s', $file_name));
|
||||
}
|
||||
|
||||
@@ -43,6 +43,21 @@ class WebserviceKeyCore extends ObjectModel
|
||||
protected $table = 'webservice_account';
|
||||
protected $identifier = 'id_webservice_account';
|
||||
|
||||
|
||||
public function add($autodate = true, $nullValues = false)
|
||||
{
|
||||
if (WebserviceKey::keyExists($this->key))
|
||||
return false;
|
||||
return parent::add($autodate = true, $nullValues = false);
|
||||
}
|
||||
|
||||
static public function keyExists($key)
|
||||
{
|
||||
return (!Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('SELECT `key`
|
||||
FROM '._DB_PREFIX_.'webservice_account
|
||||
WHERE `key` = \''.pSQL($key).'\'') ? false : true);
|
||||
}
|
||||
|
||||
public function getFields()
|
||||
{
|
||||
parent::validateFields();
|
||||
@@ -75,7 +90,7 @@ class WebserviceKeyCore extends ObjectModel
|
||||
return true;
|
||||
}
|
||||
|
||||
static public function getPermissionForAccount($auth_key)
|
||||
public static function getPermissionForAccount($auth_key)
|
||||
{
|
||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
||||
SELECT p.*
|
||||
@@ -90,7 +105,7 @@ class WebserviceKeyCore extends ObjectModel
|
||||
return $permissions;
|
||||
}
|
||||
|
||||
static public function isKeyActive($auth_key)
|
||||
public static function isKeyActive($auth_key)
|
||||
{
|
||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
||||
SELECT a.active
|
||||
@@ -105,7 +120,7 @@ class WebserviceKeyCore extends ObjectModel
|
||||
}
|
||||
}
|
||||
|
||||
static public function getClassFromKey($auth_key)
|
||||
public static function getClassFromKey($auth_key)
|
||||
{
|
||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
||||
SELECT a.class_name as class
|
||||
@@ -120,7 +135,7 @@ class WebserviceKeyCore extends ObjectModel
|
||||
}
|
||||
}
|
||||
|
||||
static public function setPermissionForAccount($idAccount, $permissionsToSet)
|
||||
public static function setPermissionForAccount($idAccount, $permissionsToSet)
|
||||
{
|
||||
$ok = true;
|
||||
$sql = 'DELETE FROM `'._DB_PREFIX_.'webservice_permission` WHERE `id_webservice_account` = '.(int)($idAccount);
|
||||
@@ -133,7 +148,7 @@ class WebserviceKeyCore extends ObjectModel
|
||||
$methods = array('GET', 'PUT', 'POST', 'DELETE', 'HEAD');
|
||||
foreach ($permissionsToSet as $resourceName => $resource_methods)
|
||||
if (in_array($resourceName, array_keys($resources)))
|
||||
foreach ($resource_methods as $methodName => $value)
|
||||
foreach (array_keys($resource_methods) as $methodName)
|
||||
if (in_array($methodName, $methods))
|
||||
$permissions[] = array($methodName, $resourceName);
|
||||
$account = new WebserviceKey($idAccount);
|
||||
|
||||
@@ -213,6 +213,9 @@ class WebserviceOutputBuilderCore
|
||||
case 401 :
|
||||
$this->status = $_SERVER['SERVER_PROTOCOL'].' 401 Unauthorized';
|
||||
break;
|
||||
case 403 :
|
||||
$this->status = $_SERVER['SERVER_PROTOCOL'].' 403 Forbidden';
|
||||
break;
|
||||
case 404 :
|
||||
$this->status = $_SERVER['SERVER_PROTOCOL'].' 404 Not Found';
|
||||
break;
|
||||
@@ -272,7 +275,7 @@ class WebserviceOutputBuilderCore
|
||||
if (is_null($this->wsResource))
|
||||
throw new WebserviceException ('You must set web service resource for get the resources list.', array(82, 500));
|
||||
$output = '';
|
||||
$more_attr = array('shop_name' => Tools::htmlentitiesUTF8(Configuration::get('PS_SHOP_NAME')));
|
||||
$more_attr = array('shop_name' => Configuration::get('PS_SHOP_NAME'));
|
||||
$output .= $this->objectRender->renderNodeHeader('api', array(), $more_attr);
|
||||
foreach ($this->wsResource as $resourceName => $resource)
|
||||
{
|
||||
@@ -573,7 +576,7 @@ class WebserviceOutputBuilderCore
|
||||
if (isset($this->wsResource[$assoc_name]['class']) && class_exists($this->wsResource[$assoc_name]['class'], true))
|
||||
$class_name = $this->wsResource[$assoc_name]['class'];
|
||||
$output_details = '';
|
||||
foreach ($objects_assoc as $key => $object_assoc)
|
||||
foreach ($objects_assoc as $object_assoc)
|
||||
{
|
||||
if ($depth == 0 || $class_name === null)
|
||||
{
|
||||
@@ -586,7 +589,7 @@ class WebserviceOutputBuilderCore
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach ($object_assoc as $key_id => $id)
|
||||
foreach ($object_assoc as $id)
|
||||
{
|
||||
if ($class_name !== null)
|
||||
{
|
||||
|
||||
@@ -297,7 +297,7 @@ class WebserviceRequestCore
|
||||
*/
|
||||
public function specificPriceForProduct($entity_object, $parameters)
|
||||
{
|
||||
foreach($parameters as $name => $value)
|
||||
foreach(array_keys($parameters) as $name)
|
||||
{
|
||||
$parameters[$name]['object_id'] = $entity_object->id;
|
||||
}
|
||||
@@ -323,7 +323,6 @@ class WebserviceRequestCore
|
||||
$use_reduc = (isset($value['use_reduction']) ? $value['use_reduction'] : true);
|
||||
$use_ecotax = (isset($value['use_ecotax']) ? $value['use_ecotax'] : Configuration::get('PS_USE_ECOTAX'));
|
||||
$specific_price_output = null;
|
||||
$county = (isset($value['county']) ? $value['county'] : 0);
|
||||
$return_value = Product::priceCalculation(null, $value['object_id'], $id_product_attribute, $id_country, $id_state, $id_county, $id_currency, $id_group, $quantity,
|
||||
$use_tax, $decimals, $only_reduc, $use_reduc, $use_ecotax, $specific_price_output, null);
|
||||
$arr_return[$name] = array('sqlId'=>strtolower($name), 'value'=>$return_value);
|
||||
@@ -340,7 +339,7 @@ class WebserviceRequestCore
|
||||
*/
|
||||
public function specificPriceForCombination($entity_object, $parameters)
|
||||
{
|
||||
foreach($parameters as $name => $value)
|
||||
foreach(array_keys($parameters) as $name)
|
||||
{
|
||||
$parameters[$name]['object_id'] = $entity_object->id_product;
|
||||
$parameters[$name]['product_attribute'] = $entity_object->id;
|
||||
@@ -818,7 +817,6 @@ class WebserviceRequestCore
|
||||
protected function setObjects()
|
||||
{
|
||||
$objects = array();
|
||||
$count = 0;
|
||||
$arr_avoid_id = array();
|
||||
$ids = array();
|
||||
if (isset($this->urlFragments['id']))
|
||||
@@ -856,7 +854,6 @@ class WebserviceRequestCore
|
||||
|
||||
protected function parseDisplayFields($str)
|
||||
{
|
||||
$last = 0;
|
||||
$bracket_level = 0;
|
||||
$part = array();
|
||||
$tmp = '';
|
||||
@@ -877,7 +874,7 @@ class WebserviceRequestCore
|
||||
if ($tmp != '')
|
||||
$part[] = $tmp;
|
||||
$fields = array();
|
||||
foreach ($part as $key => $str)
|
||||
foreach ($part as $str)
|
||||
{
|
||||
$field_name = trim(substr($str, 0, (strpos($str, '[') === false ? strlen($str) : strpos($str, '['))));
|
||||
if (!isset($fields[$field_name])) $fields[$field_name] = null;
|
||||
@@ -962,6 +959,23 @@ class WebserviceRequestCore
|
||||
else
|
||||
$i18n_available_filters[] = $fieldName;
|
||||
|
||||
// Date feature : date=1
|
||||
if (!empty($this->urlFragments['date']) && $this->urlFragments['date'])
|
||||
{
|
||||
if (!in_array('date_add', $available_filters))
|
||||
$available_filters[] = 'date_add';
|
||||
if (!in_array('date_upd', $available_filters))
|
||||
$available_filters[] = 'date_upd';
|
||||
if (!array_key_exists('date_add', $this->resourceConfiguration['fields']))
|
||||
$this->resourceConfiguration['fields']['date_add'] = array('sqlId' => 'date_add');
|
||||
if (!array_key_exists('date_upd', $this->resourceConfiguration['fields']))
|
||||
$this->resourceConfiguration['fields']['date_upd'] = array('sqlId' => 'date_upd');
|
||||
}
|
||||
else
|
||||
foreach ($available_filters as $key => $value)
|
||||
if ($value == 'date_add' || $value == 'date_upd')
|
||||
unset($available_filters[$key]);
|
||||
|
||||
//construct SQL filter
|
||||
$sql_filter = '';
|
||||
$sql_join = '';
|
||||
@@ -1253,7 +1267,6 @@ class WebserviceRequestCore
|
||||
protected function executeEntityDelete()
|
||||
{
|
||||
$objects = array();
|
||||
$count = 0;
|
||||
$arr_avoid_id = array();
|
||||
$ids = array();
|
||||
if (isset($this->urlFragments['id']))
|
||||
@@ -1356,7 +1369,7 @@ class WebserviceRequestCore
|
||||
$this->setError(400, 'id is duplicate in request', 89);
|
||||
return false;
|
||||
}
|
||||
if ($xmlEntities->count() != count($ids))
|
||||
if (count($xmlEntities) != count($ids))
|
||||
{
|
||||
$this->setError(400, 'id is required when modifying a resource', 90);
|
||||
return false;
|
||||
|
||||
@@ -296,7 +296,7 @@ class WebserviceSpecificManagementImagesCore implements WebserviceSpecificManage
|
||||
// images root node management : many image for one entity (product)
|
||||
case '':
|
||||
$this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('image_types', array());
|
||||
foreach ($this->imageTypes as $imageTypeName => $imageType)
|
||||
foreach (array_keys($this->imageTypes) as $imageTypeName)
|
||||
{
|
||||
$more_attr = array(
|
||||
'xlink_resource' => $this->wsObject->wsUrl.$this->wsObject->urlSegment[0].'/'.$imageTypeName,
|
||||
@@ -369,7 +369,7 @@ class WebserviceSpecificManagementImagesCore implements WebserviceSpecificManage
|
||||
// List the general image types
|
||||
case '':
|
||||
$this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('general_image_types', array());
|
||||
foreach ($this->imageTypes['general'] as $generalImageTypeName => $generalImageType)
|
||||
foreach (array_keys($this->imageTypes['general']) as $generalImageTypeName)
|
||||
{
|
||||
$more_attr = array(
|
||||
'xlink_resource' => $this->wsObject->wsUrl.$this->wsObject->urlSegment[0].'/'.$this->wsObject->urlSegment[1].'/'.$generalImageTypeName,
|
||||
@@ -479,13 +479,12 @@ class WebserviceSpecificManagementImagesCore implements WebserviceSpecificManage
|
||||
$ids[] = $image['id_product'];
|
||||
$ids = array_unique($ids, SORT_NUMERIC);
|
||||
asort($ids);
|
||||
foreach ($ids as $key => $id)
|
||||
foreach ($ids as $id)
|
||||
$this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('image', array(), array('id' => $id, 'xlink_resource'=>$this->wsObject->wsUrl.'images/'.$this->imageType.'/'.$id), false);
|
||||
}
|
||||
else
|
||||
{
|
||||
$nodes = scandir($directory);
|
||||
$lastId = 0;
|
||||
foreach ($nodes as $node)
|
||||
{
|
||||
// avoid too much preg_match...
|
||||
@@ -525,7 +524,6 @@ class WebserviceSpecificManagementImagesCore implements WebserviceSpecificManage
|
||||
|
||||
// New Behavior
|
||||
$languages = Language::getLanguages();
|
||||
$images = array();
|
||||
foreach ($languages as $language)
|
||||
foreach (Image::getImages($language['id_lang'], $object_id) as $image)
|
||||
$available_image_ids[] = $image['id_image'];
|
||||
@@ -987,7 +985,7 @@ class WebserviceSpecificManagementImagesCore implements WebserviceSpecificManage
|
||||
else
|
||||
{
|
||||
$imagesTypes = ImageType::getImagesTypes('products');
|
||||
foreach ($imagesTypes AS $k => $imageType)
|
||||
foreach ($imagesTypes AS $imageType)
|
||||
if (!imageResize($tmpName, _PS_PROD_IMG_DIR_.$image->getExistingImgPath().'-'.stripslashes($imageType['name']).'.'.$image->image_format, $imageType['width'], $imageType['height'], $image->image_format))
|
||||
$this->_errors[] = Tools::displayError('An error occurred while copying image:').' '.stripslashes($imageType['name']);
|
||||
}
|
||||
|
||||
+2
-2
@@ -58,7 +58,7 @@ class ZoneCore extends ObjectModel
|
||||
*
|
||||
* @return array Zones
|
||||
*/
|
||||
static public function getZones($active = false)
|
||||
public static function getZones($active = false)
|
||||
{
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
||||
SELECT *
|
||||
@@ -72,7 +72,7 @@ class ZoneCore extends ObjectModel
|
||||
*
|
||||
* @return integer id_zone
|
||||
*/
|
||||
static public function getIdByName($name)
|
||||
public static function getIdByName($name)
|
||||
{
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
||||
SELECT `id_zone`
|
||||
|
||||
Reference in New Issue
Block a user