[-] BO : cart rules are now cleaned when a component of a product rule (like a product, a category, a supplier...) is deleted

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@16548 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
dMetzger
2012-07-24 13:11:56 +00:00
parent 412cae1d51
commit 096bc90802
6 changed files with 60 additions and 1 deletions
+3
View File
@@ -93,6 +93,9 @@ class AttributeCore extends ObjectModel
foreach ($combinations as $combination)
$combination->delete();
}
// Delete associated restrictions on cart rules
CartRule::cleanProductRuleIntegrity('attributes', $this->id);
/* Reinitializing position */
$this->cleanPositions((int)$this->id_attribute_group);
+40
View File
@@ -1096,6 +1096,46 @@ class CartRuleCore extends ObjectModel
{
return (bool)Configuration::get('PS_CART_RULE_FEATURE_ACTIVE');
}
/* When an entity associated to a product rule (product, category, attribute, supplier, manufacturer...) is deleted, the product rules must be updated */
public static function cleanProductRuleIntegrity($type, $list)
{
// Type must be available in the 'type' enum of the table cart_rule_product_rule
if (!in_array($type, array('products', 'categories', 'attributes', 'manufacturers', 'suppliers')))
return false;
// This check must not be removed because this var is used a few lines below
$list = (is_array($list) ? implode(',', array_map('intval', $list)) : (int)$list);
if (!preg_match('/^[0-9,]+$/', $list))
return false;
// Delete associated restrictions on cart rules
Db::getInstance()->execute('
DELETE crprv
FROM `'._DB_PREFIX_.'cart_rule_product_rule` crpr
LEFT JOIN `'._DB_PREFIX_.'cart_rule_product_rule_value` crprv ON crpr.`id_product_rule` = crprv.`id_product_rule`
WHERE crpr.`type` = "'.pSQL($type).'"
AND crprv.`id_item` IN ('.$list.')'); // $list is checked a few lines above
// Delete the product rules that does not have any values
if (Db::getInstance()->Affected_Rows() > 0)
Db::getInstance()->execute('
DELETE FROM `'._DB_PREFIX_.'cart_rule_product_rule`
WHERE `id_product_rule` NOT IN (SELECT id_product_rule FROM `'._DB_PREFIX_.'cart_rule_product_rule_value`)');
// If the product rules were the only conditions of a product rule group, delete the product rule group
if (Db::getInstance()->Affected_Rows() > 0)
Db::getInstance()->execute('
DELETE FROM `'._DB_PREFIX_.'cart_rule_product_rule_group`
WHERE `id_product_rule_group` NOT IN (SELECT id_product_rule_group FROM `'._DB_PREFIX_.'cart_rule_product_rule`)');
// If the product rule group were the only restrictions of a cart rule, update de cart rule restriction cache
if (Db::getInstance()->Affected_Rows() > 0)
Db::getInstance()->execute('
UPDATE `'._DB_PREFIX_.'cart_rule` cr
LEFT JOIN `'._DB_PREFIX_.'cart_rule_product_rule_group` crprg ON cr.id_cart_rule = crprg.id_cart_rule
SET product_restriction = IF(crprg.id_product_rule_group IS NULL, 0, 1)');
return true;
}
/**
* @static
+3
View File
@@ -323,6 +323,9 @@ class CategoryCore extends ObjectModel
Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'category_product` WHERE `id_category` IN ('.$list.')');
Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'category_group` WHERE `id_category` IN ('.$list.')');
Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'category_shop` WHERE `id_category` IN ('.$list.')');
// Delete associated restrictions on cart rules
CartRule::cleanProductRuleIntegrity('categories', $to_delete);
Category::cleanPositions($this->id_parent);
+3
View File
@@ -117,7 +117,10 @@ class ManufacturerCore extends ObjectModel
return false;
if (parent::delete())
{
CartRule::cleanProductRuleIntegrity('manufacturers', $this->id);
return $this->deleteImage();
}
}
/**
+8 -1
View File
@@ -672,7 +672,8 @@ class ProductCore extends ObjectModel
!$this->deleteAccessories() ||
!$this->deleteFromAccessories() ||
!$this->deleteFromSupplier() ||
!$this->deleteDownload())
!$this->deleteDownload() ||
!$this->deleteFromCartRules())
return false;
return true;
@@ -690,6 +691,12 @@ class ProductCore extends ObjectModel
return $return;
}
public function deleteFromCartRules()
{
CartRule::cleanProductRuleIntegrity('products', $this->id);
return true;
}
public function deleteFromSupplier()
{
return Db::getInstance()->delete('product_supplier', 'id_product = '.(int)$this->id);
+3
View File
@@ -355,7 +355,10 @@ class SupplierCore extends ObjectModel
public function delete()
{
if (parent::delete())
{
CartRule::cleanProductRuleIntegrity('suppliers', $this->id);
return $this->deleteImage();
}
}
/**