// Merge -> revision 8624
This commit is contained in:
+44
-45
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user