SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Wizard
    Join Date
    Jul 2006
    Location
    New Zealand
    Posts
    1,300
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Gift Certificate System.

    Hi,i am Wondering how do i go about Making a gift certificate system where the user can enter in a gift certificate box where it takes a discount off the total price this is my cart code

    PHP Code:
            $items=array();
            $prices=array();
            $pid=array();
            include("dbconnect.php");
        // please refer to the companion file catalog.php, which is very similar to this one
        // and here only differences are commented.
        session_start();
        if (!isset($_SESSION['cart'])) {
            $_SESSION['cart'] = array();
        }

        if (isset($_GET['empty'])) {
            // Empty the shopping cart array
            unset($_SESSION['cart']);
            header('location: '.$_SERVER['PHP_SELF'].'?'.SID);
            exit();
        }

                                    $cQuery="SELECT * FROM products";
                                    $result=mysqli_query($con,$cQuery);;
                                    if(!$result)
                                    {
                                        echo "Error:".mysqli_error($con);
                                    }
                                    else
                                    {
                                        $count=$result->num_rows;
                                        if($count>0)
                                        {
                                            while($data=$result->fetch_assoc())
                                            {
                                                //echo " here is  ".$data['productName'];
                                                $pid[]=$data['pid'];
                                                $items[]=$data['productName'];
                                                $prices[]=$data['ProductCost'];
                                                //$data['prices']//$prices =mysqli_fetch_assoc();
                                            }
                                        }
                                        else
                                        {
                                        echo "There is no products in the catalog,Please contact the webmaster of this store";
                                        }
                                    }?>
    <?php
        $total 
    0// add up the total
        // list the quantities in the cart rather than the catalog
        
    for ($i 0$i count($_SESSION['cart']); $i++) {
            echo 
    '<tr><td>'.$pid[$_SESSION['cart'][$i]].'</td><td> &nbsp;'.$items[$_SESSION['cart'][$i]].'</td>';
            echo 
    '<td align="right">&nbsp;$'.number_format($prices[$_SESSION['cart'][$i]], 2).'<br/></td></tr>';
            
    $total += $prices[$_SESSION['cart'][$i]];

        }
    ?>
        <tr>
            <th align="right">Total:</th><br />
            <th align="right">$<?php echo number_format($total2); ?></th>
            </tr></table>
            <table>
            <tr>
                <td colspan="2">(if you have a gift certificated please enter it here</td>
            </tr>
            <tr>
                <td><th align="right">Discount Total:</th><br />
            <th align="right"><input type="text" name="discount#" maxlength="4" width="5px"></th>
        </td>
            </tr>
            </table>

  2. #2
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    store the gc's you have issue into a database. when the user enters a gc number, check to make sure it exists and has not already been used.

    store the dollar amount of the gc in the database. use this amount to subract from the total.

  3. #3
    SitePoint Wizard
    Join Date
    Jul 2006
    Location
    New Zealand
    Posts
    1,300
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i have a table created with the following

    gid which is gift id
    idnum which is the number which is for the user
    gra which is amount of discount for the user who buys it.

    so now how do i go about the checking part and hasnt been used? can anyone right up an example?

  4. #4
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    assuming gid and idnum are integers

    select gra from mytable where idnum = $idnum and gid = $gid

    if they are not integers then quote them obviously

    use mysql_num_rows() to see if a match was found, and then grab the gra just like any other result from a db.

  5. #5
    SitePoint Evangelist ashattuc's Avatar
    Join Date
    Aug 2002
    Location
    Boise, Idaho
    Posts
    411
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To check if the gc has been used, I would just add a "used" column. When the gc is created, it's set to '0' and when the checkout is complete, switch that value to '1'.
    Chris S.

    Free Web Scripts - Form generators, AJAX tools and more!
    Micro CMS - A totally free AJAX-based, SEO-ed CMS!

  6. #6
    SitePoint Wizard cranial-bore's Avatar
    Join Date
    Jan 2002
    Location
    Australia
    Posts
    2,634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    and be sure not to use an autoincrement for your certificate "id" or they will be easily guessed!

  7. #7
    SitePoint Wizard
    Join Date
    Jul 2006
    Location
    New Zealand
    Posts
    1,300
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh ok thank you.

    now i have done it but now how do i make it check the gca amount and take that away from the total if they do have a gift certificated?

    wat i mean is

    gca -=$total[$_SESSION['cart'][$i]];

    is that correct or would i need somthing else?

  8. #8
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by william232
    is that correct or would i need somthing else?
    did you try it?

  9. #9
    SitePoint Wizard
    Join Date
    Jul 2006
    Location
    New Zealand
    Posts
    1,300
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes nothing.

  10. #10
    SitePoint Wizard cranial-bore's Avatar
    Join Date
    Jan 2002
    Location
    Australia
    Posts
    2,634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Shouldn't you be taking the gift certificate amount (I assume that is what gca is) away from the total?
    Is your total stored in the session, or is it calculated as a sum of the cost of the items in the session?

  11. #11
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by william232
    yes nothing.
    im sure you got an error. so you didnt exactly get "nothing"

    think about this for a second...
    you want to subtract the $gca from the $total

    $total -= $gca;

  12. #12
    SitePoint Wizard
    Join Date
    Jul 2006
    Location
    New Zealand
    Posts
    1,300
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    now how can i subtract and display the total of what has been subtracted from $total-=$gca;

    like what i mean is how can i display the discount total above the gift certificate box area?

    because the total is adding all the prices from the $_session['cart']; above the gift certificate system so how can i get cuz where it displays the cost it does this.

    PHP Code:
    echo number_format($total,2); 
    How can i go about this?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •