BookshopBookshop_caddyHandler::isCartEmpty()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
//  ------------------------------------------------------------------------ //
3
//                      BOOKSHOP - MODULE FOR XOOPS 2                        //
4
//                  Copyright (c) 2007, 2008 Instant Zero                    //
5
//                     <http://www.instant-zero.com/>                        //
6
// ------------------------------------------------------------------------- //
7
//  This program is free software; you can redistribute it and/or modify     //
8
//  it under the terms of the GNU General Public License as published by     //
9
//  the Free Software Foundation; either version 2 of the License, or        //
10
//  (at your option) any later version.                                      //
11
//                                                                           //
12
//  You may not change or alter any portion of this comment or credits       //
13
//  of supporting developers from this source code or any supporting         //
14
//  source code which is considered copyrighted (c) material of the          //
15
//  original comment or credit authors.                                      //
16
//                                                                           //
17
//  This program is distributed in the hope that it will be useful,          //
18
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
19
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
20
//  GNU General Public License for more details.                             //
21
//                                                                           //
22
//  You should have received a copy of the GNU General Public License        //
23
//  along with this program; if not, write to the Free Software              //
24
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
25
//  ------------------------------------------------------------------------ //
26
27
defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined');
28
29
define('CADDY_NAME', 'bookshop_caddie');
30
31
include_once XOOPS_ROOT_PATH . '/kernel/object.php';
32
if (!class_exists('Bookshop_XoopsPersistableObjectHandler')) {
33
    include_once XOOPS_ROOT_PATH . '/modules/bookshop/class/PersistableObjectHandler.php';
34
}
35
36
/**
37
 * Class bookshop_caddy
38
 */
39 View Code Duplication
class bookshop_caddy extends Bookshop_Object
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
40
{
41
    public function __construct()
42
    {
43
        $this->initVar('caddy_id', XOBJ_DTYPE_INT, null, false);
44
        $this->initVar('caddy_book_id', XOBJ_DTYPE_INT, null, false);
45
        $this->initVar('caddy_qte', XOBJ_DTYPE_INT, null, false);
46
        $this->initVar('caddy_price', XOBJ_DTYPE_TXTBOX, null, false);
47
        $this->initVar('caddy_cmd_id', XOBJ_DTYPE_INT, null, false);
48
        $this->initVar('caddy_shipping', XOBJ_DTYPE_TXTBOX, null, false);
49
    }
50
}
51
52
/**
53
 * Class BookshopBookshop_caddyHandler
54
 */
55
class BookshopBookshop_caddyHandler extends Bookshop_XoopsPersistableObjectHandler
56
{
57
    /**
58
     * @param $db
59
     */
60
    public function __construct($db)
61
    {    //                                         Table               Classe          Id
62
        parent::__construct($db, 'bookshop_caddy', 'bookshop_caddy', 'caddy_id');
63
    }
64
65
    /**
66
     * Renvoie, si on en trouve un, un livre qui s'est bien vendu avec un livre particulier
67
     *
68
     * @param  integer $caddy_book_id Identifiant du livre dont on recherche le jumeau
69
	 * @return integer Le n° du livre le plus vendu avec le livre en question
70
     */
71
    public function getBestWith($caddy_book_id)
72
    {
73
        $sql    = 'SELECT caddy_book_id, sum(caddy_qte) mv FROM ' . $this->table . ' WHERE caddy_cmd_id IN (SELECT caddy_cmd_id FROM ' . $this->table . ' WHERE caddy_book_id=' . (int)$caddy_book_id . ') GROUP BY caddy_book_id ORDER BY mv DESC';
74
        $result = $this->db->query($sql, 1);
75
        if (!$result) {
76
            return 0;
77
        }
78
        $myrow = $this->db->fetchArray($result);
79
80
        return $myrow['caddy_book_id'];
81
    }
82
83
    /**
84
	 * Renvoie la liste des livres les plus vendus dans une catégorie particulière
85
     *
86
	 * @param integer $book_cid Catégorie des livres
87
	 * @param integer $start Début de la recherche
88
	 * @param integer $limit Nombre maximum d'enregistrements à retourner
89
	 * @param boolean $withQuantity Faut il renvoyer les quantités vendues ?
90
	 * @return array Les identifiants des X livres les plus vendus dans cette catégorie
91
     */
92
    public function getMostSoldBooksInCategory($book_cid, $start = 0, $limit = 0, $withQuantity = false)
93
    {
94
        $ret = array();
95
        if (!is_array($book_cid)) {
96
            if ($book_cid > 0) {
97
                $sql = 'SELECT c.caddy_book_id, sum( c.caddy_qte ) AS mv FROM ' . $this->table . ' c, ' . $this->db->prefix('bookshop_books') . ' b WHERE (c.caddy_book_id = b.book_id) AND b.book_cid = ' . (int)$book_cid . ' GROUP BY c.caddy_book_id ORDER BY mv DESC';
98
            } else {
99
                $sql = 'SELECT c.caddy_book_id, sum( c.caddy_qte ) AS mv FROM ' . $this->table . ' c, ' . $this->db->prefix('bookshop_books') . ' b WHERE (c.caddy_book_id = b.book_id) GROUP BY c.caddy_book_id ORDER BY mv DESC';
100
            }
101
        } else {
102
            $sql = 'SELECT c.caddy_book_id, sum( c.caddy_qte ) AS mv FROM ' . $this->table . ' c, ' . $this->db->prefix('bookshop_books') . ' b WHERE (c.caddy_book_id = b.book_id) AND b.book_cid IN (' . implode(',', $book_cid) . ') GROUP BY c.caddy_book_id ORDER BY mv DESC';
103
        }
104
        $result = $this->db->query($sql, $limit, $start);
105
        if ($result) {
106
            while ($myrow = $this->db->fetchArray($result)) {
107
                if (!$withQuantity) {
108
                    $ret[] = $myrow['caddy_book_id'];
109
                } else {
110
                    $ret[$myrow['caddy_book_id']] = $myrow['mv'];
111
                }
112
            }
113
        }
114
115
        return $ret;
116
    }
117
118
    /**
119
	 * Renvoie la liste des livres les plus vendus toutes catégories confondues
120
     *
121
	 * @param integer $start Début de la recherche
122
	 * @param integer $limit Nombre maximum d'enregistrements à retourner
123
	 * @return array Les identifiants des X livres les plus vendus dans cette catégorie
124
     */
125 View Code Duplication
    public function getMostSoldBooks($start = 0, $limit = 0)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
126
    {
127
        $ret    = array();
128
        $sql    = 'SELECT caddy_book_id, sum( caddy_qte ) as mv FROM ' . $this->table . ' GROUP BY caddy_book_id ORDER BY mv DESC';
129
        $result = $this->db->query($sql, $limit, $start);
130
        if ($result) {
131
            while ($myrow = $this->db->fetchArray($result)) {
132
                $ret[] = $myrow['caddy_book_id'];
133
            }
134
        }
135
136
        return $ret;
137
    }
138
139
    /**
140
	 * Calcul du caddy à partir du tableau en session qui se présente sous la forme :
141
     *  $datas['number'] = indice du produit
142
     *  $datas['id'] = Identifiant du livre
143
	 * 	$datas['qty'] = Quantité voulue
144
     *
145
	 * @param array $cartForTemplate Contenu du caddy à passer au template (en fait la liste des produits)
146
     * @param        boolean               emptyCart Indique si le panier est vide ou pas
147
     * @param float  $shippingAmount       Montant des frais de port
148
     * @param float  $commandAmount        Montant HT de la commande
149
     * @param float  $vatAmount            VAT amount
150
	 * @param string $goOn Adresse vers laquelle renvoyer le visiteur après qu'il ait ajouté un produit dans son panier (cela correspond en fait à la catégorie du dernier livre ajouté dans le panier)
151
	 * @param float $commandAmountTTC Montant TTC de la commande
152
	 * @param array $discountsDescription Descriptions des remises appliquées
153
     */
154
    public function computeCart(&$cartForTemplate, &$emptyCart, &$shippingAmount, &$commandAmount, &$vatAmount, &$goOn, &$commandAmountTTC, &$discountsDescription)
155
    {
156
        global $h_bookshop_authors, $h_bookshop_books, $h_bookshop_booksauthors, $h_bookshop_cat, $h_bookshop_vat, $h_bookshop_discounts;
157
        if ($this->isCartEmpty()) {    // Pas de caddie
158
            $emptyCart = true;
159
        } else {
160
            $emptyCart  = false;
161
            $tblCaddie  = array();
0 ignored issues
show
Unused Code introduced by
$tblCaddie is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
162
            $tblCaddie  = isset($_SESSION[CADDY_NAME]) ? $_SESSION[CADDY_NAME] : array();
163
            $caddyCount = count($tblCaddie);
164
            if ($caddyCount > 0) {
165
                $cpt                = 0;
166
                $fraisPort          = 0;
0 ignored issues
show
Unused Code introduced by
$fraisPort is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
167
                $totalBooksQuantity = 0;
168
                $tblVat             = array();
0 ignored issues
show
Unused Code introduced by
$tblVat is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
169
                if (!is_object($h_bookshop_vat)) {
170
                    $h_bookshop_vat = xoops_getModuleHandler('bookshop_vat', BOOKSHOP_DIRNAME);
171
                }
172
                if (!is_object($h_bookshop_books)) {
173
                    $h_bookshop_books = xoops_getModuleHandler('bookshop_books', BOOKSHOP_DIRNAME);
174
                }
175
                if (!is_object($h_bookshop_cat)) {
176
                    $h_bookshop_cat = xoops_getModuleHandler('bookshop_cat', BOOKSHOP_DIRNAME);
177
                }
178
                if (!is_object($h_bookshop_booksauthors)) {
179
                    $h_bookshop_booksauthors = xoops_getModuleHandler('bookshop_booksauthors', BOOKSHOP_DIRNAME);
180
                }
181
                if (!is_object($h_bookshop_authors)) {
182
                    $h_bookshop_authors = xoops_getModuleHandler('bookshop_authors', BOOKSHOP_DIRNAME);
183
                }
184
                if (!is_object($h_bookshop_discounts)) {
185
                    $h_bookshop_discounts = xoops_getModuleHandler('bookshop_discounts', BOOKSHOP_DIRNAME);
186
                }
187
                $tblVat = $h_bookshop_vat->GetAllVats();
188
                foreach ($tblCaddie as $produit) {
189
                    $datas       = array();
0 ignored issues
show
Unused Code introduced by
$datas is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
190
                    $book_id     = $produit['id'];
191
                    $book_number = $produit['number'];
192
                    $book_qte    = $produit['qty'];
193
                    $book        = null;
0 ignored issues
show
Unused Code introduced by
$book is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
194
                    $book        = $h_bookshop_books->get($book_id);
195
                    $totalBooksQuantity += $produit['qty'];
196
                    if (!is_object($book)) {
197
                        exit(_BOOKSHOP_ERROR9);
198
                    }
199
                    ++$cpt;
200
                    if ($cpt == $caddyCount) {    // On arrive sur le dernier livre
201
                        $category = null;
0 ignored issues
show
Unused Code introduced by
$category is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
202
                        $category = $h_bookshop_cat->get($book->getVar('book_cid'));
203
                        if (is_object($category)) {
204
                            $goOn = $h_bookshop_cat->GetCategoryLink($category->getVar('cat_cid'), $category->getVar('cat_title'));
205
                        }
206
                    }
207
                    $datas = $book->toArray();
208
                    // Recherche des auteurs
209
                    $tblTmp = $tblTmp2 = $tblAuteurs = $tblJoin = array();
0 ignored issues
show
Unused Code introduced by
$tblAuteurs is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
Unused Code introduced by
$tblTmp is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
210
                    $tblTmp = $h_bookshop_booksauthors->getObjects(new Criteria('ba_book_id', $book_id, '='), true);
211
                    foreach ($tblTmp as $item) {
212
                        if ($item->getVar('ba_type') == 1) {
213
                            $tblTmp2[] = $item->getVar('ba_auth_id');    // Que les auteurs
214
                        }
215
                    }
216
                    $tblAuteurs = $h_bookshop_authors->getObjects(new Criteria('auth_id', '(' . implode(',', $tblTmp2) . ')', 'IN'), true);
217
                    foreach ($tblAuteurs as $item) {
218
                        $tblJoin[] = $item->getVar('auth_firstname') . ' ' . $item->getVar('auth_name');
219
                    }
220
                    if (count($tblJoin) > 0) {
221
                        $datas['book_joined_authors'] = implode(', ', $tblJoin);
222
                    }
223
                    $datas['book_number'] = $book_number;
224
225
                    // Calculs "financiers" ***************************************************************************
226
                    if ($book->getVar('book_discount_price') > 0) {
227
                        $ht = (float)$book->getVar('book_discount_price');
228
                    } else {
229
                        $ht = (float)$book->getVar('book_price');
230
                    }
231
                    $htDiscounted   = $ht;
232
                    $fraisPortLivre = (float)$book->getVar('book_shipping_price');
233
                    $h_bookshop_discounts->applyDiscountOnEachBook($book_id, $htDiscounted, $discountsDescription, $book_qte, $fraisPortLivre);
234
                    $prixReelHT = $htDiscounted * $book_qte;
235
                    $vatRate    = $tblVat[$book->getVar('book_vat_id')]->getVar('vat_rate');
236
                    $montantTVA = bookshop_getVAT($prixReelHT, $vatRate);
237
                    $fraisPort  = $fraisPortLivre * $book_qte;
238
                    $totalTTC   = $prixReelHT + $montantTVA + $fraisPort;
239
240
                    $datas['book_price_normal_ht']     = sprintf('%0.' . bookshop_getmoduleoption('decimals_count') . 'f', $ht);
241
                    $datas['book_price_discounted_ht'] = sprintf('%0.' . bookshop_getmoduleoption('decimals_count') . 'f', $htDiscounted);
242
                    $datas['book_qty']                 = $book_qte;
243
                    $datas['book_price_ht']            = sprintf('%0.' . bookshop_getmoduleoption('decimals_count') . 'f', $prixReelHT);
244
                    $datas['book_vat_rate']            = sprintf('%0.' . bookshop_getmoduleoption('decimals_count') . 'f', $vatRate);
245
                    $datas['book_vat_amount']          = sprintf('%0.' . bookshop_getmoduleoption('decimals_count') . 'f', $montantTVA);
246
                    $datas['book_shipping_amount']     = sprintf('%0.' . bookshop_getmoduleoption('decimals_count') . 'f', $fraisPort);
247
                    $datas['book_price_ttc']           = sprintf('%0.' . bookshop_getmoduleoption('decimals_count') . 'f', $totalTTC);
248
                    $cartForTemplate[]                 = $datas;
249
250
                    // Les cumuls (dans les variables "globales")
251
                    $shippingAmount += $fraisPort;
252
                    $commandAmount += $prixReelHT;
253
                    $vatAmount += $montantTVA;
254
                }
255
				// Règles sur TOUS les livres
256
                $h_bookshop_discounts->applyDiscountOnAllBooks($commandAmount, $discountsDescription, $totalBooksQuantity);
257
258
				// Règles sur les frais de port
259
                $h_bookshop_discounts->applyDiscountOnShipping($shippingAmount, $discountsDescription, $totalBooksQuantity);
260
261
				// Règles (n°2) sur les frais de port
262
                $h_bookshop_discounts->applyDiscountOnShipping2($shippingAmount, $commandAmount, $discountsDescription, $totalBooksQuantity);
263
264
				// Règles sur le montant global de la commande
265
                $commandAmountTTC = $shippingAmount + $commandAmount + $vatAmount;
266
                $h_bookshop_discounts->applyDiscountOnCommand($commandAmountTTC, $discountsDescription);
267
            }
268
        }
269
    }
270
271
    /**
272
     * Indique si le caddy est vide ou pas
273
     *
274
     * @return boolean vide, ou pas...
275
     */
276
    public function isCartEmpty()
277
    {
278
        if (isset($_SESSION[CADDY_NAME])) {
279
            return false;
280
        } else {
281
            return true;
282
        }
283
    }
284
285
    /**
286
     * Vidage du caddy, s'il existe
287
     */
288
    public function emptyCart()
289
    {
290
        if (isset($_SESSION[CADDY_NAME])) {
291
            unset($_SESSION[CADDY_NAME]);
292
        }
293
    }
294
295
    /**
296
     * Ajout d'un produit au caddy
297
     *
298
     * @param integer $book_id  Identifiant du livre
299
	 * @param integer $quantity Quantité à ajouter
300
     */
301
    public function addProduct($book_id, $quantity)
302
    {
303
        $tbl_caddie = $tbl_caddie2 = array();
304
        if (isset($_SESSION[CADDY_NAME])) {
305
            $tbl_caddie = $_SESSION[CADDY_NAME];
306
        }
307
        $exists = false;
308
        foreach ($tbl_caddie as $produit) {
309
            if ($produit['id'] == $book_id) {
310
                $exists = true;
311
                $produit['qty'] += $quantity;
312
            }
313
            $tbl_caddie2[] = $produit;
314
        }
315
        if (!$exists) {
316
            $datas                = array();
317
            $datas['number']      = count($tbl_caddie) + 1;
318
            $datas['id']          = $book_id;
319
            $datas['qty']         = $quantity;
320
            $tbl_caddie[]         = $datas;
321
            $_SESSION[CADDY_NAME] = $tbl_caddie;
322
        } else {
323
            $_SESSION[CADDY_NAME] = $tbl_caddie2;
324
        }
325
    }
326
327
    /**
328
     * Suppression d'un produit du caddy
329
     *
330
	 * @param integer $indice Indice de l'élément à supprimer
331
     */
332
    public function deleteProduct($indice)
333
    {
334
        $tbl_caddie = array();
0 ignored issues
show
Unused Code introduced by
$tbl_caddie is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
335
        if (isset($_SESSION[CADDY_NAME])) {
336
            $tbl_caddie = $_SESSION[CADDY_NAME];
337
            if (isset($tbl_caddie[$indice])) {
338
                unset($tbl_caddie[$indice]);
339
                if (count($tbl_caddie) > 0) {
340
                    $_SESSION[CADDY_NAME] = $tbl_caddie;
341
                } else {
342
                    unset($_SESSION[CADDY_NAME]);
343
                }
344
            }
345
        }
346
    }
347
348
    /**
349
	 * Mise à jour des quantités du caddy suite à la validation du formulaire du caddy
350
     */
351
    public function updateQuantites()
352
    {
353
        global $h_bookshop_books;
354
        $tbl_caddie = $tbl_caddie2 = array();
0 ignored issues
show
Unused Code introduced by
$tbl_caddie is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
355
        if (isset($_SESSION[CADDY_NAME])) {
356
            $tbl_caddie = $_SESSION[CADDY_NAME];
357
            foreach ($tbl_caddie as $produit) {
358
                $number = $produit['number'];
359
                $name   = 'qty_' . $number;
360
                if (isset($_POST[$name])) {
361
                    $valeur = (int)$_POST[$name];
362
                    if ($valeur > 0) {
363
                        $book_id = $produit['id'];
364
                        $book    = null;
0 ignored issues
show
Unused Code introduced by
$book is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
365
                        $book    = $h_bookshop_books->get($book_id);
366
                        if (is_object($book)) {
367
                            if ($book->getVar('book_stock') - $valeur > 0) {
368
                                $produit['qty'] = $valeur;
369
                                $tbl_caddie2[]  = $produit;
370
                            } else {
371
                                $produit['qty'] = $book->getVar('book_stock');
372
                                $tbl_caddie2[]  = $produit;
373
                            }
374
                        }
375
                    }
376
                }
377
            }
378
            if (count($tbl_caddie2) > 0) {
379
                $_SESSION[CADDY_NAME] = $tbl_caddie2;
380
            } else {
381
                unset($_SESSION[CADDY_NAME]);
382
            }
383
        }
384
    }
385
386
    /**
387
	 * Renvoie les éléments constituants une commande
388
     *
389
     * @param  integer $caddy_cmd_id Identifiant de la commande
390
     * @return array   Tableau d'objets caddy
391
     */
392
    public function getCaddyFromCommand($caddy_cmd_id)
393
    {
394
        $ret     = array();
0 ignored issues
show
Unused Code introduced by
$ret is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
395
        $critere = new Criteria('caddy_cmd_id', $caddy_cmd_id, '=');
396
        $ret     = $this->getObjects($critere);
397
398
        return $ret;
399
    }
400
401
    /**
402
	 * Renvoie les ID de commandes pour un livre acheté
403
     *
404
     * @param  integer $book_id Identifiant du livre
405
	 * @return array Les ID des commandes dans lesquelles ce livre a été commandé
406
     */
407 View Code Duplication
    public function getCommandIdFromBook($book_id)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
408
    {
409
        $ret    = array();
410
        $sql    = 'SELECT caddy_cmd_id FROM ' . $this->table . ' WHERE caddy_book_id=' . (int)$book_id;
411
        $result = $this->db->query($sql);
412
        if (!$result) {
413
            return $ret;
414
        }
415
        while ($myrow = $this->db->fetchArray($result)) {
416
            $ret[] = $myrow['caddy_cmd_id'];
417
        }
418
419
        return $ret;
420
    }
421
}
422