[-] BO : cart rules are now cleaned when a component of a product rule (like a product, a category, a supplier...) is deleted
This commit is contained in:
1 parent
f4fa8bd1b1
commit
f1270e3ab0
6 files changed
+60
-1
No files matched your search
@@ -94,6 +94,9 @@ class AttributeCore extends ObjectModel
|
|||||||
$combination->delete();
|
$combination->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Delete associated restrictions on cart rules
|
||||||
|
CartRule::cleanProductRuleIntegrity('attributes', $this->id);
|
||||||
|
|
||||||
/* Reinitializing position */
|
/* Reinitializing position */
|
||||||
$this->cleanPositions((int)$this->id_attribute_group);
|
$this->cleanPositions((int)$this->id_attribute_group);
|
||||||
|
|
||||||
|
|||||||
@@ -1097,6 +1097,46 @@ class CartRuleCore extends ObjectModel
|
|||||||
return (bool)Configuration::get('PS_CART_RULE_FEATURE_ACTIVE');
|
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
|
* @static
|
||||||
* @param $name
|
* @param $name
|
||||||
|
|||||||
@@ -324,6 +324,9 @@ class CategoryCore extends ObjectModel
|
|||||||
Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'category_group` 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.')');
|
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);
|
Category::cleanPositions($this->id_parent);
|
||||||
|
|
||||||
/* Delete category images and its children images */
|
/* Delete category images and its children images */
|
||||||
|
|||||||
@@ -117,7 +117,10 @@ class ManufacturerCore extends ObjectModel
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (parent::delete())
|
if (parent::delete())
|
||||||
|
{
|
||||||
|
CartRule::cleanProductRuleIntegrity('manufacturers', $this->id);
|
||||||
return $this->deleteImage();
|
return $this->deleteImage();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+8
-1
@@ -672,7 +672,8 @@ class ProductCore extends ObjectModel
|
|||||||
!$this->deleteAccessories() ||
|
!$this->deleteAccessories() ||
|
||||||
!$this->deleteFromAccessories() ||
|
!$this->deleteFromAccessories() ||
|
||||||
!$this->deleteFromSupplier() ||
|
!$this->deleteFromSupplier() ||
|
||||||
!$this->deleteDownload())
|
!$this->deleteDownload() ||
|
||||||
|
!$this->deleteFromCartRules())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -690,6 +691,12 @@ class ProductCore extends ObjectModel
|
|||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function deleteFromCartRules()
|
||||||
|
{
|
||||||
|
CartRule::cleanProductRuleIntegrity('products', $this->id);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public function deleteFromSupplier()
|
public function deleteFromSupplier()
|
||||||
{
|
{
|
||||||
return Db::getInstance()->delete('product_supplier', 'id_product = '.(int)$this->id);
|
return Db::getInstance()->delete('product_supplier', 'id_product = '.(int)$this->id);
|
||||||
|
|||||||
@@ -355,7 +355,10 @@ class SupplierCore extends ObjectModel
|
|||||||
public function delete()
|
public function delete()
|
||||||
{
|
{
|
||||||
if (parent::delete())
|
if (parent::delete())
|
||||||
|
{
|
||||||
|
CartRule::cleanProductRuleIntegrity('suppliers', $this->id);
|
||||||
return $this->deleteImage();
|
return $this->deleteImage();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in new issue
Block a user