// Merge -> revision 8624

This commit is contained in:
rMalie
2011-09-16 15:02:29 +00:00
parent 72e890b65c
commit c0224d4958
7 changed files with 281 additions and 87 deletions
+44 -45
View File
@@ -52,14 +52,14 @@ class SpecificPriceCore extends ObjectModel
public function getFields() public function getFields()
{ {
$this->validateFields(); $this->validateFields();
$fields['id_product'] = (int)($this->id_product); $fields['id_product'] = (int)$this->id_product;
$fields['id_shop'] = (int)($this->id_shop); $fields['id_shop'] = (int)$this->id_shop;
$fields['id_currency'] = (int)($this->id_currency); $fields['id_currency'] = (int)$this->id_currency;
$fields['id_country'] = (int)($this->id_country); $fields['id_country'] = (int)$this->id_country;
$fields['id_group'] = (int)($this->id_group); $fields['id_group'] = (int)$this->id_group;
$fields['price'] = (float)($this->price); $fields['price'] = (float)$this->price;
$fields['from_quantity'] = (int)($this->from_quantity); $fields['from_quantity'] = (int)$this->from_quantity;
$fields['reduction'] = (float)($this->reduction); $fields['reduction'] = (float)$this->reduction;
$fields['reduction_type'] = pSQL($this->reduction_type); $fields['reduction_type'] = pSQL($this->reduction_type);
$fields['from'] = pSQL($this->from); $fields['from'] = pSQL($this->from);
$fields['to'] = pSQL($this->to); $fields['to'] = pSQL($this->to);
@@ -68,17 +68,16 @@ class SpecificPriceCore extends ObjectModel
public static function getByProductId($id_product) public static function getByProductId($id_product)
{ {
return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' return Db::getInstance()->ExecuteS('
SELECT * SELECT * FROM `'._DB_PREFIX_.'specific_price` WHERE `id_product` = '.(int)$id_product
FROM `'._DB_PREFIX_.'specific_price` );
WHERE `id_product` = '.(int)$id_product);
} }
public static function getIdsByProductId($id_product) public static function getIdsByProductId($id_product)
{ {
return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
SELECT `id_specific_price` SELECT `id_specific_price`
FROM `'._DB_PREFIX_.'specific_price` FROM `'._DB_PREFIX_.'specific_price`
WHERE `id_product` = '.(int)$id_product); WHERE `id_product` = '.(int)$id_product);
} }
@@ -91,7 +90,7 @@ class SpecificPriceCore extends ObjectModel
$select .= ' IF (\''.$now.'\' >= `from` AND \''.$now.'\' <= `to`, '.pow(2, 0).', 0) + '; $select .= ' IF (\''.$now.'\' >= `from` AND \''.$now.'\' <= `to`, '.pow(2, 0).', 0) + ';
$priority = SpecificPrice::getPriority($id_product); $priority = SpecificPrice::getPriority($id_product);
foreach (array_reverse($priority) AS $k => $field) foreach (array_reverse($priority) as $k => $field)
$select .= ' IF (`'.$field.'` = '.(int)(${$field}).', '.pow(2, $k + 1).', 0) + '; $select .= ' IF (`'.$field.'` = '.(int)(${$field}).', '.pow(2, $k + 1).', 0) + ';
return rtrim($select, ' +').') AS `score`'; return rtrim($select, ' +').') AS `score`';
@@ -121,7 +120,7 @@ class SpecificPriceCore extends ObjectModel
{ {
if (!self::isFeatureActive()) if (!self::isFeatureActive())
return array(); return array();
/* /*
** 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. ** 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.
** The price must not change between the top and the bottom of the page ** The price must not change between the top and the bottom of the page
@@ -146,7 +145,7 @@ class SpecificPriceCore extends ObjectModel
AND AND
(`to` = \'0000-00-00 00:00:00\' OR \''.$now.'\' <= `to`) (`to` = \'0000-00-00 00:00:00\' OR \''.$now.'\' <= `to`)
) )
ORDER BY `from_quantity` DESC, `score` DESC, `from_quantity` DESC'); ORDER BY `from_quantity` DESC, `score` DESC');
} }
return self::$_specificPriceCache[$key]; return self::$_specificPriceCache[$key];
} }
@@ -186,17 +185,17 @@ class SpecificPriceCore extends ObjectModel
{ {
if (!self::isFeatureActive()) if (!self::isFeatureActive())
return array(); return array();
$now = date('Y-m-d H:i:s'); $now = date('Y-m-d H:i:s');
$res = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' $res = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
SELECT *, SELECT *,
'.self::_getScoreQuery($id_product, $id_shop, $id_currency, $id_country, $id_group).' '.self::_getScoreQuery($id_product, $id_shop, $id_currency, $id_country, $id_group).'
FROM `'._DB_PREFIX_.'specific_price` FROM `'._DB_PREFIX_.'specific_price`
WHERE `id_product` IN(0, '.(int)($id_product).') AND WHERE `id_product` IN(0, '.(int)$id_product.') AND
`id_shop` IN(0, '.(int)($id_shop).') AND `id_shop` IN(0, '.(int)$id_shop.') AND
`id_currency` IN(0, '.(int)($id_currency).') AND `id_currency` IN(0, '.(int)$id_currency.') AND
`id_country` IN(0, '.(int)($id_country).') AND `id_country` IN(0, '.(int)$id_country.') AND
`id_group` IN(0, '.(int)($id_group).') `id_group` IN(0, '.(int)$id_group.')
AND AND
( (
(`from` = \'0000-00-00 00:00:00\' OR \''.$now.'\' >= `from`) (`from` = \'0000-00-00 00:00:00\' OR \''.$now.'\' >= `from`)
@@ -207,16 +206,16 @@ class SpecificPriceCore extends ObjectModel
'); ');
$targeted_prices = array(); $targeted_prices = array();
$last_quantity = NULL; $last_quantity = null;
foreach($res as $specific_price) foreach($res as $specific_price)
{ {
if (!isset($last_quantity)) if (!isset($last_quantity))
$last_quantity = $specific_price['from_quantity']; $last_quantity = $specific_price['from_quantity'];
else if ($last_quantity == $specific_price['from_quantity']) else if ($last_quantity == $specific_price['from_quantity'])
break; break;
$last_quantity = $specific_price['from_quantity']; $last_quantity = $specific_price['from_quantity'];
if ($specific_price['from_quantity'] > 1) if ($specific_price['from_quantity'] > 1)
$targeted_prices[] = $specific_price; $targeted_prices[] = $specific_price;
} }
@@ -228,25 +227,25 @@ class SpecificPriceCore extends ObjectModel
{ {
if (!self::isFeatureActive()) if (!self::isFeatureActive())
return array(); return array();
$now = date('Y-m-d H:i:s'); $now = date('Y-m-d H:i:s');
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' return Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
SELECT *, SELECT *,
'.self::_getScoreQuery($id_product, $id_shop, $id_currency, $id_country, $id_group).' '.self::_getScoreQuery($id_product, $id_shop, $id_currency, $id_country, $id_group).'
FROM `'._DB_PREFIX_.'specific_price` FROM `'._DB_PREFIX_.'specific_price`
WHERE `id_product` IN(0, '.(int)($id_product).') AND WHERE `id_product` IN(0, '.(int)$id_product.') AND
`id_shop` IN(0, '.(int)($id_shop).') AND `id_shop` IN(0, '.(int)$id_shop.') AND
`id_currency` IN(0, '.(int)($id_currency).') AND `id_currency` IN(0, '.(int)$id_currency.') AND
`id_country` IN(0, '.(int)($id_country).') AND `id_country` IN(0, '.(int)$id_country.') AND
`id_group` IN(0, '.(int)($id_group).') AND `id_group` IN(0, '.(int)$id_group.') AND
`from_quantity` >= '.(int)($quantity).' `from_quantity` >= '.(int)$quantity.'
AND AND
( (
(`from` = \'0000-00-00 00:00:00\' OR \''.$now.'\' >= `from`) (`from` = \'0000-00-00 00:00:00\' OR \''.$now.'\' >= `from`)
AND AND
(`to` = \'0000-00-00 00:00:00\' OR \''.$now.'\' <= `to`) (`to` = \'0000-00-00 00:00:00\' OR \''.$now.'\' <= `to`)
) )
ORDER BY `score` DESC, `from_quantity` DESC ORDER BY `from_quantity` DESC, `score` DESC
'); ');
} }
@@ -254,14 +253,14 @@ class SpecificPriceCore extends ObjectModel
{ {
if (!self::isFeatureActive()) if (!self::isFeatureActive())
return array(); return array();
$resource = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' $resource = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
SELECT `id_product` SELECT `id_product`
FROM `'._DB_PREFIX_.'specific_price` FROM `'._DB_PREFIX_.'specific_price`
WHERE `id_shop` IN(0, '.(int)($id_shop).') AND WHERE `id_shop` IN(0, '.(int)$id_shop.') AND
`id_currency` IN(0, '.(int)($id_currency).') AND `id_currency` IN(0, '.(int)$id_currency.') AND
`id_country` IN(0, '.(int)($id_country).') AND `id_country` IN(0, '.(int)$id_country.') AND
`id_group` IN(0, '.(int)($id_group).') AND `id_group` IN(0, '.(int)$id_group.') AND
`from_quantity` = 1 AND `from_quantity` = 1 AND
( (
(`from` = \'0000-00-00 00:00:00\' OR \''.$beginning.'\' >= `from`) (`from` = \'0000-00-00 00:00:00\' OR \''.$beginning.'\' >= `from`)
@@ -273,22 +272,22 @@ class SpecificPriceCore extends ObjectModel
', false); ', false);
$ids_product = array(); $ids_product = array();
while ($row = DB::getInstance()->nextRow($resource)) while ($row = DB::getInstance()->nextRow($resource))
$ids_product[] = (int)($row['id_product']); $ids_product[] = (int)$row['id_product'];
return $ids_product; return $ids_product;
} }
public static 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)); return Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'specific_price` WHERE `id_product` = '.(int)$id_product);
} }
public function duplicate($id_product = false) public function duplicate($id_product = false)
{ {
if ($id_product) if ($id_product)
$this->id_product = (int)($id_product); $this->id_product = (int)$id_product;
return $this->add(); return $this->add();
} }
/** /**
* This method is allow to know if a feature is used or active * This method is allow to know if a feature is used or active
* @since 1.5.0.1 * @since 1.5.0.1
@@ -298,10 +297,10 @@ class SpecificPriceCore extends ObjectModel
{ {
if (self::$feature_active === null) if (self::$feature_active === null)
self::$feature_active = (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' self::$feature_active = (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
SELECT COUNT(*) SELECT COUNT(*)
FROM `'._DB_PREFIX_.'specific_price` FROM `'._DB_PREFIX_.'specific_price`
'); ');
return self::$feature_active; return self::$feature_active;
} }
} }
+63
View File
@@ -28,6 +28,7 @@
class UpgraderCore{ class UpgraderCore{
const DEFAULT_CHECK_VERSION_DELAY_HOURS = 24; const DEFAULT_CHECK_VERSION_DELAY_HOURS = 24;
public $rss_version_link = 'http://www.prestashop.com/xml/version.xml'; public $rss_version_link = 'http://www.prestashop.com/xml/version.xml';
public $rss_md5file_link_dir = 'http://www.prestashop.com/xml/md5/';
/** /**
* link contains hte url where to download the file * link contains hte url where to download the file
* *
@@ -35,6 +36,9 @@ class UpgraderCore{
*/ */
private $needUpgrade = false; private $needUpgrade = false;
private $noRefresh = false; private $noRefresh = false;
private $changedFiles = array();
private $missingFiles = array();
private $versionIsModified = false;
public $version_name; public $version_name;
public $version_num; public $version_num;
@@ -154,4 +158,63 @@ class UpgraderCore{
return false; return false;
} }
public function getChangedFilesList()
{
$checksum = simplexml_load_file($this->rss_md5file_link_dir._PS_VERSION_.'.xml');
if ($checksum === false)
throw new Exception('No checksum xml file for your Prestashop version');
$this->browseXmlAndCompare($checksum);
return $this->changedFiles;
}
protected function addChangedFile($path)
{
$this->versionIsModified = true;
$this->changedFiles[] = $path;
}
protected function addMissingFile($path)
{
$this->versionIsModified = true;
$this->missingFiles[] = $path;
}
protected function browseXmlAndCompare($node, &$currentPath = array(), $level = 0)
{
foreach ($node as $key => $child)
{
if (is_object($child) && $child->getName() != 'md5file')
{
$level += 1;
$currentPath[$level] = $child->getName();
$this->browseXmlAndCompare($child, $currentPath, $level);
$level -= 1;
}
else
{
$path = '';
for ($i=1;$i<=$level;$i++)
$path .= $currentPath[$i].'/';
$path .= (string)$child->attributes()->name;
$path = str_replace('ps_root_dir',_PS_ROOT_DIR_,$path);
if(!file_exists($path))
$this->addMissingFile($path);
else if (!$this->compareChecksum($path, (string)$child->attributes()->sum))
$this->addChangedFile($path);
}
}
}
protected function compareChecksum($path, $originalSum)
{
if (md5_file($path) == $originalSum)
return true;
return false;
}
public function isAuthenticPrestashopVersion()
{
return !$this->versionIsModified;
}
} }
+2 -1
View File
@@ -26,7 +26,8 @@
*/ */
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date dans le passé header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date dans le passé
include_once(INSTALL_PATH.'/../classes/ConfigurationTest.php'); if (!class_exists('ConfigurationTest',false))
require_once(INSTALL_PATH.'/../classes/ConfigurationTest.php');
// Functions list to test with 'test_system' // Functions list to test with 'test_system'
$funcs = array('fopen', 'fclose', 'fread', 'fwrite', 'rename', 'file_exists', 'unlink', 'rmdir', 'mkdir', 'getcwd', 'chdir', 'chmod'); $funcs = array('fopen', 'fclose', 'fread', 'fwrite', 'rename', 'file_exists', 'unlink', 'rmdir', 'mkdir', 'getcwd', 'chdir', 'chmod');
+64 -2
View File
@@ -457,7 +457,19 @@ $this->standalone = true;
$this->nextDesc = $this->l('Upgrade process done. Congratulations ! You can now reactive your shop.'); $this->nextDesc = $this->l('Upgrade process done. Congratulations ! You can now reactive your shop.');
$this->next = ''; $this->next = '';
} }
public function ajaxProcessCheckFilesVersion()
{
if ($testOrigCore = $this->upgrader->isAuthenticPrestashopVersion() !== false)
$this->nextParams['status'] = 'ok';
else
$this->nextParams['status'] = 'nok';
$changedFileList = $this->upgrader->getChangedFilesList();
// echo '<img src="'.$originalCore.'" /> '.
$this->nextParams['msg'] = ($testOrigCore?$this->l('Core files are ok'):sprintf($this->l('%s core files have been modified'), sizeof($changedFileList)));
$this->nextParams['result'] = $changedFileList;
}
public function ajaxProcessUpgradeNow() public function ajaxProcessUpgradeNow()
{ {
$this->nextDesc = $this->l('Starting upgrade ...'); $this->nextDesc = $this->l('Starting upgrade ...');
@@ -1570,7 +1582,11 @@ txtError[37] = "'.$this->l('The config/defines.inc.php file was not found. Where
$configurationDone = '../img/admin/disabled.gif'; $configurationDone = '../img/admin/disabled.gif';
echo '<b>'.$this->l('Options chosen').' : </b>'.'<img src="'.$configurationDone.'" /> '.($testConfigDone?$this->l('autoupgrade configuration ok'):$this->l('Please configure autoupgrade options')).'<br/><br/>'; echo '<b>'.$this->l('Options chosen').' : </b>'.'<img src="'.$configurationDone.'" /> '.($testConfigDone?$this->l('autoupgrade configuration ok'):$this->l('Please configure autoupgrade options')).'<br/><br/>';
echo '<a class="button" id="scrollToOptions" href="#options">'.$this->l('Modify your options').'</a>'; echo '<b>'.$this->l('PrestaShop Original version').' : </b>'.'<span id="checkPrestaShopFilesVersion">
<img id="pleaseWait" src="'.__PS_BASE_URI__.'img/loader.gif"/>
</span>';
echo '<p> <a class="button" id="scrollToOptions" href="#options">'.$this->l('Modify your options').'</a></p>';
echo '</fieldset>'; echo '</fieldset>';
echo '<br/>'; echo '<br/>';
@@ -1687,6 +1703,8 @@ echo '</script>';
.button-autoupgrade {-moz-border-bottom-colors: none;-moz-border-image: none;-moz-border-left-colors: none;-moz-border-right-colors: none;-moz-border-top-colors: none;border-color: #FFF6D3 #DFD5AF #DFD5AF #FFF6D3;border-right: 1px solid #DFD5AF;border-style: solid;border-width: 1px;color: #268CCD;font-size: medium;padding: 5px;} .button-autoupgrade {-moz-border-bottom-colors: none;-moz-border-image: none;-moz-border-left-colors: none;-moz-border-right-colors: none;-moz-border-top-colors: none;border-color: #FFF6D3 #DFD5AF #DFD5AF #FFF6D3;border-right: 1px solid #DFD5AF;border-style: solid;border-width: 1px;color: #268CCD;font-size: medium;padding: 5px;}
.processing {border:2px outset grey;margin-top:1px;overflow: auto;} .processing {border:2px outset grey;margin-top:1px;overflow: auto;}
#dbResultCheck{ padding-left:20px;} #dbResultCheck{ padding-left:20px;}
#checkPrestaShopFilesVersion{margin-bottom:20px;}
#changedList ul{list-style-type:circle}
</style>'; </style>';
$this->displayWarning($this->l('This function is experimental. It\'s highly recommended to make a backup of your files and database before starting the upgrade process.')); $this->displayWarning($this->l('This function is experimental. It\'s highly recommended to make a backup of your files and database before starting the upgrade process.'));
@@ -1882,8 +1900,8 @@ function afterUpgradeDb()
{ {
// console.info("inside afterUpgradeDb"); // console.info("inside afterUpgradeDb");
// console.log(resGlobal); // console.log(resGlobal);
} }
function afterUpgradeComplete() function afterUpgradeComplete()
{ {
$("#pleaseWait").hide(); $("#pleaseWait").hide();
@@ -2093,6 +2111,50 @@ function handleError(res)
} }
} }
'; ';
// ajax to check md5 files
$js.= '$(document).ready(function(){
$.ajax({
type:"POST",
url : "'.($this->standalone? __PS_BASE_URI__ . trim($this->adminDir,DIRECTORY_SEPARATOR).'/autoupgrade/ajax-upgradetab.php' : str_replace('index','ajax-tab',$currentIndex)).'",
async: true,
data : {
dir:"'.trim($this->adminDir,DIRECTORY_SEPARATOR).'",
token : "'.$this->token.'",
tab : "'.get_class($this).'",
action : "checkFilesVersion",
params : {}
},
success : function(res,textStatus,jqXHR)
{
res = $.parseJSON(res);
answer = res.nextParams;
$("#checkPrestaShopFilesVersion").html("<span>"+answer.msg+"</span> ");
$("#checkPrestaShopFilesVersion").append("<a id=\"toggleChangedList\" class=\"button\" href=\"\">'.$this->l('See or hide the list').'</a><br/>");
$("#checkPrestaShopFilesVersion").append("<div id=\"changedList\" style=\"display:none \">");
$("#changedList").html("<ul>");
$(answer.result).each(function(k,v){
$("#changedList ul").append("<li>"+v+"</li>");
});
$("#toggleChangedList").bind("click",function(e){e.preventDefault();$("#changedList").toggle();});
}
,
error: function(res,textStatus,jqXHR)
{
if (textStatus == "timeout" && action == "download")
{
updateInfoStep("'.$this->l('Your server can\'t download the file. Please upload it first by ftp in your admin/autoupgrade directory').'");
}
else
{
updateInfoStep("[Server Error] Status message : " + textStatus);
}
}
})
});';
return $js; return $js;
} }
private function _cleanUp($path) private function _cleanUp($path)
+64
View File
@@ -28,6 +28,7 @@
class UpgraderCore{ class UpgraderCore{
const DEFAULT_CHECK_VERSION_DELAY_HOURS = 24; const DEFAULT_CHECK_VERSION_DELAY_HOURS = 24;
public $rss_version_link = 'http://www.prestashop.com/xml/version.xml'; public $rss_version_link = 'http://www.prestashop.com/xml/version.xml';
public $rss_md5file_link_dir = 'http://www.prestashop.com/xml/md5/';
/** /**
* link contains hte url where to download the file * link contains hte url where to download the file
* *
@@ -35,6 +36,8 @@ class UpgraderCore{
*/ */
private $needUpgrade = false; private $needUpgrade = false;
private $noRefresh = false; private $noRefresh = false;
private $changedFiles = array();
private $missingFiles = array();
public $version_name; public $version_name;
public $version_num; public $version_num;
@@ -158,4 +161,65 @@ class UpgraderCore{
return false; return false;
} }
public function getChangedFilesList()
{
$checksum = simplexml_load_file($this->rss_md5file_link_dir._PS_VERSION_.'.xml');
if ($checksum === false)
throw new Exception('No checksum xml file for your Prestashop version');
$this->browseXmlAndCompare($checksum);
return $this->changedFiles;
}
protected function addChangedFile($path)
{
$this->versionIsModified = true;
$this->changedFiles[] = $path;
//array_unique($this->changedFiles);
}
protected function addMissingFile($path)
{
$this->versionIsModified = true;
$this->missingFiles[] = $path;
//array_unique($this->missingFile);
}
protected function browseXmlAndCompare($node, &$currentPath = array(), $level = 0)
{
foreach ($node as $key => $child)
{
if (is_object($child) && $child->getName() != 'md5file')
{
$level += 1;
$currentPath[$level] = $child->getName();
$this->browseXmlAndCompare($child, $currentPath, $level);
$level -= 1;
}
else
{
$path = '';
for ($i=1;$i<=$level;$i++)
$path .= $currentPath[$i].'/';
$path .= (string)$child->attributes()->name;
$path = str_replace('ps_root_dir',_PS_ROOT_DIR_,$path);
if(!file_exists($path))
$this->addMissingFile($path);
else if (!$this->compareChecksum($path, (string)$child->attributes()->sum))
$this->addChangedFile($path);
}
}
}
protected function compareChecksum($path, $originalSum)
{
if (md5_file($path) == $originalSum)
return true;
return false;
}
public function isAuthenticPrestashopVersion()
{
return !$this->versionIsModified;
}
} }
+1
View File
@@ -0,0 +1 @@
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}(';5(10.M)(w($){$.N({11:w(j,k){5(!j)t{};w B(d,e){5(!d)t y;6 f=\'\',2=y,E=y;6 g=d.x,12=l(d.O||d.P);6 h=d.v||d.F||\'\';5(d.G){5(d.G.7>0){$.Q(d.G,w(n,a){6 b=a.x,u=l(a.O||a.P);6 c=a.v||a.F||\'\';5(b==8){t}z 5(b==3||b==4||!u){5(c.13(/^\\s+$/)){t};f+=c.H(/^\\s+/,\'\').H(/\\s+$/,\'\')}z{2=2||{};5(2[u]){5(!2[u].7)2[u]=p(2[u]);2[u][2[u].7]=B(a,R);2[u].7=2[u].7}z{2[u]=B(a)}}})}};5(d.I){5(d.I.7>0){E={};2=2||{};$.Q(d.I,w(a,b){6 c=l(b.14),C=b.15;E[c]=C;5(2[c]){5(!2[c].7)2[c]=p(2[c]);2[c][2[c].7]=C;2[c].7=2[c].7}z{2[c]=C}})}};5(2){2=$.N((f!=\'\'?A J(f):{}),2||{});f=(2.v)?(D(2.v)==\'16\'?2.v:[2.v||\'\']).17([f]):f;5(f)2.v=f;f=\'\'};6 i=2||f;5(k){5(f)i={};f=i.v||f||\'\';5(f)i.v=f;5(!e)i=p(i)};t i};6 l=w(s){t J(s||\'\').H(/-/g,"18")};6 m=w(s){t(D s=="19")||J((s&&D s=="K")?s:\'\').1a(/^((-)?([0-9]*)((\\.{0,1})([0-9]+))?$)/)};6 p=w(o){5(!o.7)o=[o];o.7=o.7;t o};5(D j==\'K\')j=$.S(j);5(!j.x)t;5(j.x==3||j.x==4)t j.F;6 q=(j.x==9)?j.1b:j;6 r=B(q,R);j=y;q=y;t r},S:w(a){6 b;T{6 c=($.U.V)?A 1c("1d.1e"):A 1f();c.1g=W}X(e){Y A L("Z 1h 1i 1j 1k 1l")};T{5($.U.V)b=(c.1m(a))?c:W;z b=c.1n(a,"v/1o")}X(e){Y A L("L 1p Z K")};t b}})})(M);',62,88,'||obj|||if|var|length||||||||||||||||||||||return|cnn|text|function|nodeType|null|else|new|parseXML|atv|typeof|att|nodeValue|childNodes|replace|attributes|String|string|Error|jQuery|extend|localName|nodeName|each|true|text2xml|try|browser|msie|false|catch|throw|XML|window|xml2json|nn|match|name|value|object|concat|_|number|test|documentElement|ActiveXObject|Microsoft|XMLDOM|DOMParser|async|Parser|could|not|be|instantiated|loadXML|parseFromString|xml|parsing'.split('|'),0,{}))
+43 -39
View File
@@ -653,14 +653,17 @@ class BlockLayered extends Module
foreach ($filterBlock['title_values'] as $key => $val) foreach ($filterBlock['title_values'] as $key => $val)
$title .= $key.' '.implode('/', $val).' – '; $title .= $key.' '.implode('/', $val).' – ';
$title = rtrim($title, ' – '); $title = rtrim($title, ' – ');
$metaComplement = ucfirst(strtolower($title)); $metaComplement = $title;
$metaKeyWordsComplement = str_replace(' – ', ', ', strtolower($title)); $metaKeyWordsComplement = substr(str_replace(' – ', ', ', strtolower($title)), 1000);
if (!empty($metaComplement)) if (!empty($metaComplement))
{ {
$smarty->assign('meta_title', str_replace(' - '.Configuration::get('PS_SHOP_NAME'), ' – '.$metaComplement.' - '.Configuration::get('PS_SHOP_NAME'), $categoryMetas['meta_title'])); $smarty->assign('meta_title', ucfirst(strtolower(str_replace(' - '.Configuration::get('PS_SHOP_NAME'), ' – '.$metaComplement.' - '.Configuration::get('PS_SHOP_NAME'), $categoryMetas['meta_title']))));
$smarty->assign('meta_description', rtrim($categoryTitle.' – '.$metaComplement.' – '.$categoryMetas['meta_description'], ' – ')); $smarty->assign('meta_description', rtrim($categoryTitle.' – '.$metaComplement.' – '.$categoryMetas['meta_description'], ' – '));
} }
else
$smarty->assign('meta_title', ucfirst(strtolower($categoryMetas['meta_title'])));
if (!empty($metaKeyWordsComplement)) if (!empty($metaKeyWordsComplement))
$smarty->assign('meta_keywords', rtrim($categoryTitle.', '.$metaKeyWordsComplement.', '.$categoryMetas['meta_keywords'], ', ')); $smarty->assign('meta_keywords', rtrim($categoryTitle.', '.$metaKeyWordsComplement.', '.$categoryMetas['meta_keywords'], ', '));
@@ -738,13 +741,13 @@ class BlockLayered extends Module
{ {
/* Clean categoryBox before use */ /* Clean categoryBox before use */
if (isset($_POST['categoryBox']) AND is_array($_POST['categoryBox'])) if (isset($_POST['categoryBox']) AND is_array($_POST['categoryBox']))
foreach ($_POST['categoryBox'] AS &$value) foreach ($_POST['categoryBox'] AS &$categoryBoxTmp)
$value = (int)$value; $categoryBoxTmp = (int)$categoryBoxTmp;
Db::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'layered_category WHERE id_category IN ('.implode(',', $_POST['categoryBox']).')'); Db::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'layered_category WHERE id_category IN ('.implode(',', $_POST['categoryBox']).')');
$filterValues = array(); $filterValues = array();
foreach (Tools::getValue('categoryBox') AS $idc) foreach ($_POST['categoryBox'] AS $idc)
$filterValues['categories'][] = (int)$idc; $filterValues['categories'][] = (int)$idc;
$sqlToInsert = 'INSERT INTO '._DB_PREFIX_.'layered_category (id_category, id_value, type, position) VALUES '; $sqlToInsert = 'INSERT INTO '._DB_PREFIX_.'layered_category (id_category, id_value, type, position) VALUES ';
@@ -1389,13 +1392,15 @@ class BlockLayered extends Module
if ($id_parent == 1) if ($id_parent == 1)
return false; return false;
$queryFilters = ' AND p.active = 1'; $queryFiltersWhere = ' AND p.active = 1';
$queryFiltersFrom = '';
$parent = new Category((int)$id_parent); $parent = new Category((int)$id_parent);
if (!sizeof($selectedFilters['category'])) if (!sizeof($selectedFilters['category']))
$queryFilters .= ' AND p.id_product IN (SELECT id_product FROM '._DB_PREFIX_.'category_product cp $queryFiltersFrom .= ' INNER JOIN '._DB_PREFIX_.'category_product cp
LEFT JOIN '._DB_PREFIX_.'category c ON (c.id_category = cp.id_category) ON p.id_product = cp.id_product
WHERE 1 AND c.nleft >= '.(int)$parent->nleft.' AND c.nright <= '.(int)$parent->nright.')'; INNER JOIN '._DB_PREFIX_.'category c ON (c.id_category = cp.id_category
AND c.nleft >= '.(int)$parent->nleft.' AND c.nright <= '.(int)$parent->nright.')';
foreach ($selectedFilters AS $key => $filterValues) foreach ($selectedFilters AS $key => $filterValues)
{ {
@@ -1415,12 +1420,12 @@ class BlockLayered extends Module
if(!isset($subQueries[$filterValueArray[0]])) if(!isset($subQueries[$filterValueArray[0]]))
$subQueries[$filterValueArray[0]] = array(); $subQueries[$filterValueArray[0]] = array();
$subQueries[$filterValueArray[0]][] = 'fp.`id_feature_value` = '.(int)$filterValueArray[1]; $subQueries[$filterValueArray[0]][] = 'fp.`id_feature_value` = '.(int)$filterValueArray[1];
//$queryFilters .= 'pac.`id_attribute` = '.(int)$filterValue.' OR '; //$queryFiltersWhere .= 'pac.`id_attribute` = '.(int)$filterValue.' OR ';
} }
foreach($subQueries as $subQuery) foreach($subQueries as $subQuery)
{ {
$queryFilters .= ' AND p.id_product IN (SELECT `id_product` FROM `'._DB_PREFIX_.'feature_product` fp WHERE '; $queryFiltersWhere .= ' AND p.id_product IN (SELECT `id_product` FROM `'._DB_PREFIX_.'feature_product` fp WHERE ';
$queryFilters .= implode(' OR ', $subQuery).') '; $queryFiltersWhere .= implode(' OR ', $subQuery).') ';
} }
break; break;
@@ -1434,47 +1439,47 @@ class BlockLayered extends Module
if(!isset($subQuery[$filterValueArray[0]])) if(!isset($subQuery[$filterValueArray[0]]))
$subQueries[$filterValueArray[0]] = array(); $subQueries[$filterValueArray[0]] = array();
$subQueries[$filterValueArray[0]][] = 'pac.`id_attribute` = '.(int)$filterValueArray[1]; $subQueries[$filterValueArray[0]][] = 'pac.`id_attribute` = '.(int)$filterValueArray[1];
//$queryFilters .= 'pac.`id_attribute` = '.(int)$filterValue.' OR '; //$queryFiltersWhere .= 'pac.`id_attribute` = '.(int)$filterValue.' OR ';
} }
foreach($subQueries as $subQuery) foreach($subQueries as $subQuery)
{ {
$queryFilters .= ' AND p.id_product IN (SELECT pa.`id_product` $queryFiltersWhere .= ' AND p.id_product IN (SELECT pa.`id_product`
FROM `'._DB_PREFIX_.'product_attribute_combination` pac FROM `'._DB_PREFIX_.'product_attribute_combination` pac
LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa
ON (pa.`id_product_attribute` = pac.`id_product_attribute`) WHERE '; ON (pa.`id_product_attribute` = pac.`id_product_attribute`) WHERE ';
$queryFilters .= implode(' OR ', $subQuery).') '; $queryFiltersWhere .= implode(' OR ', $subQuery).') ';
} }
break; break;
case 'category': case 'category':
$queryFilters .= ' AND p.id_product IN (SELECT id_product FROM '._DB_PREFIX_.'category_product cp WHERE '; $queryFiltersWhere .= ' AND p.id_product IN (SELECT id_product FROM '._DB_PREFIX_.'category_product cp WHERE ';
foreach ($selectedFilters['category'] AS $id_category) foreach ($selectedFilters['category'] AS $id_category)
$queryFilters .= 'cp.`id_category` = '.(int)$id_category.' OR '; $queryFiltersWhere .= 'cp.`id_category` = '.(int)$id_category.' OR ';
$queryFilters = rtrim($queryFilters, 'OR ').')'; $queryFiltersWhere = rtrim($queryFiltersWhere, 'OR ').')';
break; break;
case 'quantity': case 'quantity':
if (sizeof($selectedFilters['quantity']) == 2) if (sizeof($selectedFilters['quantity']) == 2)
break; break;
$queryFilters .= ' AND p.quantity '.(!$selectedFilters['quantity'][0] ? '=' : '>').' 0'; $queryFiltersWhere .= ' AND p.quantity '.(!$selectedFilters['quantity'][0] ? '=' : '>').' 0';
break; break;
case 'manufacturer': case 'manufacturer':
$queryFilters .= ' AND p.id_manufacturer IN ('.implode($selectedFilters['manufacturer'], ',').')'; $queryFiltersWhere .= ' AND p.id_manufacturer IN ('.implode($selectedFilters['manufacturer'], ',').')';
break; break;
case 'condition': case 'condition':
if (sizeof($selectedFilters['condition']) == 3) if (sizeof($selectedFilters['condition']) == 3)
break; break;
$queryFilters .= ' AND p.condition IN ('; $queryFiltersWhere .= ' AND p.condition IN (';
foreach ($selectedFilters['condition'] AS $cond) foreach ($selectedFilters['condition'] AS $cond)
$queryFilters .= '\''.$cond.'\','; $queryFiltersWhere .= '\''.$cond.'\',';
$queryFilters = rtrim($queryFilters, ',').')'; $queryFiltersWhere = rtrim($queryFiltersWhere, ',').')';
break; break;
case 'weight': case 'weight':
if ($selectedFilters['weight'][0] != 0 OR $selectedFilters['weight'][1] != 0) if ($selectedFilters['weight'][0] != 0 OR $selectedFilters['weight'][1] != 0)
$queryFilters .= ' AND p.`weight` BETWEEN '.(float)($selectedFilters['weight'][0] - 0.001).' AND '.(float)($selectedFilters['weight'][1] + 0.001); $queryFiltersWhere .= ' AND p.`weight` BETWEEN '.(float)($selectedFilters['weight'][0] - 0.001).' AND '.(float)($selectedFilters['weight'][1] + 0.001);
case 'price': case 'price':
if (isset($selectedFilters['price'])) if (isset($selectedFilters['price']))
@@ -1516,20 +1521,22 @@ class BlockLayered extends Module
SELECT p.`id_product` id_product SELECT p.`id_product` id_product
FROM `'._DB_PREFIX_.'product` p FROM `'._DB_PREFIX_.'product` p
'.$priceFilterQueryOut.' '.$priceFilterQueryOut.'
WHERE 1 '.$queryFilters.' GROUP BY id_product'); '.$queryFiltersFrom.'
WHERE 1 '.$queryFiltersWhere.' GROUP BY id_product', false);
$allProductsIn = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' $allProductsIn = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
SELECT p.`id_product` id_product SELECT p.`id_product` id_product
FROM `'._DB_PREFIX_.'product` p FROM `'._DB_PREFIX_.'product` p
'.$priceFilterQueryIn.' '.$priceFilterQueryIn.'
WHERE 1 '.$queryFilters.' GROUP BY id_product'); '.$queryFiltersFrom.'
WHERE 1 '.$queryFiltersWhere.' GROUP BY id_product', false);
$productIdList = array(); $productIdList = array();
foreach ($allProductsIn as $product) while ($product = DB::getInstance()->nextRow($allProductsIn))
$productIdList[] = (int)$product['id_product']; $productIdList[] = (int)$product['id_product'];
foreach ($allProductsOut as $product) while ($product = DB::getInstance()->nextRow($allProductsOut))
if (isset($priceFilter) AND $priceFilter) if (isset($priceFilter) AND $priceFilter)
{ {
$price = Product::getPriceStatic($product['id_product']); $price = Product::getPriceStatic($product['id_product']);
@@ -1605,13 +1612,8 @@ class BlockLayered extends Module
case 'condition': case 'condition':
case 'quantity': case 'quantity':
$sqlQuery['select'] = ' $sqlQuery['select'] = '
SELECT p.`id_product`, p.`condition`, p.`id_manufacturer`, p.`quantity`, p.`weight`, SELECT p.`id_product`, p.`condition`, p.`id_manufacturer`, p.`quantity`, p.`weight`
(SELECT GROUP_CONCAT(`id_category`) FROM `'._DB_PREFIX_.'category_product` cp WHERE cp.`id_product` = p.`id_product`) ids_cat, ';
(SELECT GROUP_CONCAT(`id_feature_value`) FROM `'._DB_PREFIX_.'feature_product` fp WHERE fp.`id_product` = p.`id_product`) ids_feat,
(SELECT GROUP_CONCAT(DISTINCT(pac.`id_attribute`))
FROM `'._DB_PREFIX_.'product_attribute_combination` pac
LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (pa.`id_product_attribute` = pac.`id_product_attribute`)
WHERE pa.`id_product` = p.`id_product`) ids_attr';
$sqlQuery['from'] = ' $sqlQuery['from'] = '
FROM '._DB_PREFIX_.'product p '; FROM '._DB_PREFIX_.'product p ';
$sqlQuery['join'] = ' $sqlQuery['join'] = '
@@ -1906,6 +1908,7 @@ class BlockLayered extends Module
} }
$blackList = array('weight','price'); $blackList = array('weight','price');
$nofollow = false;
foreach ($filterBlocks as &$typeFilter) foreach ($filterBlocks as &$typeFilter)
{ {
if(count($typeFilter) > 0 AND !in_array($typeFilter['type'], $blackList)) if(count($typeFilter) > 0 AND !in_array($typeFilter['type'], $blackList))
@@ -1987,11 +1990,12 @@ class BlockLayered extends Module
INNER JOIN `'._DB_PREFIX_.'price_static_index` psi ON (psi.id_product = p.id_product AND psi.id_currency = '.(int)$idCurrency.' INNER JOIN `'._DB_PREFIX_.'price_static_index` psi ON (psi.id_product = p.id_product AND psi.id_currency = '.(int)$idCurrency.'
AND psi.price_min <= '.(int)$filterValue[1].' AND psi.price_max >= '.(int)$filterValue[0].') '; AND psi.price_min <= '.(int)$filterValue[1].' AND psi.price_max >= '.(int)$filterValue[0].') ';
} }
else{ else
{
$idCurrency = Currency::getCurrent()->id; $idCurrency = Currency::getCurrent()->id;
$priceFilterQuery = ' $priceFilterQuery = '
INNER JOIN `'._DB_PREFIX_.'price_static_index` psi ON (psi.id_product = p.id_product AND psi.id_currency = '.(int)$idCurrency.' INNER JOIN `'._DB_PREFIX_.'price_static_index` psi
AND psi.`id_product` = p.`id_product` AND psi.`id_currency` = '.(int)$idCurrency.') '; ON (psi.id_product = p.id_product AND psi.id_currency = '.(int)$idCurrency.') ';
} }
return array('join' => $priceFilterQuery, 'select' => ', psi.price_min, psi.price_max'); return array('join' => $priceFilterQuery, 'select' => ', psi.price_min, psi.price_max');