[-] Core: fix cache product group reduction #PSCFV-4974
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@17883 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
1 parent
0fd7eeaccc
commit
ec82772928
3 files changed
+49
-39
No files matched your search
@@ -332,7 +332,7 @@ class CategoryCore extends ObjectModel
|
|||||||
CartRule::cleanProductRuleIntegrity('categories', array($cat->id));
|
CartRule::cleanProductRuleIntegrity('categories', array($cat->id));
|
||||||
Category::cleanPositions($cat->id_parent);
|
Category::cleanPositions($cat->id_parent);
|
||||||
/* Delete Categories in GroupReduction */
|
/* Delete Categories in GroupReduction */
|
||||||
if (GroupReduction::getGroupReductionByCategoryId((int)$cat->id))
|
if (GroupReduction::getGroupsReductionByCategoryId((int)$cat->id))
|
||||||
GroupReduction::deleteCategory($cat->id);
|
GroupReduction::deleteCategory($cat->id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+45
-27
@@ -149,41 +149,57 @@ class GroupReductionCore extends ObjectModel
|
|||||||
WHERE `id_group` = '.(int)$id_group.' AND `id_category` = '.(int)$id_category);
|
WHERE `id_group` = '.(int)$id_group.' AND `id_category` = '.(int)$id_category);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getGroupsByCategoryId($id_category)
|
||||||
|
{
|
||||||
|
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
|
||||||
|
SELECT gr.`id_group` as id_group, gr.`reduction` as reduction, id_group_reduction
|
||||||
|
FROM `'._DB_PREFIX_.'group_reduction` gr
|
||||||
|
WHERE `id_category` = '.(int)$id_category
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public static function getGroupByCategoryId($id_category)
|
public static function getGroupByCategoryId($id_category)
|
||||||
{
|
{
|
||||||
|
Tools::displayAsDeprecated('Use GroupReduction::getGroupsByCategoryId($id_category)');
|
||||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
||||||
SELECT gr.`id_group` as id_group, gr.`reduction` as reduction
|
SELECT gr.`id_group` as id_group, gr.`reduction` as reduction, id_group_reduction
|
||||||
FROM `'._DB_PREFIX_.'group_reduction` gr
|
FROM `'._DB_PREFIX_.'group_reduction` gr
|
||||||
WHERE `id_category` = '.(int)$id_category,
|
WHERE `id_category` = '.(int)$id_category
|
||||||
false);
|
, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getGroupsReductionByCategoryId($id_category)
|
||||||
|
{
|
||||||
|
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
|
||||||
|
SELECT gr.`id_group_reduction` as id_group_reduction, id_group
|
||||||
|
FROM `'._DB_PREFIX_.'group_reduction` gr
|
||||||
|
WHERE `id_category` = '.(int)$id_category
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public static function getGroupReductionByCategoryId($id_category)
|
public static function getGroupReductionByCategoryId($id_category)
|
||||||
{
|
{
|
||||||
|
Tools::displayAsDeprecated('Use GroupReduction::getGroupsByCategoryId($id_category)');
|
||||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
||||||
SELECT gr.`id_group_reduction` as id_group_reduction
|
SELECT gr.`id_group_reduction` as id_group_reduction
|
||||||
FROM `'._DB_PREFIX_.'group_reduction` gr
|
FROM `'._DB_PREFIX_.'group_reduction` gr
|
||||||
WHERE `id_category` = '.(int)$id_category,
|
WHERE `id_category` = '.(int)$id_category
|
||||||
false);
|
, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function setProductReduction($id_product, $id_group, $id_category, $reduction)
|
public static function setProductReduction($id_product, $id_group = null, $id_category, $reduction = null)
|
||||||
{
|
{
|
||||||
Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
GroupReduction::deleteProductReduction((int)$id_product);
|
||||||
SELECT pgr.`id_product`, pgr.`id_group`, pgr.`reduction`
|
$reductions = GroupReduction::getGroupsByCategoryId((int)$id_category);
|
||||||
FROM `'._DB_PREFIX_.'product_group_reduction_cache` pgr
|
if ($reductions)
|
||||||
WHERE pgr.`id_product` = '.(int)$id_product
|
{
|
||||||
);
|
$res = true;
|
||||||
|
foreach ($reductions as $reduction)
|
||||||
|
$res &= Db::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.'product_group_reduction_cache` (`id_product`, `id_group`, `reduction`)
|
||||||
|
VALUES ('.(int)$id_product.', '.(int)$reduction['id_group'].', '.(float)$reduction['reduction'].')');
|
||||||
|
}
|
||||||
|
|
||||||
if (Db::getInstance()->NumRows() == 0)
|
return $res;
|
||||||
$query = 'INSERT INTO `'._DB_PREFIX_.'product_group_reduction_cache` (`id_product`, `id_group`, `reduction`)
|
|
||||||
VALUES ('.(int)$id_product.', '.(int)$id_group.', '.(float)$reduction.')';
|
|
||||||
else
|
|
||||||
$query = 'UPDATE `'._DB_PREFIX_.'product_group_reduction_cache`
|
|
||||||
SET `reduction` = '.(float)$reduction.'
|
|
||||||
WHERE `id_product` = '.(int)$id_product.' AND `id_group` = '.(int)$id_group;
|
|
||||||
|
|
||||||
return (Db::getInstance()->execute($query));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function deleteProductReduction($id_product)
|
public static function deleteProductReduction($id_product)
|
||||||
@@ -196,23 +212,25 @@ class GroupReductionCore extends ObjectModel
|
|||||||
|
|
||||||
public static function duplicateReduction($id_product_old, $id_product)
|
public static function duplicateReduction($id_product_old, $id_product)
|
||||||
{
|
{
|
||||||
$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
$res = Db::getInstance(_PS_USE_SQL_SLAVE_)->executes('
|
||||||
SELECT pgr.`id_product`, pgr.`id_group`, pgr.`reduction`
|
SELECT pgr.`id_product`, pgr.`id_group`, pgr.`reduction`
|
||||||
FROM `'._DB_PREFIX_.'product_group_reduction_cache` pgr
|
FROM `'._DB_PREFIX_.'product_group_reduction_cache` pgr
|
||||||
WHERE pgr.`id_product` = '.(int)$id_product_old
|
WHERE pgr.`id_product` = '.(int)$id_product_old
|
||||||
);
|
);
|
||||||
if (!$row)
|
if (!$res)
|
||||||
return true;
|
return true;
|
||||||
|
foreach ($res as $row)
|
||||||
$query = 'INSERT INTO `'._DB_PREFIX_.'product_group_reduction_cache` (`id_product`, `id_group`, `reduction`) VALUES ';
|
{
|
||||||
$query .= '('.(int)$id_product.', '.(int)$row['id_group'].', '.(float)$row['reduction'].')';
|
$query = 'INSERT INTO `'._DB_PREFIX_.'product_group_reduction_cache` (`id_product`, `id_group`, `reduction`) VALUES ';
|
||||||
return (Db::getInstance()->execute($query));
|
$query .= '('.(int)$id_product.', '.(int)$row['id_group'].', '.(float)$row['reduction'].')';
|
||||||
|
}
|
||||||
|
return Db::getInstance()->execute($query);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function deleteCategory($id_category)
|
public static function deleteCategory($id_category)
|
||||||
{
|
{
|
||||||
$query = 'DELETE FROM `'._DB_PREFIX_.'group_reduction` WHERE `id_category` = '.(int)$id_category;
|
$query = 'DELETE FROM `'._DB_PREFIX_.'group_reduction` WHERE `id_category` = '.(int)$id_category;
|
||||||
if (Db::getInstance()->execute($query) === false)
|
if (Db::getInstance()->Execute($query) === false)
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-11
@@ -467,6 +467,7 @@ class ProductCore extends ObjectModel
|
|||||||
else
|
else
|
||||||
StockAvailable::setProductOutOfStock((int)$this->id, 2);
|
StockAvailable::setProductOutOfStock((int)$this->id, 2);
|
||||||
|
|
||||||
|
$this->setGroupReduction();
|
||||||
Hook::exec('actionProductSave', array('id_product' => $this->id));
|
Hook::exec('actionProductSave', array('id_product' => $this->id));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -474,6 +475,7 @@ class ProductCore extends ObjectModel
|
|||||||
public function update($null_values = false)
|
public function update($null_values = false)
|
||||||
{
|
{
|
||||||
$return = parent::update($null_values);
|
$return = parent::update($null_values);
|
||||||
|
$this->setGroupReduction();
|
||||||
Hook::exec('actionProductSave', array('id_product' => $this->id));
|
Hook::exec('actionProductSave', array('id_product' => $this->id));
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
@@ -803,8 +805,6 @@ class ProductCore extends ObjectModel
|
|||||||
if (!$this->addToCategories($categories))
|
if (!$this->addToCategories($categories))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!$this->setGroupReduction())
|
|
||||||
return false;
|
|
||||||
SpecificPriceRule::applyAllRules(array((int)$this->id));
|
SpecificPriceRule::applyAllRules(array((int)$this->id));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -4522,15 +4522,7 @@ class ProductCore extends ObjectModel
|
|||||||
*/
|
*/
|
||||||
public function setGroupReduction()
|
public function setGroupReduction()
|
||||||
{
|
{
|
||||||
$row = GroupReduction::getGroupByCategoryId($this->id_category_default);
|
return GroupReduction::setProductReduction($this->id, null, $this->id_category_default);
|
||||||
if (!$row) // Remove
|
|
||||||
{
|
|
||||||
if (!GroupReduction::deleteProductReduction($this->id))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else if (!GroupReduction::setProductReduction($this->id, $row['id_group'], $this->id_category_default, (float)$row['reduction']))
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in new issue
Block a user