Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 1 of 1
  1. #1
    Senior Member Karloff's Avatar
    Join Date
    Oct 2005
    Posts
    744
    Member #
    11702
    i have a wishlist which the client has now added a 6 tier pricing system to it.

    i have manged to pass $cost (the relating value of the product dependant on the link they click to 'add to wishlist'

    however the cost shown is always the fist price which was pass to it:dead:

    can anyone help me fix the update/ add/ delete feature of this

    here is my cart.php
    PHP Code:
    <?php
    // Include MySQL class
    require_once('includes/mysql.class.php');
    // Include database connection
    require_once('includes/global.inc.php');
    // Include functions
    require_once('includes/functions.inc.php');
    // Start the session
    session_start();
    // Process actions
    $cart $_SESSION['cart'];
    $cost $_SESSION['cost'];
    $action $_GET['action'];
    switch (
    $action) {
        case 
    'add':
            if (
    $cart) {
                
    $cart .= ','.$_GET['id'];
            } else {
                
    $cart $_GET['id'];
            }
            if (
    $cost) {
                
    $cost .= ','.$_GET['cost'];
            } else {
                
    $cost $_GET['cost'];
            }

            break;
        case 
    'delete':
            if (
    $cart) {
                
    $items explode(',',$cart);
                
    $newcart '';
                foreach (
    $items as $item) {
                    if (
    $_GET['id'] != $item) {
                        if (
    $newcart != '') {
                            
    $newcart .= ','.$item;
                        } else {
                            
    $newcart $item;
                        }
                    }
                }
                
    $cart $newcart;
            }
            if (
    $cost) {
                
    $items explode(',',$cost);
                
    $newcost '';
                foreach (
    $items as $item) {
                    if (
    $_GET['cost'] != $item) {
                        if (
    $newcost != '') {
                            
    $newcost .= ','.$item;
                        } else {
                            
    $newcost $item;
                        }
                    }
                }
                
    $cost $newcost;
            }
            break;
        case 
    'update':
        if (
    $cart) {
            
    $newcart '';
            foreach (
    $_POST as $key=>$value) {
                if (
    stristr($key,'qty')) {
                    
    $id str_replace('qty','',$key);
                    
    $items = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart);
                    
    $newcart '';
                    foreach (
    $items as $item) {
                        if (
    $id != $item) {
                            if (
    $newcart != '') {
                                
    $newcart .= ','.$item;
                            } else {
                                
    $newcart $item;
                            }
                        }
                    }
                    for (
    $i=1;$i<=$value;$i++) {
                        if (
    $newcart != '') {
                            
    $newcart .= ','.$id;
                        } else {
                            
    $newcart $id;
                        }
                    }
                }
            }
        }
        
    $cart $newcart;
        if (
    $cost) {
            
    $newcost '';
            foreach (
    $_POST as $key=>$value) {
                if (
    stristr($key,'qty')) {
                    
    $id str_replace('qty','',$key);
                    
    $items = ($newcost != '') ? explode(',',$newcost) : explode(',',$cost);
                    
    $newcost '';
                    foreach (
    $items as $item) {
                        if (
    $id != $item) {
                            if (
    $newcost != '') {
                                
    $newcost .= ','.$item;
                            } else {
                                
    $newcost $item;
                            }
                        }
                    }
                    for (
    $i=1;$i<=$value;$i++) {
                        if (
    $newcost != '') {
                            
    $newcost .= ','.$id;
                        } else {
                            
    $newcost $id;
                        }
                    }
                }
            }
        }
        
    $cost $newcost;
        break;
    }
    $_SESSION['cart'] = $cart;
    $_SESSION['cost'] = $cost;

    ?>

    <div id="shoppingcart">
    <? echo $cart ?>
    <br />
    <? echo $cost ?>
    <h3>Your Wishlist</h3>

    <?php
    echo writeShoppingCart();
    ?>

    </div>

    <div id="contents">

    <h4>Please check quantities...</h4>

    <?php
    echo showCart();
    ?>



    </div>
    and here is the showcart function
    PHP Code:
    function showCart() {
        global 
    $db;
        
    $cart $_SESSION['cart'];

        
    $cost $_SESSION['cost'];
        if (
    $cart) {
            
    $items explode(',',$cart);
            
    $contents = array();
            foreach (
    $items as $item) {
                
    $contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1;
            }
            
            
    $output[] = '<form action="cart&action=update" method="post" id="cart">';
            
    $output[] = '<table>';
            foreach (
    $contents as $id=>$qty) {
                
    $sql 'SELECT * FROM products WHERE id = '.$id;
                
    $result $db->query($sql);
                
    $row $result->fetch();
                
    extract($row);
                
                
    $output[] = '<tr><th>Product name</th><!--<th>Cost</th>--><th>Quantity</th><th>Total Cost</th><th>Delete</th></tr>';
                
    $output[] = '<tr>';
                
                
    $output[] = '<td>'.$title.'</td>';
    //            $output[] = '<td>&pound;'.$cost.'</td>';
    //            $output[] = '<td><input class="quantity" type="text" name="qty'.$id.'" value="'.$qty.'" size="3" maxlength="3" /></td>';
                
    $output[] = '<td>'.$qty.'</td>';
                
    $output[] = '<td>&pound;'.($cost $qty).'</td>';
                
    $total += $cost $qty;
                
    $output[] = '<td><a href="cart&action=delete&id='.$id.'" class="r">X</a></td>';
                
    $output[] = '</tr>';
            }
            
    $output[] = '</table>';
            
    $output[] = '<p>Grand total: <strong>&pound;'.$total.'</strong></p>';
            
    $output[] = '<p><button type="submit">Update wishlist</button></p>';
            
    $output[] = '</form>';
            
    $output[] = '<p class="calc"><a href="leasecalculator&amt='.$total.'">Calculate lease payments for your wishlist</a></p>';
        } else {
            
    $output[] = '<p>You wishlist is empty.</p>';
        }
        return 
    join('',$output);
        


  2.  


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 02:48 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2022 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com