Le bug provient de la ligne 100 du script client/plugins/sauvpanier/Sauvpanier.class.php : le unserialize($recsauv->panier) renvoie false.
Si je regarde dans la table sauvpanier, l'objet est sérialisé avec des backslashes en trop.
Est-il normal qu'on rajoute des slahes avec addslashes dans les méthodes post() et demarrage() de Sauvpanier.class.php, et qu'en plus on fasse un mysql_real_escape_string() sur la même variable dans Baseobj::getListValsSql() ? Comme on a backslashé par deux fois, la variable sérialisée est mal stockée dans la base de données.
Si je retire tous les addslashes() dans Sauvpanier.class.php, et que je purge la table sauvpanier, tout rentre dans l'ordre. C'est effectivement plus logique que la fonction qui génère la requête sql s'occupe de backslasher, et que le programmeur n'ai pas à s'inquiéter de ce backslash à tout bout de champ. D'ailleurs nulle part ailleurs dans le code ne subsiste d'appels à addslashes(). Des restes d'une ancienne version ?
Proposition d'une nouvelle version de Sauvpanier.class.php (supprimer les portions de codes que j'ai commenté) :
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) Octolys Development */
/* email : thelia@octolys.fr */
/* web : http://www.octolys.fr */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License, or */
/* (at your option) any later version. */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program; if not, write to the Free Software */
/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/* */
/*************************************************************************************/
?>
<?php
include_once(realpath(dirname(__FILE__)) . "/../../../classes/PluginsClassiques.class.php");
include_once(realpath(dirname(__FILE__)) . "/../../../classes/Panier.class.php");
include_once(realpath(dirname(__FILE__)) . "/../../../classes/Client.class.php");
class Sauvpanier extends PluginsClassiques{
var $id;
var $client;
var $panier;
var $date;
var $table="sauvpanier";
var $bddvars = array("id", "client", "panier", "date");
function Sauvpanier(){
$this->Baseobj();
}
function init(){
$cnx = new Cnx();
$query_sauvpanier = "CREATE TABLE `sauvpanier` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`client` INT NOT NULL ,
`panier` TEXT NOT NULL,
`date` datetime NOT NULL default '0000-00-00 00:00:00'
) ;";
$resul_sauvpanier = mysql_query($query_sauvpanier, $cnx->link);
}
function charger($client){
return $this->getVars("select * from $this->table where client=\"$client\"");
}
function post(){
if(($_REQUEST['action'] == "ajouter" || $_REQUEST['action'] == "supprimer") && $_SESSION['navig']->client->id){
$tempsauv = new Sauvpanier();
if($tempsauv->charger($_SESSION['navig']->client->id)){
$this->charger($_SESSION['navig']->client->id);
$this->panier = /*addslashes(*/serialize($_SESSION['navig']->panier)/*)*/;
$this->date = date("Y-m-d H:i:s");
$this->maj();
}
else {
$this->client = $_SESSION['navig']->client->id;
$this->panier = /*addslashes(*/serialize($_SESSION['navig']->panier)/*)*/;
$this->date = date("Y-m-d H:i:s");
$this->add();
}
}
}
function demarrage(){
if($_REQUEST['action'] == "connexion") {
$client = new Client();
if($client->charger($_REQUEST['email'], $_REQUEST['motdepasse'])){
$recsauv = new Sauvpanier();
if(! $recsauv->charger($client->id)){
$recsauv->client = $client->id;
$recsauv->panier = /*addslashes(*/serialize($_SESSION['navig']->panier)/*)*/;
$recsauv->date = date("Y-m-d H:i:s");
$recsauv->add();
return;
}
if(! $_SESSION['navig']->panier->nbart){
$_SESSION['navig']->panier = new Panier();
$_SESSION['navig']->panier = unserialize($recsauv->panier);
}
else {
$recsauv->panier = /*addslashes(*/serialize($_SESSION['navig']->panier)/*)*/;
$this->date = date("Y-m-d H:i:s");
$recsauv->maj();
}
}
}
}
}
?>