Jump to content

Tips code : rendre les codes promos NON cumulables


Recommended Posts

Bonjour,
 
plusieurs clients m'ont demandé de ne plus jamais rendre cumulable un bon de réduction,
et certains modules créent des codes promo cumulables par défaut.
 
J'ai oublié de préciser que c'est pour Prestashop v1.6
 
Si vous ne voulez plus que les codes promos soient cumulables,
éditez le fichier CartRule.php se trouvant dans /classes (mieux vaut créer un override de cette classe)
et modifiez les conditions (IF) comme ci-dessous.
 
Commentez le code comme ci-dessous :
 
	/*
	if ($this->cart_rule_restriction && $otherCartRule['cart_rule_restriction'] && $otherCartRule['id_cart_rule'] != $this->id) {
		$combinable = Db::getInstance()->getValue('
		SELECT id_cart_rule_1
		FROM '._DB_PREFIX_.'cart_rule_combination
		WHERE (id_cart_rule_1 = '.(int)$this->id.' AND id_cart_rule_2 = '.(int)$otherCartRule['id_cart_rule'].')
		OR (id_cart_rule_2 = '.(int)$this->id.' AND id_cart_rule_1 = '.(int)$otherCartRule['id_cart_rule'].')');
		if (!$combinable) {
	
			$cart_rule = new CartRule((int)$otherCartRule['id_cart_rule'], $context->cart->id_lang);
			// The cart rules are not combinable and the cart rule currently in the cart has priority over the one tested
			if ($cart_rule->priority <= $this->priority) {
				return (!$display_error) ? false : Tools::displayError('This voucher is not combinable with an other voucher already in your cart:').' '.$cart_rule->name;
			}
			// But if the cart rule that is tested has priority over the one in the cart, we remove the one in the cart and keep this new one
			else {
				$context->cart->removeCartRule($cart_rule->id);
			} 
		}
	}			
	*/

 

 
Rajoutez ce code après le commentaire  : 
if ($otherCartRule['id_cart_rule'] != $this->id) { 
$cart_rule = new CartRule((int)$otherCartRule['id_cart_rule'], $context->cart->id_lang);
// The cart rules are not combinable and the cart rule currently in the cart has priority over the one tested
if ($cart_rule->priority <= $this->priority) {
return (!$display_error) ? false : Tools::displayError('This voucher is not combinable with an other voucher already in your cart:').' '.$cart_rule->name;
}
// But if the cart rule that is tested has priority over the one in the cart, we remove the one in the cart and keep this new one
else {
$context->cart->removeCartRule($cart_rule->id);
}
} 
 
Il existe surement d'autres manière de faire,
celle-ci fonctionne bien et créera une erreur lorsque l'on veut rajouter un 2e code promo dans son panier.
 
 
-----------------------
 
Ensuite, pour la page Mes bons de réductions :
I faut modifier la colonne Cumulable pour obliger le "Non".
 

Pour cela, ouvrez le fichier discount.tpl du thème, et enlever le IF ELSE pour ne laisser que la ligne du "No".
Par exemple dans discount.tpl , remplacez :

<td class="discount_cumulative">
    {if $discountDetail.cumulable == 1}
        <i class="icon-ok icon"></i> {l s='Yes'}
    {else}
        <i class="icon-remove icon"></i> {l s='No'}
    {/if}
</td>

par :

<td class="discount_cumulative">
    <i class="icon-remove icon"></i> {l s='No'}
</td>

Vous pouvez aussi masquer la colonne du cumul si vous voulez avec ce bout de css à la fin de votre fichier global.css par exemple :

#discount table.discount .discount_cumulative{
display:none;
}

Edited by Christophe Boix (see edit history)
Link to comment
Share on other sites

j'ai oublié de préciser, si vous utilisez la page Mes bons de réductions, alors il faut modifier la colonne Cumulable pour obliger le "Non".
Pour cela, ouvrez le fichier discount.tpl du thème, et enlever le IF ELSE pour ne laisser que la ligne du "No".
Par exemple dans discount.tpl , remplacez :

<td class="discount_cumulative">
	{if $discountDetail.cumulable == 1}
		<i class="icon-ok icon"></i> {l s='Yes'}
	{else}
		<i class="icon-remove icon"></i> {l s='No'}
	{/if}
</td>

par :

<td class="discount_cumulative">
	<i class="icon-remove icon"></i> {l s='No'}
</td>

  • Like 1
Link to comment
Share on other sites

  • 3 years later...
  • 3 years later...

Voici le code à rajouter pour PS 1.7.7.5 

           if ($otherCartRule['id_cart_rule'] != $this->id) {
                        $cart_rule = new CartRule((int) $otherCartRule['id_cart_rule'], $cart->id_lang);
                        // The cart rules are not combinable and the cart rule currently in the cart has priority over the one tested
                        if ($cart_rule->priority <= $this->priority) {
                            return (!$display_error) ? false : $this->trans('This voucher is not combinable with an other voucher already in your cart: %s', [$cart_rule->name], 'Shop.Notifications.Error');
                        } else {
                            // But if the cart rule that is tested has priority over the one in the cart, we remove the one in the cart and keep this new one
                            $cart->removeCartRule($cart_rule->id);
                        }
                }


 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...