IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

Addition au panier


Sujet :

Langage PHP

  1. #1
    Futur Membre du Club
    Homme Profil pro
    Développeur Web
    Inscrit en
    Mars 2020
    Messages
    15
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Charente (Poitou Charente)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mars 2020
    Messages : 15
    Points : 9
    Points
    9
    Par défaut Addition au panier
    Bonjour à vous, j'ai un problème avec le panier d'un de mes projets.
    Je vous explique:

    J'ai actuellement 2 produit dans mon panier qui est égale a 229,60€.
    Cependant mon calcul final quand j'addition tout sa j'obtiens 230,60€

    Sa c'est pour calculer le prix d'un produit grâce a sa quantité
    Je vous met mon code ci-dessous:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
     
    <?php $panier = $db->executeQuery('SELECT * FROM panier WHERE user_id = ? ORDER BY id DESC', array($userInfo[0]['id']));
                            foreach ($panier as $paniers) { 
     
                            $produits = $db->executeQuery('SELECT * FROM produit WHERE produit = ? ORDER BY id', array($paniers["produit_id"]));
                            $images = $db->executeQuery('SELECT * FROM produit_image WHERE produit_id = ? ORDER BY id limit 1', array($paniers["produit_id"]));
                            ?>
                                        <tr class="product-row">
                                            <td class="product-col">
                                                <figure class="product-image-container">
                                                    <a href="./produit_voir?produit=<?php echo $produits[0]["produit"]; ?>" class="product-image">
                                                        <img src="./assets/boutique/<?php echo $images[0]["images"]; ?>" alt="product">
                                                    </a>
                                                </figure>
                                                <h2 class="product-title">
                                                    <p><span><?php echo $produits[0]["titre"]; ?></span><br>
                                        <span>Taille: <?php echo $paniers["taille"]; ?></span><br>
                                        <span>Couleur: <?php echo $paniers["couleur"]; ?></span><br>
                                        <span>Catégorie: <?php echo $produits[0]["categorie"]; ?></span><br>
                                        <span>Sous catégorie: <?php echo $produits[0]["sous_categorie"]; ?></span><br>
                                    </p>
                                                </h2>
                                            </td>
                                            <td><?php echo $produits[0]["prix"]; ?>€</td>
                                            <td>
                                                <?php echo $paniers["quantiter"]; ?>
                                            </td>
                                            <td><?php 
                                        $montant = ($paniers["quantiter"] * $produits[0]["prix"]);
                                        $total = 0;
                                        $total = $montant + $total;
                                        $superTotal += $total;
                                        echo $total;
                                    ?>€ <a href="./panier?id=<?php echo $paniers["id"]; ?>" title="Remove product" class="btn-remove"><span class="sr-only">Remove</span></a></td>
                                        </tr>
     
     
                                        <?php } ?>
    Ensuite pour mon total sa donne sa :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
     
    <td><?php
                                        $panniers1 = $db->executeQuery('SELECT * FROM panier WHERE user_id = ?', array($userInfo[0]["id"]));
                                        if ($panniers1[0]['user_id'] == 0) 
                                        { ?>
     
                                                0.00€
     
                                        <?php } else { ?>
     
                                        <?php
                                               echo $superTotal; 
                                        ?>€
     
                                        <?php } ?></td>
    Voila le screen de la page pour vous donner une idée de ce que sa donne : https://prnt.sc/sbdggy

    J'espère que vous pourrais m'aidée.
    Si vous voulez me contacter je suis joignable par email : bernard-dylan@outlook.fr
    Ou sur discord : dylan_brnd#9682

  2. #2
    Membre averti Avatar de Freudd
    Homme Profil pro
    Développeur Web
    Inscrit en
    Avril 2014
    Messages
    165
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 31
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2014
    Messages : 165
    Points : 379
    Points
    379
    Par défaut
    Bonjour ,

    Je ne vois pas la déclaration de la variable $superTotal. Tu l'as bien initialisé à 0 ?

  3. #3
    Membre à l'essai
    Homme Profil pro
    Conseiller Technique
    Inscrit en
    Décembre 2018
    Messages
    11
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Conseiller Technique

    Informations forums :
    Inscription : Décembre 2018
    Messages : 11
    Points : 10
    Points
    10
    Par défaut
    C'est moi ou le code est un vrai bazar?

  4. #4
    Membre confirmé Avatar de ma5t3r
    Homme Profil pro
    Développeur freelance
    Inscrit en
    Mai 2015
    Messages
    320
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur freelance
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mai 2015
    Messages : 320
    Points : 492
    Points
    492
    Par défaut
    Le temps de lire ton post, on n'a plus envie de répondre à ton problème.
    J'attache trop d'importance à ma langue natale pour passer outre tes fautes d'orthographe et de grammaire trop nombreuses. C'est fatigant de lire un "truc" pareil.
    Comprendre ton post demande plus d'effort que résoudre le problème.

    Bordel di diou !

  5. #5
    Futur Membre du Club
    Homme Profil pro
    Développeur Web
    Inscrit en
    Mars 2020
    Messages
    15
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Charente (Poitou Charente)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mars 2020
    Messages : 15
    Points : 9
    Points
    9
    Par défaut
    Citation Envoyé par Zoki_Marciano Voir le message
    C'est moi ou le code est un vrai bazar?
    Ne t'inquiète pas il est bien ranger sur mon logiciel c'est juste que j'ai fait un copier-coller.

    Citation Envoyé par Freudd Voir le message
    Je ne vois pas la déclaration de la variable $superTotal. Tu l'as bien initialisé à 0 ?
    Bonjour, pourrais-tu m'en dire plus sur cette fameuse déclaration et ou la placer dans mon code ?

    Citation Envoyé par ma5t3r Voir le message
    Le temps de lire ton post, on n'a plus envie de répondre à ton problème...
    Bonjour je suis désoler, mais malheureusement j'ai beaucoup de difficulté avec le français, mais j'essaye de m'améliorer comme je peux...
    C'est dommage d'avoir des gens comme toi qui juge sans savoir le passé de chacun, et tout de suite critiquer.
    Ça c'est fatigant d'avoir des gens comme toi dans la vie de tous les jours sa ne donnent pas envie de réussir, c'est découragé.

  6. #6
    Invité
    Invité(e)
    Par défaut
    Bonjour,

    peux-tu montrer le code complet ?

  7. #7
    Futur Membre du Club
    Homme Profil pro
    Développeur Web
    Inscrit en
    Mars 2020
    Messages
    15
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Charente (Poitou Charente)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mars 2020
    Messages : 15
    Points : 9
    Points
    9
    Par défaut
    Bonjour, pas de problème je te partage ma page complet:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
     
    <?php 
      // Connexion au service
      include("./global.php");
     
      // Identification des page 
      $pageid = "panier";
     
        // Supprimer un élément du panier 
      if(isset($_GET['id'])) {
            if(is_numeric($_GET['id'])) {
                $db->executeInsert('DELETE FROM panier WHERE id = ?', array($_GET['id']));
                $ok = "";
        }
      }
      // Ajouter un code promo
      if(isset($_POST['add_code'])) {
        $code = ($_POST['code']);
            $check_code2 = $db->executeQuery('SELECT COUNT(*) AS count_row FROM codepromo WHERE code = ?', array($code));
            if($check_code2[0]["count_row"] == 0)
            {
     
            $ok3 = "";
            }
            $check_code2 = $db->executeQuery('SELECT COUNT(*) AS count_row FROM codepromo WHERE code = ? and activer = ?', array($code,"0"));
            if($check_code2[0]["count_row"] == 1)
            {
            $ok4 = "";
            }
            $check_code = $db->executeQuery('SELECT COUNT(*) AS count_row FROM codepromo WHERE code = ? and activer = ?', array($code,"1"));
            if($check_code[0]["count_row"] == 1)
            {
            if(empty($errorNews)) {
            $date = date("d-m-Y à H:i"); 
            $codepromo = $db->executeQuery("SELECT * FROM codepromo WHERE code = ? ", array($code));
            $db->executeInsert('INSERT INTO panier_code (user_id,code,prix) VALUES (?,?,?)', array($userInfo[0]["id"],$code,$codepromo[0]["prix"]));
            $ok1 = "";
          }
        }
      }
     
        // Ajouter une livraison
      if(isset($_POST['livraison'])) {
        $typelivraison = ($_POST['typelivraison']);
            if(empty($errorNews)) {
            $tarrif = $db->executeQuery("SELECT * FROM livraison_tarrif WHERE pays = ? and type = ? ", array($userInfo[0]["pays"],$typelivraison));
            $db->executeInsert('INSERT INTO panier_livraison (user_id,pays,prix,type) VALUES (?,?,?,?)', array($userInfo[0]["id"],$userInfo[0]["pays"],$tarrif[0]['prix'],$tarrif[0]['type']));
            $ok5 = "";
        }
      }
     
        //Supprimer une livraison
      if(isset($_GET['supp_livraison'])) {
            if(is_numeric($_GET['supp_livraison'])) {
                $db->executeInsert('DELETE FROM panier_livraison WHERE id = ?', array($_GET['supp_livraison']));
                $ok6 = "";
        }
      }
     
      //Supprimer un code promo 
      if(isset($_GET['suppcode'])) {
            if(is_numeric($_GET['suppcode'])) {
                $db->executeInsert('DELETE FROM panier_code WHERE id = ?', array($_GET['suppcode']));
                $ok2 = "";
        }
      }
    ?>
    <!DOCTYPE html>
    <!-- Une réalisation de Dylan tout droit réserver -->
    <html lang="fr">
    <head>
        <?php include './configuration.php'; ?>
        <title><?php echo $infoweb[0]["nomdusite"]; ?> | Panier</title>
        <?php include './style.php'; ?>
    </head>
     
    <body>
        <div class="page-wrapper">
           <?php include './menu.php'; ?>
           <?php if(isset($ok)) { ?>
                                <script type="text/javascript">Swal.fire({
                                      icon: 'success',
                                      title: 'Articles supprimer du panier.',
                                      showConfirmButton: false,
                                      timer: 2500
                                      })
                                </script>
                            <?php } ?>
                            <?php if(isset($ok1)) { ?>
                                <script type="text/javascript">Swal.fire({
                                      icon: 'success',
                                      title: 'Code promo ajouter',
                                      showConfirmButton: false,
                                      timer: 2500
                                      })
                                </script>
                            <?php } ?>
                            <?php if(isset($ok2)) { ?>
                                <script type="text/javascript">Swal.fire({
                                      icon: 'success',
                                      title: 'Code promo supprimer',
                                      showConfirmButton: false,
                                      timer: 2500
                                      })
                                </script>
                            <?php } ?>
                             <?php if(isset($ok3)) { ?>
                                <script type="text/javascript">Swal.fire({
                                      icon: 'error',
                                      title: 'Oups, ce code promo n\'existe pas!',
                                      showConfirmButton: false,
                                      timer: 2500
                                      })
                                </script>
                            <?php } ?>
                            <?php if(isset($ok4)) { ?>
                                <script type="text/javascript">Swal.fire({
                                      icon: 'error',
                                      title: 'Oups, ce code promo est désactiver',
                                      showConfirmButton: false,
                                      timer: 2500
                                      })
                                </script>
                            <?php } ?>
                            <?php if(isset($ok5)) { ?>
                                <script type="text/javascript">Swal.fire({
                                      icon: 'success',
                                      title: 'Frais de livraison ajouter.',
                                      showConfirmButton: false,
                                      timer: 2500
                                      })
                                </script>
                            <?php } ?>
                            <?php if(isset($ok6)) { ?>
                                <script type="text/javascript">Swal.fire({
                                      icon: 'success',
                                      title: 'Prix de livraison supprimer',
                                      showConfirmButton: false,
                                      timer: 2500
                                      })
                                </script>
                            <?php } ?>
             <main class="main">
                <nav aria-label="breadcrumb" class="breadcrumb-nav">
                    <div class="container">
                        <ol class="breadcrumb">
                            <li class="breadcrumb-item"><a href="./index"><i class="icon-home"></i></a></li>
                            <li class="breadcrumb-item active" aria-current="page">Panier</li>
                        </ol>
                    </div><!-- End .container -->
                </nav>
                <div class="container">
                    <?php
                                        $panniers1 = $db->executeQuery('SELECT * FROM panier WHERE user_id = ?', array($userInfo[0]["id"]));
                                        if ($panniers1[0]['user_id'] == 0) 
                                        { ?>
                                            <center><h2>Panier vide</h2></center>
                                          <?php } else { ?>  
                    <div class="row">
                        <div class="col-lg-8">
     
                            <div class="cart-table-container">
                                <table class="table table-cart">
                                    <thead>
                                        <tr>
                                            <th class="product-col">Porduit</th>
                                            <th class="price-col">Prix unitaire</th>
                                            <th class="qty-col">Quantité</th>
                                            <th>Total</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php $panier = $db->executeQuery('SELECT * FROM panier WHERE user_id = ? ORDER BY id DESC', array($userInfo[0]['id']));
                            foreach ($panier as $paniers) { 
     
                            $produits = $db->executeQuery('SELECT * FROM produit WHERE produit = ? ORDER BY id', array($paniers["produit_id"]));
                            $images = $db->executeQuery('SELECT * FROM produit_image WHERE produit_id = ? ORDER BY id limit 1', array($paniers["produit_id"]));
                            ?>
                                        <tr class="product-row">
                                            <td class="product-col">
                                                <figure class="product-image-container">
                                                    <a href="./produit_voir?produit=<?php echo $produits[0]["produit"]; ?>" class="product-image">
                                                        <img src="./assets/boutique/<?php echo $images[0]["images"]; ?>" alt="product">
                                                    </a>
                                                </figure>
                                                <h2 class="product-title">
                                                    <p><span><?php echo $produits[0]["titre"]; ?></span><br>
                                        <span>Taille: <?php echo $paniers["taille"]; ?></span><br>
                                        <span>Couleur: <?php echo $paniers["couleur"]; ?></span><br>
                                        <span>Catégorie: <?php echo $produits[0]["categorie"]; ?></span><br>
                                        <span>Sous catégorie: <?php echo $produits[0]["sous_categorie"]; ?></span><br>
                                    </p>
                                                </h2>
                                            </td>
                                            <td><?php echo $produits[0]["prix"]; ?>€</td>
                                            <td>
                                                <?php echo $paniers["quantiter"]; ?>
                                            </td>
                                            <td><?php 
     
                                        $montant = ($paniers["quantiter"] * $produits[0]["prix"]);
                                        $total = 0;
                                        $total = $montant + $total;
                                        $superTotal += $total;
                                        echo $total;
                                    ?>€ <a href="./panier?id=<?php echo $paniers["id"]; ?>" title="Remove product" class="btn-remove"><span class="sr-only">Remove</span></a></td>
                                        </tr>
     
     
                                        <?php } ?>
     
     
                                    </tbody>
     
                                                                    <tfoot>
                                        <tr>
                                            <td colspan="4" class="clearfix">
                                                <div class="float-left">
                                                    <a href="./index " class="btn btn-outline-secondary">Continuer mes achats</a>
                                                </div><!-- End .float-left -->
     
                                                <div class="float-right">
                                                    <a href="./panier" class="btn btn-outline-secondary btn-update-cart">Relancer le panier</a>
                                                </div><!-- End .float-right -->
                                            </td>
                                        </tr>
                                    </tfoot>
                                </table>
                            </div><!-- End .cart-table-container -->
                             <?php
                                        $panierlive = $db->executeQuery('SELECT * FROM panier_livraison WHERE user_id = ?', array($userInfo[0]["id"]));
                                        if ($panierlive[0]['user_id'] == 0) 
                                        { ?>
     
                            <div class="cart-discount">
                                <h4>Livraison </h4>
                                <form method="POST">
                                    <div class="input-group">
                                      <select class="form-control" name="typelivraison">
                                                      <?php $livraison = $db->executeQuery('SELECT * FROM livraison_tarrif where pays = ? ORDER BY id', array($userInfo[0]['pays']));
                                                                foreach ($livraison as $livraisons) { 
                                                            ?>
                                                      <option value="<?php echo $livraisons['type']; ?>"><?php echo $livraisons['pays']; ?> - <?php echo $livraisons['description']; ?> - <?php echo $livraisons['prix']; ?>€ </option>
                                                    <?php } ?>
                                                    </select>
                                                     <button type="submit" name="livraison" class="btn btn-outline-secondary">Valider</button>
                                      </div>
     
                                </form>
     
                            </div>
                             <?php } else { ?> 
                             <?php } ?>
                            <div class="cart-discount">
                                <h4>Un code promo ?</h4>
                                <?php
                        $codepromo_panier = $db->executeQuery('SELECT * FROM panier_code WHERE user_id = ?', array($userInfo[0]["id"]));
                        if ($codepromo_panier[0]['user_id'] == 0) 
                        { ?>
                                <form method="POST">
                                    <div class="input-group">
                                        <input type="text" name="code" class="form-control form-control-sm" placeholder="Entré votre code promo"  required>
                                        <div class="input-group-append">
                                            <button class="btn btn-sm btn-primary" type="submit" name="add_code">Appliquer</button>
                                        </div>
                                    </div><!-- End .input-group -->
                                </form>
                                <?php } else { ?>
                                    <form action="#">
                                    <div class="input-group">
                                        <input type="text" class="form-control form-control-sm" value="<?php echo $codepromo_panier[0]["code"]; ?>" disabled>
                                        <div class="input-group-append">
                                            <button class="btn btn-sm btn-primary" type="submit" disabled="">Appliquer</button>
                                        </div>
                                    </div><!-- End .input-group -->
                                </form>
                                <?php } ?>
                            </div><!-- End .cart-discount -->
                        </div><!-- End .col-lg-8 -->
     
                        <div class="col-lg-4">
                            <div class="cart-summary">
                                <h3>Résumé</h3>
     
                                <table class="table table-totals">
                                    <tbody>
                                        <tr>
                                            <td>Sous total</td>
                                            <td><?php
                                        $panniers1 = $db->executeQuery('SELECT * FROM panier WHERE user_id = ?', array($userInfo[0]["id"]));
                                        if ($panniers1[0]['user_id'] == 0) 
                                        { ?>
     
                                                0.00€
     
                                        <?php } else { ?>
     
                                        <?php
                                               echo $superTotal; 
                                        ?>€
     
                                        <?php } ?></td>
                                        </tr>
     
                                          <?php
                                        $codepromo_panier = $db->executeQuery('SELECT * FROM panier_code WHERE user_id = ?', array($userInfo[0]["id"]));
                                        if ($codepromo_panier[0]['user_id'] == 0) 
                                        { ?>
                                       <?php } else { ?>
                                         <tr>
                                            <td>Code promo</td>
                                            <td> 
                                                -<?php echo $codepromo_panier[0]["prix"]; ?>€ <h5>(<?php echo $codepromo_panier[0]["code"]; ?>) <a href="./panier?suppcode=<?php echo $codepromo_panier[0]["id"]; ?>"><i class="fas fa-trash"></i></a></h5>
                                            </td>
                                        </tr>
                                        <?php } ?>
     
                                        <!-- Livraison Prix-->
                                        <?php
                                        $panierlivez = $db->executeQuery('SELECT * FROM panier_livraison WHERE user_id = ?', array($userInfo[0]["id"]));
                                        if ($panierlivez[0]['user_id'] == 0) 
                                        { ?>
                                        <?php } else { ?> 
                                          <?php
                                        $panierlive = $db->executeQuery('SELECT * FROM panier_livraison WHERE user_id = ? and pays = ?', array($userInfo[0]["id"],"France"));
                                        if ($panierlive[0]['prix'] == 8.00) 
                                        { ?>
                                          <?php if ($superTotal > '99') {?>
                                            <tr>
                                            <td>Prix livraison</td>
                                            <td><?php echo $panierlive[0]["prix"]; ?>€ <a href="./panier?supp_livraison=<?php echo $panierlive[0]["id"]; ?>"><i class="fas fa-trash"></i></a></td>
                                        </tr>
                                          <?php } else { ?> 
                                           <tr>
                                            <td>Prix livraison</td>
                                            <td>Gratuit <a href="./panier?supp_livraison=<?php echo $panierlive[0]["id"]; ?>"><i class="fas fa-trash"></i></a></td>
                                        </tr>
                                         <?php } ?>
     
                                          <?php } else { ?> 
                                             <tr>
                                            <td>Prix livraison</td>
                                            <td><?php echo $panierlivez[0]["prix"]; ?>€ <a href="./panier?supp_livraison=<?php echo $panierlivez[0]["id"]; ?>"><i class="fas fa-trash"></i></a></td>
                                        </tr>
                                          <?php } ?>
     
                                      <?php } ?>
                                      <!-- Fin du prix de livraison -->
     
                                    </tbody>
                                    <tfoot>
                                        <tr>
                                            <td>Total de la commande</td>
                                            <td><?php
                                        $panniers1 = $db->executeQuery('SELECT * FROM panier WHERE user_id = ?', array($userInfo[0]["id"]));
                                        if ($panniers1[0]['user_id'] == 0) 
                                        { ?>
     
                                                0.00€
     
                                        <?php } else { ?>
                                        <?php
                                        $codepromo_panier = $db->executeQuery('SELECT * FROM panier_code WHERE user_id = ?', array($userInfo[0]["id"]));
                                        if ($codepromo_panier[0]['user_id'] == 0) 
                                        { ?>
                                          <!-- Sans code promo -->
                                      <?php 
                                          $panierlive = $db->executeQuery('SELECT * FROM panier_livraison WHERE user_id = ?', array($userInfo[0]["id"]));
                                          if ($panierlive[0]['user_id'] == 0) 
                                          {
                                            echo "0.00";
                                            } else {
                                            #Livraison remplis 
                                            # Si la livraison et pour la france et qu'elle est normal alors on affiche : 
                                            $panierlives = $db->executeQuery('SELECT * FROM panier_livraison WHERE user_id = ? and pays = ?', array($userInfo[0]["id"],"France"));
                                            if ($panierlives[0]['prix'] == 8.00) 
                                            { 
                                              if ($superTotal > '99') {
                                              # Si la livraison fait + de 99.00€ on affiche : 
                                                $suptotal = ($superTotal + $panierlives[0]["prix"]);
     
                                              } else {
                                              #Si elle fait - de 99.00€ on affiche : 
                                                $suptotal = ($superTotal);
                                              }
                                            } else {
                                              $suptotal = ($superTotal + $panierlive[0]["prix"]);
                                            }
     
                                            }
                                            # Résultat 
                                            echo $suptotal; 
     
                                            ?><?php } else { ?>
                                        <!-- Avec code promo -->
                                        <?php 
                                          $panierlive = $db->executeQuery('SELECT * FROM panier_livraison WHERE user_id = ?', array($userInfo[0]["id"]));
                                          if ($panierlive[0]['user_id'] == 0) 
                                          {
                                            echo "0.00";
                                            } else {
                                            #Livraison remplis 
                                            # Si la livraison et pour la france et qu'elle est normal alors on affiche : 
                                            $panierlives = $db->executeQuery('SELECT * FROM panier_livraison WHERE user_id = ? and pays = ?', array($userInfo[0]["id"],"France"));
                                            if ($panierlives[0]['prix'] == 8.00) 
                                            { 
                                              if ($superTotal > '99') {
                                              # Si la livraison fait + de 99.00€ on affiche : 
                                                $suptotal = (- $codepromo_panier[0]["prix"] + $superTotal + $panierlives[0]["prix"]);
     
                                              } else {
                                              #Si elle fait - de 99.00€ on affiche : 
                                                $suptotal = (- $codepromo_panier[0]["prix"] + $superTotal);
                                              }
                                            } else {
                                              $suptotal = (- $codepromo_panier[0]["prix"] + $superTotal + $panierlive[0]["prix"]);
                                            }
     
                                            }
                                            # Résultat 
                                            echo $suptotal; 
     
                                            ?>€
     
                                        <?php } ?>
                                        <?php } ?></td>
                                        </tr>
                                    </tfoot>
                                </table>
                                <?php
                                        $panierlive = $db->executeQuery('SELECT * FROM panier_livraison WHERE user_id = ?', array($userInfo[0]["id"]));
                                        if ($panierlive[0]['user_id'] == 0) 
                                        { ?>
                                          <?php } else { ?> 
                                <div class="checkout-methods">
                                    <?php
    /* Les variables suivantes doivent être personnalisées selon vos besoins */
      $email_paypal= ''.$infoweb[0]["paypal"].'';/*email associé au compte paypal du vendeur*/
      $item_numero = ''.$userInfo[0]['id'].''; /*Numéro du produit en vente*/
      $item_prix   = ''.$suptotal.''; /*prix du produit*/
      $item_nom    = ''.$infoweb[0]["nomdusite"].' - Textile'; /*Nom du produit*/
      $url_retour= ''.$infoweb[0]["lien2"].'/paiement_valider';/*page de remerciement à créer*/
      $url_cancel= ''.$infoweb[0]["lien2"].'/paiement_annulation'; /*page d'annulation d'achat*/
      $url_confirmation= ''.$infoweb[0]["lien2"].'/paiement_valider';/*page de confirmation d'achat*/
    /* fin déclaration des variables */
     
      echo '
      <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
      <input type="hidden" name="cmd" value="_xclick"/>
      <input type="hidden" name="business" value="'.$email_paypal.'"/>
      <input type="hidden" name="item_name" value="'.$item_nom.'"/>
      <input type="hidden" name="item_number" value="'.$item_numero.'"/>
      <input type="hidden" name="amount" value="'.$item_prix.'"/>
      <input type="hidden" name="currency_code" value="EUR"/>
      <input type="hidden" name="no_note" value="1"/>
      <input type="hidden" name="no_shipping" value="0"/>
      <input type="hidden" name="lc" value="FR"/>
      <input type="hidden" name="notify_url" value="'.$url_confirmation.'"/>
      <input type="hidden" name="cancel_return" value="'.$url_cancel.'">
      <input type="hidden" name="return" value="'.$url_retour.'">
      <button type="submit" name="submit" class="btn btn-block btn-sm btn-primary"><span>Paiement</span></button>
      </form> ';
    ?>
                                <?php if($userInfo[0]['developpeur'] == 1) { ?>
                                  <a href="./espace_client/paiement_valider" class="btn btn-block btn-sm btn-primary"><span>Paiement DEV</span></a>
                                <?php } ?>
                                </div>
                              <?php } ?>
                                <!-- End .checkout-methods -->
                            </div><!-- End .cart-summary -->
                        </div><!-- End .col-lg-4 -->
                    </div><!-- End .row -->
                    <?php } ?>
     
                </div><!-- End .container -->
     
                <div class="mb-6"></div><!-- margin -->
            </main><!-- End .main -->
        </div><!-- End .page-wrapper -->
    <?php include './footer.php'; ?>
    <?php include './menu_mobile.php'; ?>
    <?php include './js.php'; ?>
    </body>
    </html>

  8. #8
    Invité
    Invité(e)
    Par défaut
    1- Initialisation de $superTotal :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    <?php $panier = $db->executeQuery('SELECT * FROM panier WHERE user_id = ? ORDER BY id DESC', array($userInfo[0]['id']));
     
    $superTotal = 0; // initialisation (AVANT boucle foreach)
     
    foreach ($panier as $paniers) { 
     
    ...
    2- Calcul du total-produit et ajout au superTotal :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    	<td><?php 
    		$total_produit = ($paniers["quantiter"] * $produits[0]["prix"]);
    		echo $total_produit;
    		// on ajoute le total_produit au superTotal
    		$superTotal += $total;
    		?>€ <a href="./panier?id=<?php echo $paniers["id"]; ?>" title="Remove product" class="btn-remove"><span class="sr-only">Remove</span></a></td>
    3- Ce n'est pas '99', mais 99 (numérique) :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <?php if ($superTotal > 99) {?>
    4- Ensuite, ON NE COMPREND PLUS :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    	#Livraison remplis 
    	# Si la livraison et pour la france et qu'elle est normal alors on affiche : 
    	$panierlives = $db->executeQuery('SELECT * FROM panier_livraison WHERE user_id = ? and pays = ?', array($userInfo[0]["id"],"France"));
    	if ($panierlives[0]['prix'] == 8.00) 
    	{ 
    	  if ($superTotal > '99') {
    	  # Si la livraison fait + de 99.00€ on affiche : 
    		$suptotal = ($superTotal + $panierlives[0]["prix"]);
     
    	  } else {
    	  #Si elle fait - de 99.00€ on affiche : 
    		$suptotal = ($superTotal);
    	  }
    	} else {
    	  $suptotal = ($superTotal + $panierlive[0]["prix"]);
    	}
     
    	}
    	# Résultat 
    	echo $suptotal;
    Là, tu AJOUTES $panierlives[0]["prix"] au "sous-total" * :
    • QUE VAUT $panierlives[0]["prix"] ??
    • ça EXPLIQUE certainement la différence de prix, non ?


    => il ne faut pas faire comme ça !
    il faut afficher les différents prix indépendamment :
    • Sous-Total : ..... €
    • Livraison : ...... €
    • (Avec code promo) Remise : - ..... €
      Et en fin (la somme) :
    • TOTAL : ....... €


    * CONSEIL : mets des noms de variables plus explicites !
    • $total_produit
    • $sous_total_produits (= somme des $total_produit) -> (c'est ce que tu as MAL appelé : "superTotal")
    • $frais_livraison
    • $remise_promo
    • $TOTAL_GLOBAL

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    $TOTAL_GLOBAL = ($sous_total_produits + $frais_livraison - $remise_promo);

  9. #9
    Membre à l'essai
    Homme Profil pro
    Conseiller Technique
    Inscrit en
    Décembre 2018
    Messages
    11
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Conseiller Technique

    Informations forums :
    Inscription : Décembre 2018
    Messages : 11
    Points : 10
    Points
    10
    Par défaut
    Et sauf erreur de ma part mais les requêtes sont exécutées sans être préparé, niveau sécurité c'est pas top.

  10. #10
    Futur Membre du Club
    Homme Profil pro
    Développeur Web
    Inscrit en
    Mars 2020
    Messages
    15
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Charente (Poitou Charente)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mars 2020
    Messages : 15
    Points : 9
    Points
    9
    Par défaut
    Bonjour, après plusieurs jours de réflexion j'ai refait le code.
    Mais j'ai toujours ce problème du total qui ne fonctionne pas... je te laisse regarder, et me corriger.
    La mon total de tout mes produits me retourne 0
    Alors qu'il devrais m'afficher : 195.5€

    Voici un screen de la page : https://prnt.sc/sf7hej

    Voila le code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
     
    <?php 
      // Connexion au service
      include("./global.php");
     
      // Identification des page 
      $pageid = "panier";
     
        // Supprimer un élément du panier 
      if(isset($_GET['id'])) {
            if(is_numeric($_GET['id'])) {
                $db->executeInsert('DELETE FROM panier WHERE id = ?', array($_GET['id']));
                $ok = "";
        }
      }
      // Ajouter un code promo
      if(isset($_POST['add_code'])) {
        $code = ($_POST['code']);
            $check_code2 = $db->executeQuery('SELECT COUNT(*) AS count_row FROM codepromo WHERE code = ?', array($code));
            if($check_code2[0]["count_row"] == 0)
            {
     
            $ok3 = "";
            }
            $check_code2 = $db->executeQuery('SELECT COUNT(*) AS count_row FROM codepromo WHERE code = ? and activer = ?', array($code,"0"));
            if($check_code2[0]["count_row"] == 1)
            {
            $ok4 = "";
            }
            $check_code = $db->executeQuery('SELECT COUNT(*) AS count_row FROM codepromo WHERE code = ? and activer = ?', array($code,"1"));
            if($check_code[0]["count_row"] == 1)
            {
            if(empty($errorNews)) {
            $date = date("d-m-Y à H:i"); 
            $codepromo = $db->executeQuery("SELECT * FROM codepromo WHERE code = ? ", array($code));
            $db->executeInsert('INSERT INTO panier_code (user_id,code,prix) VALUES (?,?,?)', array($userInfo[0]["id"],$code,$codepromo[0]["prix"]));
            $ok1 = "";
          }
        }
      }
     
        // Ajouter une livraison
      if(isset($_POST['livraison'])) {
        $typelivraison = ($_POST['typelivraison']);
            if(empty($errorNews)) {
            $tarrif = $db->executeQuery("SELECT * FROM livraison_tarrif WHERE pays = ? and type = ? ", array($userInfo[0]["pays"],$typelivraison));
            $db->executeInsert('INSERT INTO panier_livraison (user_id,pays,prix,type) VALUES (?,?,?,?)', array($userInfo[0]["id"],$userInfo[0]["pays"],$tarrif[0]['prix'],$tarrif[0]['type']));
            $ok5 = "";
        }
      }
     
        //Supprimer une livraison
      if(isset($_GET['supp_livraison'])) {
            if(is_numeric($_GET['supp_livraison'])) {
                $db->executeInsert('DELETE FROM panier_livraison WHERE id = ?', array($_GET['supp_livraison']));
                $ok6 = "";
        }
      }
     
      //Supprimer un code promo 
      if(isset($_GET['suppcode'])) {
            if(is_numeric($_GET['suppcode'])) {
                $db->executeInsert('DELETE FROM panier_code WHERE id = ?', array($_GET['suppcode']));
                $ok2 = "";
        }
      }
    ?>
    <!DOCTYPE html>
    <!-- Une réalisation de Dylan tout droit réserver -->
    <html lang="fr">
    <head>
        <?php include './configuration.php'; ?>
        <title><?php echo $infoweb[0]["nomdusite"]; ?> | Panier</title>
        <?php include './style.php'; ?>
    </head>
     
    <body>
      <!-- Affiche la liste des produits dans le panier -->
    <?php $panier = $db->executeQuery('SELECT * FROM panier WHERE user_id = ? ORDER BY id DESC', array($userInfo[0]['id']));
    // Recherche du produit dans la base de donnée.
    $produits = $db->executeQuery('SELECT * FROM produit WHERE produit = ? ORDER BY id', array($panier[0]["produit_id"]));
    // Recherche de l'images du produit dans la base de donnée.
    $images = $db->executeQuery('SELECT * FROM produit_image WHERE produit_id = ? ORDER BY id limit 1', array($panier[0]["produit_id"]));
     
    $superTotal = 0; // initialisation (AVANT boucle foreach)
     
    foreach ($panier as $paniers) 
     
    { ?>
    titre : <?php echo $produits[0]["titre"]; ?><br>
    Prix unit : <?php echo $produits[0]["prix"]; ?>€ <br> 
    Quantiter : <?php echo $paniers["quantiter"]; ?> <br>
    total : <?php $total_produit = ($paniers["quantiter"] * $produits[0]["prix"]);
                  echo $total_produit;
                  // on ajoute le total_produit au superTotal
                  $superTotal += $total;
            ?>€
    <br><br>
    <?php } ?> 
    <!-- Fin de la liste de produit -->
     
    <!-- Affichage du prix total -->
    <br>
    total du panier : <?php echo $superTotal; ?>€<br>
    <!-- Fin de l'affichage du prix total -->
     
    </body>
    </html>
    Merci beaucoup pour ton aide.

  11. #11
    Invité
    Invité(e)
    Par défaut
    Bonjour,

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    total : <?php $total_produit = ($paniers["quantiter"] * $produits[0]["prix"]);
                  echo $total_produit;
                  // on ajoute le total_produit au superTotal
                  $superTotal += $total;
    Ce n'est pas $total, mais $total_produit.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
                  $superTotal += $total_produit;

  12. #12
    Futur Membre du Club
    Homme Profil pro
    Développeur Web
    Inscrit en
    Mars 2020
    Messages
    15
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Charente (Poitou Charente)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mars 2020
    Messages : 15
    Points : 9
    Points
    9
    Par défaut
    Bonjour,
    Super Merci beaucoup grâce à toi tout marche sans problème.
    Franchement Merci!

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [MySQL] addition pour total d'un panier
    Par blue-fab dans le forum PHP & Base de données
    Réponses: 2
    Dernier message: 01/06/2007, 12h48
  2. Addition de dates
    Par shingo dans le forum PostgreSQL
    Réponses: 1
    Dernier message: 19/01/2004, 14h53
  3. Addition et multiplications
    Par Yayel dans le forum SQL Procédural
    Réponses: 6
    Dernier message: 04/04/2003, 23h15
  4. [VB6] Problème d'addition de dates et de nombres
    Par pepper dans le forum VB 6 et antérieur
    Réponses: 8
    Dernier message: 28/11/2002, 21h12
  5. [imprecis]Réaliser a^n avec seulement l'opérateur d'addition
    Par Amon dans le forum Algorithmes et structures de données
    Réponses: 18
    Dernier message: 08/11/2002, 22h22

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo