Subtotaal winkelwagen op volgende pagina

Overzicht Reageren

Sponsored by: Vacatures door Monsterboard

Yoeri Boven

Yoeri Boven

05/01/2012 18:27:02
Quote Anchor link
Ik was bezig om dit scriptdit script te bestuderen, maar nu ik hem een klein beetje wil uitbreiden stuit ik op een paar problemen.
In het winkelwagentje zie je het subtotaal. Deze wordt in de functions.inc.php gedefinieerd door $total. Ik heb een 'checkout' knop gemaakt en daar wil ik het subtotaal op laten zien.
Kan iemand me vertellen hoe het moet? Ik dacht dat als ik
Quote:
$_SESSION['total'] = $total;
zou doen het wel werkte, maar dat is helaas niet zo.

Volgens mij is het maar een klein dingetje, dus zou iemand het mij willen uitleggen? :)

Alvast bedankt.


Code (php)
PHP script in nieuw venster Selecteer het PHP script
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
<?php
function writeShoppingCart() {
    $cart = $_SESSION['cart'];
    if (!$cart) {
        return '<p>You have no items in your shopping cart</p>';
    }
else {
        // Parse the cart session variable
        $items = explode(',',$cart);
        $s = (count($items) > 1) ? 's':'';
        return '<p>You have <a href="cart.php">'.count($items).' item'.$s.' in your shopping cart</a></p>';
    }
}

function
showCart() {
    global $db;
    $cart = $_SESSION['cart'];
    if ($cart) {
        $items = explode(',',$cart);
        $contents = array();
        foreach ($items as $item) {
            $contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1;
        }

        $output[] = '<form action="cart.php?action=update" method="post" id="cart">';
        $output[] = '<table>';
        foreach ($contents as $id=>$qty) {
            $result = mysql_query('SELECT * FROM books WHERE id = '.$id);
            $row = mysql_fetch_array($result);
            extract($row);
            $output[] = '<tr>';
            $output[] = '<td><a href="cart.php?action=delete&id='.$id.'" class="r">Remove</a></td>';
            $output[] = '<td>'.$title.' by '.$author.'</td>';
            $output[] = '<td>&pound;'.$price.'</td>';
            $output[] = '<td><input type="text" name="qty'.$id.'" value="'.$qty.'" size="3" maxlength="3" /></td>';
            $output[] = '<td>&pound;'.($price * $qty).'</td>';
            $total += $price * $qty;
            $output[] = '</tr>';
        }

        $output[] = '</table>';
        $output[] = '<p>Grand total: <strong>&pound;'.$total.'</strong></p>';
        $output[] = '<div><button type="submit">Update cart</button></div>';
        $output[] = '</form>';
    }
else {
        $output[] = '<p>You shopping cart is empty.</p>';
    }

    return join('',$output);
}

?>


Update: Iets te vroeg gevraagd. Ik heb bovenstaande code toegevoegd en in checkout.php de juiste bestanden 'geincluded'.
Gewijzigd op 05/01/2012 18:31:10 door Yoeri Boven
 
PHP hulp

PHP hulp

26/04/2024 17:22:44
 
Bas  van de Steeg

Bas van de Steeg

05/01/2012 18:32:31
Quote Anchor link
Oke mooi dat je er zelf uit bent gekomen.
;-)
 



Overzicht Reageren

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.