Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

[*] BO : fix execution time in cart rule controller when shop has too many cart rules #1456

Open
wants to merge 1 commit into from

3 participants

@GuigZ-

If two manu cart rules on BO, we have a max execution time.

Thanks

@jeromenadaud

Hi,

Thank you for reporting,

Is this solving your problem : #2598

Best regards.

@jocel1 jocel1 was assigned by jeromenadaud
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 27, 2014
  1. @GuigZ-
This page is out of date. Refresh to see the latest.
View
22 admin-dev/themes/default/template/controllers/cart_rules/conditions.tpl
@@ -228,8 +228,16 @@
</label>
</p>
<div id="cart_rule_restriction_div">
+ <div class="choice">
+ <input type="radio" name="cartRulesSelection" value="select" {if $cart_rules.unselected|@count == 0}checked="checked"{/if}/>
+ <strong>{l s='Combinable all cart rules'}</strong><br />
+ <input type="radio" name="cartRulesSelection" value="unselect" {if $cart_rules.selected|@count == 0}checked="checked"{/if}/>
+ <strong>{l s='Uncombinable all cart rules'}</strong><br />
+ <input type="radio" name="cartRulesSelection" value="personnalize" {if $cart_rules.selected|@count > 0 && $cart_rules.unselected|@count > 0}checked="checked"{/if} />
+ <strong>{l s='Personnalize'}</strong>
+ </div>
<br />
- <table class="table">
+ <table id="cartRulesSelection" class="table" {if $cart_rules.selected|@count == 0 || $cart_rules.unselected|@count == 0}style="display:none;"{/if}>
<tr>
<td>
<p>{l s='Uncombinable cart rules'}</p>
@@ -307,3 +315,15 @@
{/if}
</div>
</div>
+<script type="text/javascript">
+$(function() {
+ $('input[name=cartRulesSelection]').change(function(){
+ if($('input[name=cartRulesSelection]:checked').val() == 'personnalize') {
+ $("#cartRulesSelection").slideDown();
+ }
+ else{
+ $("#cartRulesSelection").slideUp();
+ }
+ });
+});
+</script>
View
29 classes/CartRule.php
@@ -992,6 +992,23 @@ public static function cleanCache()
protected function getCartRuleCombinations()
{
$array = array();
+ $query_combinations = 'SELECT IF(id_cart_rule_1 = '.(int)$this->id.', id_cart_rule_2, id_cart_rule_1) AS id_cart_rule
+ FROM '._DB_PREFIX_.'cart_rule_combination
+ WHERE '.(int)$this->id.' = id_cart_rule_1
+ OR '.(int)$this->id.' = id_cart_rule_2';
+
+ $results_combinations = DB::getInstance()->executeS($query_combinations);
+
+ $combinations = array();
+
+ if ($results_combinations && sizeof($results_combinations)) {
+ foreach( $results_combinations as $id_cart_rule) {
+ $combinations[] = $id_cart_rule['id_cart_rule'];
+ }
+ }
+
+ $combinations = sizeof($combinations) ? implode(',', $combinations) : 0;
+
$array['selected'] = Db::getInstance()->executeS('
SELECT cr.*, crl.*, 1 as selected
FROM '._DB_PREFIX_.'cart_rule cr
@@ -999,24 +1016,16 @@ protected function getCartRuleCombinations()
WHERE cr.id_cart_rule != '.(int)$this->id.'
AND (
cr.cart_rule_restriction = 0
- OR cr.id_cart_rule IN (
- SELECT IF(id_cart_rule_1 = '.(int)$this->id.', id_cart_rule_2, id_cart_rule_1)
- FROM '._DB_PREFIX_.'cart_rule_combination
- WHERE '.(int)$this->id.' = id_cart_rule_1
- OR '.(int)$this->id.' = id_cart_rule_2
- )
+ OR cr.id_cart_rule IN ('.$combinations.')
)');
$array['unselected'] = Db::getInstance()->executeS('
SELECT cr.*, crl.*, 1 as selected
FROM '._DB_PREFIX_.'cart_rule cr
INNER JOIN '._DB_PREFIX_.'cart_rule_lang crl ON (cr.id_cart_rule = crl.id_cart_rule AND crl.id_lang = '.(int)Context::getContext()->language->id.')
- LEFT JOIN '._DB_PREFIX_.'cart_rule_combination crc1 ON (cr.id_cart_rule = crc1.id_cart_rule_1 AND crc1.id_cart_rule_2 = '.(int)$this->id.')
- LEFT JOIN '._DB_PREFIX_.'cart_rule_combination crc2 ON (cr.id_cart_rule = crc2.id_cart_rule_2 AND crc2.id_cart_rule_1 = '.(int)$this->id.')
WHERE cr.cart_rule_restriction = 1
AND cr.id_cart_rule != '.(int)$this->id.'
- AND crc1.id_cart_rule_1 IS NULL
- AND crc2.id_cart_rule_1 IS NULL');
+ AND cr.id_cart_rule NOT IN ('.$combinations.')');
return $array;
}
View
19 controllers/admin/AdminCartRulesController.php
@@ -185,12 +185,21 @@ protected function afterAdd($currentObject)
Db::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.'cart_rule_'.$type.'` (`id_cart_rule`, `id_'.$type.'`) VALUES '.implode(',', $values));
}
// Add cart rule restrictions
- if (Tools::getValue('cart_rule_restriction') && is_array($array = Tools::getValue('cart_rule_select')) && count($array))
+ if (Tools::getValue('cart_rule_restriction'))
{
- $values = array();
- foreach ($array as $id)
- $values[] = '('.(int)$currentObject->id.','.(int)$id.')';
- Db::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.'cart_rule_combination` (`id_cart_rule_1`, `id_cart_rule_2`) VALUES '.implode(',', $values));
+ if (Tools::getValue('cartRulesSelection') === 'personnalize') {
+ $values = array();
+ foreach ($array as $id)
+ $values[] = '('.(int)$currentObject->id.','.(int)$id.')';
+ Db::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.'cart_rule_combination` (`id_cart_rule_1`, `id_cart_rule_2`) VALUES '.implode(',', $values));
+ }
+ else if (Tools::getValue('cartRulesSelection') === 'select')
+ {
+ Db::getInstance()->execute('
+ INSERT INTO `'._DB_PREFIX_.'cart_rule_combination` (`id_cart_rule_1`, `id_cart_rule_2`) (
+ SELECT id_cart_rule, '.(int)$currentObject->id.' FROM `'._DB_PREFIX_.'cart_rule` WHERE cart_rule_restriction = 1
+ )');
+ }
}
// Add product rule restrictions
if (Tools::getValue('product_restriction') && is_array($ruleGroupArray = Tools::getValue('product_rule_group')) && count($ruleGroupArray))
Something went wrong with that request. Please try again.