// 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()
{
$this->validateFields();
$fields['id_product'] = (int)($this->id_product);
$fields['id_shop'] = (int)($this->id_shop);
$fields['id_currency'] = (int)($this->id_currency);
$fields['id_country'] = (int)($this->id_country);
$fields['id_group'] = (int)($this->id_group);
$fields['price'] = (float)($this->price);
$fields['from_quantity'] = (int)($this->from_quantity);
$fields['reduction'] = (float)($this->reduction);
$fields['id_product'] = (int)$this->id_product;
$fields['id_shop'] = (int)$this->id_shop;
$fields['id_currency'] = (int)$this->id_currency;
$fields['id_country'] = (int)$this->id_country;
$fields['id_group'] = (int)$this->id_group;
$fields['price'] = (float)$this->price;
$fields['from_quantity'] = (int)$this->from_quantity;
$fields['reduction'] = (float)$this->reduction;
$fields['reduction_type'] = pSQL($this->reduction_type);
$fields['from'] = pSQL($this->from);
$fields['to'] = pSQL($this->to);
@@ -68,17 +68,16 @@ class SpecificPriceCore extends ObjectModel
public static function getByProductId($id_product)
{
return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
SELECT *
FROM `'._DB_PREFIX_.'specific_price`
WHERE `id_product` = '.(int)$id_product);
return Db::getInstance()->ExecuteS('
SELECT * FROM `'._DB_PREFIX_.'specific_price` WHERE `id_product` = '.(int)$id_product
);
}
public static function getIdsByProductId($id_product)
{
return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
SELECT `id_specific_price`
FROM `'._DB_PREFIX_.'specific_price`
SELECT `id_specific_price`
FROM `'._DB_PREFIX_.'specific_price`
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) + ';
$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) + ';
return rtrim($select, ' +').') AS `score`';
@@ -121,7 +120,7 @@ class SpecificPriceCore extends ObjectModel
{
if (!self::isFeatureActive())
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 price must not change between the top and the bottom of the page
@@ -146,7 +145,7 @@ class SpecificPriceCore extends ObjectModel
AND
(`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];
}
@@ -186,17 +185,17 @@ class SpecificPriceCore extends ObjectModel
{
if (!self::isFeatureActive())
return array();
$now = date('Y-m-d H:i:s');
$res = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
SELECT *,
'.self::_getScoreQuery($id_product, $id_shop, $id_currency, $id_country, $id_group).'
FROM `'._DB_PREFIX_.'specific_price`
WHERE `id_product` IN(0, '.(int)($id_product).') AND
`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).')
WHERE `id_product` IN(0, '.(int)$id_product.') AND
`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`)
@@ -207,16 +206,16 @@ class SpecificPriceCore extends ObjectModel
');
$targeted_prices = array();
$last_quantity = NULL;
$last_quantity = null;
foreach($res as $specific_price)
{
if (!isset($last_quantity))
$last_quantity = $specific_price['from_quantity'];
$last_quantity = $specific_price['from_quantity'];
else if ($last_quantity == $specific_price['from_quantity'])
break;
$last_quantity = $specific_price['from_quantity'];
$last_quantity = $specific_price['from_quantity'];
if ($specific_price['from_quantity'] > 1)
$targeted_prices[] = $specific_price;
}
@@ -228,25 +227,25 @@ class SpecificPriceCore extends ObjectModel
{
if (!self::isFeatureActive())
return array();
$now = date('Y-m-d H:i:s');
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
SELECT *,
'.self::_getScoreQuery($id_product, $id_shop, $id_currency, $id_country, $id_group).'
FROM `'._DB_PREFIX_.'specific_price`
WHERE `id_product` IN(0, '.(int)($id_product).') AND
`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_quantity` >= '.(int)($quantity).'
WHERE `id_product` IN(0, '.(int)$id_product.') AND
`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_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
ORDER BY `from_quantity` DESC, `score` DESC
');
}
@@ -254,14 +253,14 @@ class SpecificPriceCore extends ObjectModel
{
if (!self::isFeatureActive())
return array();
$resource = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
SELECT `id_product`
FROM `'._DB_PREFIX_.'specific_price`
WHERE `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
WHERE `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_quantity` = 1 AND
(
(`from` = \'0000-00-00 00:00:00\' OR \''.$beginning.'\' >= `from`)
@@ -273,22 +272,22 @@ class SpecificPriceCore extends ObjectModel
', false);
$ids_product = array();
while ($row = DB::getInstance()->nextRow($resource))
$ids_product[] = (int)($row['id_product']);
$ids_product[] = (int)$row['id_product'];
return $ids_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)
{
if ($id_product)
$this->id_product = (int)($id_product);
$this->id_product = (int)$id_product;
return $this->add();
}
/**
* This method is allow to know if a feature is used or active
* @since 1.5.0.1
@@ -298,10 +297,10 @@ class SpecificPriceCore extends ObjectModel
{
if (self::$feature_active === null)
self::$feature_active = (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
SELECT COUNT(*)
SELECT COUNT(*)
FROM `'._DB_PREFIX_.'specific_price`
');
return self::$feature_active;
}
}
}
+63
View File
@@ -28,6 +28,7 @@
class UpgraderCore{
const DEFAULT_CHECK_VERSION_DELAY_HOURS = 24;
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
*
@@ -35,6 +36,9 @@ class UpgraderCore{
*/
private $needUpgrade = false;
private $noRefresh = false;
private $changedFiles = array();
private $missingFiles = array();
private $versionIsModified = false;
public $version_name;
public $version_num;
@@ -154,4 +158,63 @@ class UpgraderCore{
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;
}
}