Jump to content

Tester si un client a au moins 1 bon de réduction valable en se connectant


Recommended Posts

Bonjour,

 

Je cherche un moyen de tester si un client qui se connecte à ma boutique possède encore au moins un bon d'achat valable attaché à son nom.

L'objectif est de le mettre automatiquement dans un groupe donné s'il n'a plus aucun coupon.

 

J'ai déjà le code pour le changer de groupe :

 




/* PFS ajouté pour affectation au groupe */
$id_customer = (int)$this->context->customer->id;
if (Db::getInstance()->getValue('
SELECT COUNT(*)
FROM `' . _DB_PREFIX_ . 'cart_rule`
WHERE id_customer = ' . $id_customer . '
AND `quantity` = 1'
) = 0)
{
$customer = new Customer($id_customer);
$id_special_group = 3;
$customer->cleanGroups();
$customer->addGroups(array($id_special_group));
$customer->id_default_group = $id_special_group;
}
/* PFS */


 


Merci de votre aide.

 

Bon week-end.

 

PFS

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

Bonjour,

 

J'ai créé un override de AuthController.php.

J'insère mon code, et je sais que l'interrogation de la BDD fonctionne, je l'ai testé par ailleurs.

 

Et pourtant, j'ai cette erreur :

Fatal error: Can't use method return value in write context in override/controllers/front/AuthController.php on line 15

La ligne 15 est : ") = 0)"

 

Voilà mon fichier d'override :

<?php
   class AuthController extends AuthControllerCore {
public function postProcess()
{
parent::postProcess();
   $id_customerPFS = (int)$this->context->customer->id;
       if (Db::getInstance()->getValue('
            SELECT COUNT(*)
            FROM `' . _DB_PREFIX_ . 'cart_rule` 
            WHERE `id_customer` = ' . $id_customerPFS . ' 
            AND `quantity` = 1'
            ) = 0)
{
$customer = new Customer($id_customerPFS);
$id_special_group = 3;
$customer->cleanGroups();
$customer->addGroups(array($id_special_group));
$customer->id_default_group = $id_special_group;
return true;
}
else {
$id_customerPFS = (int)$this->context->customer->id;
$customer = new Customer($id_customerPFS);
$id_special_group = 4;
$customer->cleanGroups();
$customer->addGroups(array($id_special_group));
$customer->id_default_group = $id_special_group;
return true;
}
}
}
?>
 
Merci de votre aide.
 
PFS
Edited by pfs007 (see edit history)
Link to comment
Share on other sites

Salut,

 

Tu dois etre en PHP 5, il faut que tu sortes ta requête du "if", fais comme ça :

   $toto = Db::getInstance()->getValue('
            SELECT COUNT(*)
            FROM `' . _DB_PREFIX_ . 'cart_rule`
            WHERE `id_customer` = ' . $id_customerPFS . '
            AND `quantity` = 1'
            );
       if ($toto = 0)
{
Edited by anteverce (see edit history)
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...