J ai modifie le plugin incitation pour le frais de port uniquement. Dans le BO il y a maintenant une case ID Pays. Pour que la remise sur le frais de port fonctionne pour la France uniquement, mettez l id de la france (pour moi c est 64).
Ca devrait etre assez simple de generaliser ce code pour les autres types de remises.
Voici le code pour ceux que ca interesse, remplacer directement les fichiers puis descactiver/activer devrait passer. Chez moi ca fonctionne (enfin ca a l air !!!):
incitation_admin.php:
<?php
include_once(realpath(dirname(__FILE__)) . "/Incitation.class.php");
if($_REQUEST['action'] == "modifier"){
if($_REQUEST['id']) {
$incitation = new Incitation();
($_REQUEST['inclurepromo']==1) ? $promoinclus = 1 : $promoinclus =0;
($_REQUEST['inclurenouveaute']==1) ? $nouvinclus = 1 : $nouvinclus =0;
$query = "UPDATE $incitation->table SET actif='" . $_REQUEST['active'] . "', seuiltotal='" . $_REQUEST['seuiltotal'] . "', type='" . $_REQUEST['type'] . "', valref='" . $_REQUEST['valref'] . "', idpays ='". $_REQUEST['idpays'] . "', qtetotal ='". $_REQUEST['qtetotal'] . "', inclurepromo ='". $promoinclus . "', inclurenouveaute ='". $nouvinclus . "', prodpanier ='". $_REQUEST['prodpanier'] . "', qteprod ='". $_REQUEST['qteprod'] . "' where id='". $_REQUEST['id']."'";
$resul = mysql_query($query, $incitation->link);
?>
<script type="text/javascript">
alert("Mise a jour Incitation OK ");
</script>
<?php
}
else {
$incitation = new Incitation();
$incitation->type = $_REQUEST['type'];
$incitation->valref = $_REQUEST['valref'];
$incitation->actif = $_REQUEST['actif'];
$incitation->idpays = $_REQUEST['idpays'];
$incitation->seuiltotal = $_REQUEST['seuiltotal'];
$incitation->qtetotal = $_REQUEST['qtetotal'];
($_REQUEST['inclurepromo']==1) ? $incitation->inclurepromo = $_REQUEST['inclurepromo'] : $incitation->inclurepromo =0;
($_REQUEST['inclurenouveaute']==1) ? $incitation->inclurenouveaute = $_REQUEST['inclurenouveaute']: $incitation->inclurenouveaute =0;
$incitation->prodpanier = $_REQUEST['prodpanier'];
$incitation->qteprod = $_REQUEST['qteprod'];
$incitation->add();
}
}
if($_REQUEST['action'] == "supprimer"){
$incitation = new Incitation();
$query = "delete from $incitation->table where id='" . $_REQUEST['id'] . "'";
$resul = mysql_query($query, $incitation->link);
}
$type_bonus = array();
$incitation = new Incitation();
$query = "select * from $incitation->table order by id ";
$resul = mysql_query($query, $incitation->link);
$nbres = mysql_num_rows($resul);
if(!$nbres) return "";
$compt=0;
while($row = mysql_fetch_object($resul)){
$type_bonus[$compt] = $row;
$compt++;
}
?>
<script src='../js/jquery.js' type='text/javascript'></script>
<script type="text/javascript">
$(document).ready(function(){
$(".cache").hide();
$(".ouvre").click(function(){
$(this).next(".cache").slideToggle(300);
});
$(".ouvre2").click(function(){
$(this).next(".cache2").slideToggle(300);
});
});
</script>
<body>
<html>
<div id="contenu_int" style="width:978px;">
<img src="../client/plugins/incitation/img/plugin.png" style="float:left; margin-right:10px; margin-top:5px;" />
<p class="titre_rubrique">Incitation 0.4.1 (beta)</p>
<p align="right" class="geneva11Reg_3B4B5B"><a href="accueil.php" class="lien04">Accueil </a> <img src="gfx/suivant.gif" width="12" height="9" border="0" /><a href="#" class="lien04">Incitation</a>
</p>
<table width="100%" border="0" cellpadding="5" cellspacing="0">
<tr>
<td width="100%" height="30" class="titre_cellule_tres_sombre">Configuration des incitations</td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr class="cellule_sombre" style="font-weight:bolder">
<th width="10%" height="30" style="text-align:center">Actif</th>
<th width="12%" height="30" >Type d'incitation</th>
<th width="5%" height="30" style="text-align:center"></th>
<th width="16%" height="30"style="text-align:center">Code promo / REF</th>
<th width="5%" height="30" style="text-align:center">ID Pays</th>
<th width="5%" height="30" style="text-align:center">Tot Cmde</th>
<th width="10%" height="30" style="text-align:center">Qte Art</th>
<th width="5%" height="30" style="text-align:center">Promo</th>
<th width="5%" height="30" style="text-align:center">Nouv.</th>
<th width="10%" height="30" style="text-align:center">Ref Panier</th>
<th width="10%" height="30" style="text-align:center">Qte Ref </th>
<th width="15%" height="30" style="text-align:center">Valider</th>
<th width="10%" height="30" style="text-align:center">Suppr.</th>
</tr>
<tr class="cellule_claire"><th height="10"></th><th height="10"></th><th height="10"></th><th height="10"></th><th height="10"></th><th height="10"></th><th height="10"></th><th height="10"></th><th height="10"></th><th height="10"></th><th height="10"></th><th height="10"></th><th height="10"></th></tr>
<?php
$incitation = new Incitation();
foreach ($type_bonus as $incitation) {
echo '<tr class="cellule_claire">
<form action="module.php" method="post">
<input type="hidden" name="nom" value="incitation" />
<input type="hidden" name="id" value="'.$incitation->id.'" />
<input type="hidden" name="action" value="modifier" />
<td style="text-align:center"><input type="checkbox" name="active"';
if($incitation->actif == 1) echo 'checked="checked"';
echo 'value="1" /></td>
<td><select name="type">
<option>Choisir un type</option>
<option value="remise"';
if ($incitation->type=='remise') echo 'selected="selected"';
echo '>Remise</option>
<option value="portoffert"';
if ($incitation->type=='portoffert') echo 'selected="selected"';
echo '>Port offert</option>
<option value="bonusref"';
if ($incitation->type=='bonusref') echo 'selected="selected"';
echo '>Référence offerte</option>
</select>
</td>
<td>';
switch($incitation->type)
{
case 'remise': echo '<img src="../client/plugins/incitation/img/down.png" style="margin-left:10px;" />'; break;
case 'portoffert': echo '<img src="../client/plugins/incitation/img/globe.png" style="margin-left:10px;" />'; break;
case 'bonusref': echo '<img src="../client/plugins/incitation/img/add.png" style="margin-left:10px;" />'; break;
default : echo '<img src="../client/plugins/incitation/img/help.png" style="margin-left:10px;" />'; break;
}
echo '</td>
<td><input type="texte" name="valref" value="'.$incitation->valref.'"/></td>
<td><input type="texte" name="idpays" value="'.$incitation->idpays.'" style="width:80px;" /></td>
<td><input type="texte" name="seuiltotal" value="'.$incitation->seuiltotal.'" style="width:80px;" /></td>
<td><input type="texte" name="qtetotal" value="'.$incitation->qtetotal.'" style="width:80px;" /></td>
<td><input type="checkbox" name="inclurepromo" value="1" ';
if ($incitation->inclurepromo=='1') echo 'checked="checked"';
echo '/></td>
<td><input type="checkbox" name="inclurenouveaute" value="1" ';
if ($incitation->inclurenouveaute=='1') echo 'checked="checked"';
echo '/></td>
<td><input type="texte" name="prodpanier" value="'.$incitation->prodpanier.'" style="width:80px;" /></td>
<td><input type="texte" name="qteprod" value="'.$incitation->qteprod.'" style="width:80px;" /></td>
<td><input type="submit" value="changer"/></form></td>
<td><a style="display:block; width:16px; height:16px;" href="module.php?nom=incitation&action=supprimer&id='.$incitation->id.'"><img src="../client/plugins/incitation/img/stop.png" style="margin-left:10px;" /></a></td>
</tr>';
}
?>
<tr class="cellule_claire"><th height="10"></th><th height="10"></th><th height="10"></th><th height="10"></th><th height="10"></th><th height="10"></th><th height="10"></th><th height="10"></th><th height="10"></th><th height="10"></th><th height="10"></th><th height="10"></th><th height="10"></th></tr>
</table>
<br />
<form action="module.php" method="get">
<input type="hidden" name="nom" value="incitation" />
<input type="hidden" name="action" value="modifier" />
<input type="submit" value="Ajouter une incitation"/>
</form>
<br />
<br />
<br />
<div style="width:970px; color: #000000;">
<div class="ouvre" style="width:975px; cursor:pointer;height:50px; line-height:60px;">
<img src="../client/plugins/incitation/img/bandeau.png" style="float:left;" />
<img src="../client/plugins/incitation/img/help.png" style="float:left; margin:22px 10px 0 290px;" />
<h3>Cliquer ici pour afficher l'aide </h3>
</div>
<div class="cache" style="width:970px;">
<div class="titre_cellule_tres_sombre" style="width:970px; height:20px;">
MODE D'EMPLOI
</div>
<div style="width:955px; border:#999999 dashed 1px;border-top:none; padding:10px;">
<br />
<p>
1°) Sur les fichiers panier.php et commande.php de votre template Thélia, ajoutez la variable : <b>$incitation_active=1;</b>
</p>
<br />
<p>
2°) Pour mettre en place une incitation de type <b>remise</b>, créez d'abords un code promo dans le BO Thélia (Code promo /Ajouter un code promo) avec les paramètres de votre choix.
</p>
<br />
<p>
3°) Pour mettre en place une incitation de type <b>référence offerte</b> créez d'abords un produit spécifique, le cadeau, dans votre catalogue avec un prix=0 et un stock=0. <br />
Pour éviter de le voir s'afficher sur votre site, vous pouvez désactiver l'option "en ligne".
</p>
<br />
<br />
<h3>Interface d'administration des Incitations</h3>
<br />
<ul>
<li>- Colonne <b>"Actif"</b> : doit être cochée pour que l'incitation fonctionne sur votre site (par défaut : décochée).</li>
<br />
<li>
- Colonne <b>"Type d'incitation"</b> : selectionner l'un des 3 types disponibles.<br /><br />
<img src="../client/plugins/incitation/img/down.png" style="float:left; margin:0 10px;" /> Remise sur le montant de la commande <br />
<img src="../client/plugins/incitation/img/globe.png" style="float:left; margin:0 10px;" /> Port offert <br />
<img src="../client/plugins/incitation/img/add.png" style="float:left; margin:0 10px;" /> Référence offerte <br />
</li>
<br >
<li>- Colonne <b>"Code promo/REF"</b> : ce champ est obligatoire pour les types "remise" et "référence offerte". Il est inutile et peut rester vide pour le type "port offert". <br /><br />
<img src="../client/plugins/incitation/img/tag_green.png" style="float:left; margin:0 10px;" /> Pour le type <b>remise</b> : coller le code promo créé pour l'occasion. <br />
<img src="../client/plugins/incitation/img/tag_green.png" style="float:left; margin:0 10px;" /> Pour le type <b>référence offerte</b>: coller la référence du produit à offrir. <br /></li>
<br />
<li>- Colonne <b>"ID Pays"</b> : condition d'attribution de l'incitation : entrer l'ID du pays pour lequel l'incitation est valide, ne fonctionne qu'avec le type "frais de port" (par défaut : 0).</li>
<br />
<li>- Colonne <b>"Tot Cmde"</b> : condition d'attribution de l'incitation : entrer un montant comme seuil minimal TTC d'une commande (par défaut : 0).</li>
<br />
<li>- Colonne <b>"Qte Art"</b> : condition d'attribution de l'incitation : entrer une quantité minimale d'articles dans une commmande (par défaut : 0).</li>
<br />
<li>- Colonnes <b>"Promo"</b> et <b>"Nouv."</b> : Le total de la commande et la quantité d'articles dans le panier sont calculés en prenant en compte les produits nouveaux et/ou en promo si les cases correspondantes sont cochées et vice versa (par défaut : cochées).</li>
<br />
<li>- Colonne <b>"Référence présente"</b> : condition d'attribution de l'incitation : remplir avec la référence d'un produit du
catalogue impose que cette référence soit présente dans le panier pour attribuer l'incitation (par défaut : vide).</li>
<br />
<li>- Colonne <b>"Quantité référence"</b> : condition d'attribution de l'incitation : quantité minimum de la référence ci-dessus
(par défaut : 0).</li>
<br />
<li>- Colonne <b>"valider"</b> : obligatoire pour valider les mises à jour de chaque Incitation.</li>
</ul>
<br />
Le bouton <b>"ajouter une incitation"</b> permet de créer un nombre illimité d'Incitations pour votre site.
<br />
<br />
<br />
<h3>Mode de calcul du plugin</h3>
<br />
Le déroulement du calcul est le suivant : Sur chaque page de votre site disposant de la variable <b>$incitation_active=1</b> le plugin manipule la variable de session promo, normalement dédiée uniquement à l'enregistrement des codes promo validés par le client. Il manipule aussi le panier pour enregistrer ou supprimer les cadeaux prévus. Enfin il force le port à 0 si besoin et l'affiche sur le site si la balise Thélia #PANIER_PORT est présente. concernant les remises sur total, le plugin prend en compte les remises globales niveau client et les codes promos validés selon l'enchaînement suivant :
<br />
<br />
<ul>
<li><img src="../client/plugins/incitation/img/time.png" style="float:left; margin:0 10px;" /> 1°) Réinitialisation de la session <b>promo</b> pour calcul dynamique de sa valeur par <b>Incitation</b>.</li>
<li><img src="../client/plugins/incitation/img/tag_green.png" style="float:left; margin:0 10px;" /> 2°) Calcul des <b>codes promos</b> personnalisés soumis éventuellement par le client sur la page commande.php*</li>
<li><img src="../client/plugins/incitation/img/down.png" style="float:left; margin:0 10px;" /> 3°) Calcul des Incitations de type <b>remises</b> en fonction du total de la commande, diminué de la remise globale niveau client et des éventuels codes promos.</li>
<li><img src="../client/plugins/incitation/img/globe.png" style="float:left; margin:0 10px;" /> 4°) Calcul du <b>port offert</b> en fonction du total de la commande diminué des éventuels codes promos et remises.</li>
<li><img src="../client/plugins/incitation/img/add.png" style="float:left; margin:0 10px;" /> 5°) Calcul des <b>références offertes</b> en fonction du total de la commande diminué des éventuels codes promo et remises.</li><br />
</ul>
<br />
<img src="../client/plugins/incitation/img/error.png" style="float:left; margin:0 10px;" /> * Le plugin modifie le fonctionnement nominal de Thélia sur ce point : si un client rentre un code promo sur la page commande.php et qu'il retourne ensuite sur le site sans valider sa commande, son code promo sera réinitialisé : il sera néanmoins en mesure de le rentrer à nouveau pour en bénéficier une fois de retour sur la page commande.php.
<br />
<br />
<br />
<h3>Affichage des valeurs calculées par le plugin</h3>
<br />
<ul>
<li><img src="../client/plugins/incitation/img/down.png" style="float:left; margin:0 10px;" />L'affichage des <b>remises</b> : <br /><br />
<b>Incitation</b> utilise la session promo de Thélia ; de ce fait l'affichage de ses calculs pour les remises est totalement transparent : Incitation ne créée aucune balise supplémentaire ou substitution. Les valeurs rendues par les substitutions #PANIER_REMISE et #PANIER_TOTREMISE afficheront le montant des remises attribuées par vos incitations et le total de la commande diminué de ce montant alors que #PANIER_TOTAL affichera le montant du panier sans les remises.
</li><br />
<li><img src="../client/plugins/incitation/img/add.png" style="float:left; margin:0 10px;" />L'affichage des <b>références offertes</b> : <br /><br />
Comme tout produit, une référence offerte s'affiche automatiquement dans le panier, la commande, la facture... sans manipulation particulière.
</li><br />
<li><img src="../client/plugins/incitation/img/globe.png" style="float:left; margin:0 10px;" />L'affichage du <b>port offert</b> : <br /><br />
Le port est une valeur dynamique que Thélia calcule systématiquement avant de l'afficher. Le plugin incitation utilise donc les substitutions #PANIER_PORT et #PANIER_TOTPORT et les remplace avant Thélia. Cette manipulation a lieu sur ces substitutions si votre page comporte la variable <b>$incitation_active=1</b> (à ajouter sur transport.php pour générer la valeur exacte du port sur cette page).
</li>
</ul>
</div>
<div class="titre_cellule_tres_sombre" style="width:970px; height:20px;">
EXEMPLE
</div>
<div style="width:955px; border:#999999 dashed 1px;border-top:none; padding:10px;">
<br />
<br />
- Voici comment créer très simplement une promotion sur votre site : pour une commande atteignant 100€, 10% de remise. Pour une commmande atteignant 200€, 20% de remise.
<br />
<br />
- Sur la page code promo :
<img src="../client/plugins/incitation/img/exemple2.png" />
<br />
<br />
<br />
- Sur cette page module/incitation :
<img src="../client/plugins/incitation/img/exemple1.png" />
<br />
<br />
<br />
- Affichage du panier avec les balises Thélia :
<img src="../client/plugins/incitation/img/exemple3.png" />
<br />
</div>
</div>
</div>
<br />
<h3> Ottoroots - 2009</h3>
<img src="../client/plugins/incitation/img/email.png" style="float:left; margin-right:10px;"/>ottoroots@gmail.com <br />
<img src="../client/plugins/incitation/img/world.png" style="float:left; margin-right:10px;"/> www.cosmoweb.fr
</div>
</body>
</html>
et incitation.class.php:
<?php
include_once(realpath(dirname(__FILE__)) . "/../../../classes/PluginsClassiques.class.php");
include_once(realpath(dirname(__FILE__)) . "/../../../classes/Promo.class.php");
include_once(realpath(dirname(__FILE__)) . "/../../../classes/Commande.class.php");
include_once(realpath(dirname(__FILE__)) . "/../../../classes/Venteprod.class.php");
include_once(realpath(dirname(__FILE__)) . "/../../../classes/Produit.class.php");
class Incitation extends PluginsClassiques {
var $id;
var $type;
var $actif;
var $valref;
var $seuiltotal;
var $qtetotal;
var $prodpanier;
var $qteprod;
var $inclurepromo;
var $inclurenouveaute;
var $idpays;
var $table ="incitation";
var $bddvars = array ("id", "type", "actif", "valref", "seuiltotal", "qtetotal", "prodpanier", "qteprod", "inclurepromo", "idpays", "inclurenouveaute");
function Incitation(){
$this->PluginsClassiques("incitation");
}
function init(){
$query_incitation = "CREATE TABLE `incitation` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`type` TEXT ,
`actif` FLOAT ,
`valref` TEXT ,
`seuiltotal` FLOAT ,
`qtetotal` FLOAT ,
`prodpanier` TEXT ,
`qteprod` FLOAT ,
`inclurepromo` INT ,
`idpays` INT ,
`inclurenouveaute` INT
);";
$resul_incitation = mysql_query($query_incitation, $this->link);
$chargeref = new Incitation();
$chargeref->inclurepromo = 1;
$chargeref->inclurenouveaute = 1;
$chargeref->add();
}
function charger($id){
return $this->getVars("select * from $this->table where id=\"$id\"");
}
// Calcul combien de références offertes par Incitation sont enregistrées dans le panier
function nbre_bonusref() {
$nbre=0;
$query = "select * from $this->table where type=\"bonusref\" and actif=1";
$resul = mysql_query($query, $this->link);
while($bonusref = mysql_fetch_object($resul)){
for($i=0; $i<$_SESSION['navig']->panier->nbart; $i++){
if($_SESSION['navig']->panier->tabarticle[$i]->produit->ref==$bonusref->valref) $nbre++;
}
}
return $nbre;
}
// Calcul combien de références offertes par Incitation sont enregistrées dans une commande
function nbre_bonusref_commande($commande, $tab) {
$nbre=0;
$query = "select * from $this->table where type=\"bonusref\" and actif=1";
$resul = mysql_query($query, $this->link);
while($bonusref = mysql_fetch_object($resul)){
foreach($tab as $tab){
if($tab ==$bonusref->valref) $nbre++;
}
return $nbre;
}
}
// Conversion des sommes/pourcentages d'une remise pour l'entrée dans la session :
function convertir_valeur ($total, $valeur1, $type1, $type2) {
if ($type1 == $type2 ) {
echo '<br /><br />';
return $valeur1;
}
if ($type1 ==2 && $type2 ==1) {
$valeur = round ($valeur1*$total/100, 2);
return $valeur;
}
if ($type1 ==1 && $type2 ==2) {
$valeur = round ($valeur1*100/$total, 2);
return $valeur;
}
}
// Calcul préalable du total panier avec ou sans les nouveauté et promos
function total_incitation($bonusremise) {
$total = 0;
$taxe = 0;
for($i=0; $i<$_SESSION['navig']->panier->nbart; $i++){
$prix =0;
$quantite = $_SESSION['navig']->panier->tabarticle[$i]->quantite;
if( $_SESSION['navig']->panier->tabarticle[$i]->produit->promo == 0 && $_SESSION['navig']->panier->tabarticle[$i]->produit->nouveaute == 0)
$prix = $_SESSION['navig']->panier->tabarticle[$i]->produit->prix;
if ($_SESSION['navig']->panier->tabarticle[$i]->produit->promo == 1 && $_SESSION['navig']->panier->tabarticle[$i]->produit->nouveaute == 1) {
if ($bonusremise->inclurepromo ==1 && $bonusremise->inclurenouveaute == 1)
$prix = $_SESSION['navig']->panier->tabarticle[$i]->produit->prix2;
}
if ($_SESSION['navig']->panier->tabarticle[$i]->produit->promo == 0 && $_SESSION['navig']->panier->tabarticle[$i]->produit->nouveaute == 1) {
if ($bonusremise->inclurenouveaute ==1)
$prix = $_SESSION['navig']->panier->tabarticle[$i]->produit->prix;
}
if ($_SESSION['navig']->panier->tabarticle[$i]->produit->promo ==1 && $_SESSION['navig']->panier->tabarticle[$i]->produit->nouveaute == 0) {
if ($bonusremise->inclurepromo ==1)
$prix = $_SESSION['navig']->panier->tabarticle[$i]->produit->prix2;
}
if ($prix > 0) $prodtva = $_SESSION['navig']->panier->tabarticle[$i]->produit->tva;
$taxe += ($prix - ($prix/(1+$prodtva/100))) * $quantite;
$total += $prix*$quantite;
}
$pays = new Pays();
if($_SESSION['navig']->adresse != "" && $_SESSION['navig']->adresse != 0){
$adr = new Adresse();
$adr->charger($_SESSION['navig']->adresse);
$pays->charger($adr->pays);
}
else
$pays->charger($_SESSION['navig']->client->pays);
if($tva && $pays->tva != "" && (! $pays->tva || ($pays->tva && $_SESSION['navig']->client->intracom != "")))
$total -= $taxe;
return round($total, 2);
}
// Calcul préalable de la quantité d'articles du panier avec ou sans les nouveauté et promos et sans les références offertes
function quantite_incitation($bonusremise) {
$quantite=0;
for($i=0; $i<$_SESSION['navig']->panier->nbart; $i++){
if( ! $_SESSION['navig']->panier->tabarticle[$i]->produit->promo && ! $_SESSION['navig']->panier->tabarticle[$i]->produit->nouveaute)
$quantite += $_SESSION['navig']->panier->tabarticle[$i]->quantite;
elseif ($_SESSION['navig']->panier->tabarticle[$i]->produit->promo && $_SESSION['navig']->panier->tabarticle[$i]->produit->nouveaute) {
if ($bonusremise->inclurepromo ==1 && $bonusremise->inclurenouveaute ==1)
$quantite += $_SESSION['navig']->panier->tabarticle[$i]->quantite;
}
elseif (! $_SESSION['navig']->panier->tabarticle[$i]->produit->promo && $_SESSION['navig']->panier->tabarticle[$i]->produit->nouveaute) {
if ($bonusremise->inclurenouveaute ==1)
$quantite += $_SESSION['navig']->panier->tabarticle[$i]->quantite;
}
elseif ($_SESSION['navig']->panier->tabarticle[$i]->produit->promo && ! $_SESSION['navig']->panier->tabarticle[$i]->produit->nouveaute) {
if ($bonusremise->inclurepromo ==1)
$quantite += $_SESSION['navig']->panier->tabarticle[$i]->quantite;
}
}
$qte = $this->nbre_bonusref();
$quantite-=$qte;
return $quantite;
}
// Calcul la valeur d'une incitation de type remise si OK
function calcul_remise($bonusremise) {
$tpromo = new Promo();
$tpromo->charger($bonusremise->valref);
$total = $this->total_incitation($bonusremise);
//1°) Si soummission d'un code promo et code validé par Thélia : recalculer le total avant d'évaluer l'attribution de la remise.
if($_REQUEST['action']== "codepromo" && $_REQUEST['code']!=='' && $_REQUEST['code']== $_SESSION['navig']->promo->code){
$cpromo = new Promo();
$cpromo->charger($_SESSION['navig']->promo->code);
if($cpromo->type ==1){
$total-=$cpromo->valeur;
if($total>=$bonusremise->seuiltotal) $_SESSION['navig']->promo->valeur+=$this->convertir_valeur($total, $tpromo->valeur, $tpromo->type, 1);
}
if($cpromo->type ==2){
$cremise = round($cpromo->valeur*$total/100, 2);
$total-=$cremise;
if($total>=$bonusremise->seuiltotal) $_SESSION['navig']->promo->valeur+=$this->convertir_valeur($total, $tpromo->valeur, $tpromo->type, 2);
}
}
//2° Sinon : injecter la remise dans la session
else {
$_SESSION['navig']->promo->id = $tpromo->id;
$_SESSION['navig']->promo->code = $tpromo->code;
// Les remises se cumulent + la première remise dicte le type (somme ou pourcentage) enregistré dans la session pour toutes les autres remises qui seront converties au besoin:
if ($_SESSION['navig']->promo->type=='') $_SESSION['navig']->promo->type = $tpromo->type;
$_SESSION['navig']->promo->valeur += $this->convertir_valeur($total, $tpromo->valeur, $tpromo->type, $_SESSION['navig']->promo->type);
$_SESSION['navig']->promo->mini = $tpromo->mini;
$_SESSION['navig']->promo->utilise = $tpromo->utilise;
$_SESSION['navig']->promo->illimite = $tpromo->illimite;
$_SESSION['navig']->promo->datefin = $tpromo->datefin;
}
}
// ***************************************************************************************************************************************************
// ***************************************************************************************************************************************************
function action() {
// La fonction est exécutée sur les pages du site qui contiennent $incitation_active=1;
global $incitation_active;
if ($incitation_active !==1) return;
global $res;
// *************************Fonction remise***********************************************************************************************************
if ($_REQUEST['action']!=='codepromo') $_SESSION['navig']->promo = new Promo;
// Lister les incitation de type remise activées
$query = "select * from $this->table where type=\"remise\" and actif=1";
$resul = mysql_query($query, $this->link);
while($bonusremise = mysql_fetch_object($resul)){
$varqteprod = $this->quantite_incitation($bonusremise);
$total = $this->total_incitation($bonusremise);
$total -= $total* $_SESSION['navig']->client->pourcentage / 100;
// Conditions : remise active et code promo assigné et seuil total atteint et qantité prod atteinte :
if($bonusremise->valref !=='' && $total>=$bonusremise->seuiltotal && $varqteprod>=$bonusremise->qtetotal){
//1° Si aucune référence spécifique n'est exigée pour cette incitation :
if(!$bonusremise->prodpanier) {
$this->calcul_remise($bonusremise);
}
//2° Si une référence spécifique est exigée pour cette incitation :
else{
// La condition supp : si la référence spécifique est présente dans le panier et en quantité suffisante :
for($i=0; $i<$_SESSION['navig']->panier->nbart; $i++){
if($_SESSION['navig']->panier->tabarticle[$i]->produit->ref==$bonusremise->prodpanier && $_SESSION['navig']->panier->tabarticle[$i]->quantite>=$bonusremise->qteprod){
$this->calcul_remise($bonusremise);
}
}
}
}
}
// ********************************fonction port offert******************************************************************************************************
$query2 = "select * from $this->table where type=\"portoffert\" and actif=1";
$resul2 = mysql_query($query2, $this->link);
while($bonusportoffert = mysql_fetch_object($resul2)){
$varqteprod = $this->quantite_incitation($bonusportoffert);
$pays = $_SESSION['navig']->client->pays;
$total = $this->total_incitation($bonusportoffert);
$total -= $total* $_SESSION['navig']->client->pourcentage / 100;
$total2 = $_SESSION['navig']->panier->total();
$total2 -= $total2* $_SESSION['navig']->client->pourcentage / 100;
//Prise en compte d'un codepromo avant calcul
if ($_SESSION['navig']->promo->type==1) $total2 -= $_SESSION['navig']->promo->valeur;
if ($_SESSION['navig']->promo->type==2) $total2 -= round ($total*$_SESSION['navig']->promo->valeur/100, 2);
// conditions :
if ($total >= $bonusportoffert->seuiltotal && $varqteprod >= $bonusportoffert->qtetotal && $pays == $bonusportoffert->idpays){
//1° Si aucune référence spécifique n'est exigée pour cette incitation :
if (!$bonusportoffert->prodpanier){
$port= 0;
$res = str_replace("#PANIER_PORT", "$port", $res);
$res = str_replace("#PORT", "$port", $res);
$res = str_replace("#PANIER_TOTPORT", "$total2", $res);
}
// 2° sinon :
else{
for($i=0; $i<$_SESSION['navig']->panier->nbart; $i++){
if($_SESSION['navig']->panier->tabarticle[$i]->produit->ref==$bonusportoffert->prodpanier && $_SESSION['navig']->panier->tabarticle[$i]->quantite>=$bonusportoffert->qteprod){
$port= 0;
$res = str_replace("#PANIER_PORT", "$port", $res);
$res = str_replace("#PORT", "$port", $res);
$res = str_replace("#PANIER_TOTPORT", "$total2", $res);
}
}
}
}
}
//*******************************fonction référence offerte*********************************************************************************************
// 1°) rajouter le produit offert dans le panier si conditions remplies
$query3 = "select * from $this->table where type=\"bonusref\" and actif=1";
$resul3 = mysql_query($query3, $this->link);
$nbres = mysql_num_rows($resul3);
while($bonusref = mysql_fetch_object($resul3)){
$varqteprod = $this->quantite_incitation($bonusref);
$total = $this->total_incitation($bonusref);
$total -= $total* $_SESSION['navig']->client->pourcentage / 100;
$prodok=1;
if ($_SESSION['navig']->promo->type==1) $total -= $_SESSION['navig']->promo->valeur;
if ($_SESSION['navig']->promo->type==2) $total -= round ($total*$_SESSION['navig']->promo->valeur/100, 2);
if ($bonusref->valref !=="" && $total >= $bonusref->seuiltotal && $varqteprod >= $bonusref->qtetotal){
if (!$bonusref->prodpanier) $_SESSION['navig']->panier->ajouter($bonusref->valref, 1, "", "", "");
else {
$prodok=0;
for($i=0; $i<$_SESSION['navig']->panier->nbart; $i++){
if($_SESSION['navig']->panier->tabarticle[$i]->produit->ref==$bonusref->prodpanier && $_SESSION['navig']->panier->tabarticle[$i]->quantite>=$bonusref->qteprod){
$_SESSION['navig']->panier->ajouter($bonusref->valref, 1, "", "", "");
$prodok=1;
}
}
}
}
//2°) Supprimer le cadeau du panier si conditions non remplies
if ($total < $bonusref->seuiltotal || $varqteprod < $bonusref->qtetotal || $prodok==0){
for($i=0; $i<$_SESSION['navig']->panier->nbart; $i++){
if($_SESSION['navig']->panier->tabarticle[$i]->produit->ref==$bonusref->valref) {
$_SESSION['navig']->panier->supprimer($i);
break;
}
}
}
}
}
//******************* aprescommande() pour les incitation de type "port offert"*********************************************************************
function aprescommande($commande){
$query5 = "select * from $this->table where type=\"portoffert\" and actif=1";
$resul5 = mysql_query($query5, $this->link);
$nbres = mysql_num_rows($resul5);
for($compt=0; $compt<$_SESSION['navig']->panier->nbart; $compt++){
if($_SESSION['navig']->panier->tabarticle[$compt]->produit->ref!==$bonusref->bonus) $varqteprod += $_SESSION['navig']->panier->tabarticle[$compt]->quantite;
else continue;
}
while($bonusportoffert = mysql_fetch_object($resul5)){
$qte=0;
$total=0;
$pays = $_SESSION['navig']->client->pays;
$tab_venteprod = array();
$tab_venteprod_qte = array();
$venteprod = new Venteprod();
$query4 = "select * from $venteprod->table where commande=\"" . $commande->id . "\"";
$resul4 = mysql_query($query4, $venteprod->link);
while($venteprod = mysql_fetch_object($resul4)) {
$prodtemp = new Produit();
$prodtemp->charger($venteprod->ref);
if ($prodtemp->promo ==0 && $prodtemp->nouveaute ==0) {
$qte +=$venteprod->quantite;
$total += $prodtemp->prix*$qte;
$tab_venteprod[] = $Venteprod->ref;
$tab_venteprod_qte[] = $Venteprod->quantite;
}
if ($prodtemp->promo ==1 && $prodtemp->nouveaute ==1) {
if ($bonusportoffert->inclurepromo==1 && $bonusportoffert->inclurenouveaute ==1) {
$qte +=$venteprod->quantite;
$total += $prodtemp->prix2*$qte;
$tab_venteprod[] = $Venteprod->ref;
$tab_venteprod_qte[] = $Venteprod->quantite;
}
}
if ($prodtemp->promo ==0 && $prodtemp->nouveaute ==1) {
if ($bonusportoffert->inclurenouveaute ==1) {
$qte +=$venteprod->quantite;
$total += $prodtemp->prix*$qte;
$tab_venteprod[] = $Venteprod->ref;
$tab_venteprod_qte[] = $Venteprod->quantite;
}
}
if ($prodtemp->promo ==1 && $prodtemp->nouveaute ==0) {
if ($bonusportoffert->inclurepromo ==1) {
$qte +=$venteprod->quantite;
$total += $prodtemp->prix2*$qte;
$tab_venteprod[] = $Venteprod->ref;
$tab_venteprod_qte[] = $Venteprod->quantite;
}
}
$qte2 = $this->nbre_bonusref_commande($commande, $tab_venteprod);
$varqteprod = $qte - $qte2;
// conditions :
if ($total >= $bonusportoffert->seuiltotal && $varqteprod >= $bonusportoffert->qtetotal && $pays == $bonusportoffert->idpays){
//1° Si aucune référence spécifique n'est exigée pour cette incitation :
if (!$bonusportoffert->prodpanier){
$commande->port = 0;
$commande->maj();
return;
}
// 2° sinon :
if ($bonusportoffert->prodpanier){
$i=-1;
foreach($tab_venteprod as $v){
$i++;
if($v == $bonusportoffert->prodpanier && $tab_venteprod_qte[$i]>=$bonusportoffert->qteprod){
$commande->port = 0;
$commande->maj();
return;
}
}
}
}
}
}
}
function destroy(){
$query_incitation = "DROP TABLE `incitation`";
$resul_incitation = mysql_query($query_incitation, $this->link);
}
}
?>
Last edited by zarwal (17-10-2010 07:57:46)