Jump to content

Règles Paniers : Exclure Les Produits Déjà Remisés


Recommended Posts

Bonjour à toutes et à tous.

 

Prestashop dans ses version 1.5 et 1.6 ne permet pas d'exclure les produits déjà remisés lorsque  l'on crée une règle panier.

Une fonctionnalité qui semble pourtant évidente et indispensable.

 

Personnellement, voici ma méthode pour que les règles paniers ne s'appliquent pas aux produits remisés, mais s'appliquent bien aux autres produits du panier si ceux-ci sont éligibles.

 

Il faut modifier la méthode checkProductRestrictions de la class CartRule.

Il est donc bien évidemment conseillé de passer par un override.

modif effectuée sur 1.6.0.9

Remplacez

$eligibleProductsList = array();
if (isset($context->cart) && is_object($context->cart) && is_array($products = $context->cart->getProducts()))
foreach ($products as $product)
	$eligibleProductsList[] = (int)$product['id_product'].'-'.(int)$product['id_product_attribute'];
if (!count($eligibleProductsList))
	return (!$display_error) ? false : Tools::displayError('You cannot use this voucher in an empty cart');

par

$eligibleProductsList = array();
$promoProduct=false;
if (isset($context->cart) && is_object($context->cart) && is_array($products = $context->cart->getProducts()))
	foreach ($products as $product) {
		if(empty($product["reduction_applies"]) || $product["reduction_applies"] == 0)
			$eligibleProductsList[] = (int)$product['id_product'] . '-' . (int)$product['id_product_attribute'];
		else
			$promoProduct = true;
					}
		if (!count($eligibleProductsList) && $promoProduct == false)
			return (!$display_error) ? false : Tools::displayError('You cannot use this voucher in an empty cart');
		elseif (!count($eligibleProductsList) && $promoProduct == true)
			return (!$display_error) ? false : Tools::displayError('You cannot use this voucher with discounts products.');

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

Perso, je n'aurais pas écrit ça à la mode Prestashop mais plutôt

$eligibleProductsList = array();
$promoProduct = false;

if (isset($context->cart) && is_object($context->cart) && is_array($products = $context->cart->getProducts())) {

	foreach ($products as $product) {
	
		if(empty($product["reduction_applies"]))
			$eligibleProductsList[] = (int)$product['id_product'] . '-' . (int)$product['id_product_attribute'];
		else
			$promoProduct = true;
	}
	if (!count($eligibleProductsList)) {
		if(!$promoProduct)
			return (!$display_error) ? false : Tools::displayError('You cannot use this voucher in an empty cart');
		else
			return (!$display_error) ? false : Tools::displayError('You cannot use this voucher on an already discounted');
}
}
Edited by Eolia (see edit history)
  • Like 1
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...