PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Tue Nov 12, 2019 10:31 pm

All times are UTC - 5 hours




Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
PostPosted: Fri Oct 08, 2010 1:46 pm 
Offline
Forum Newbie

Joined: Fri Oct 08, 2010 1:33 pm
Posts: 15
Location: Fort Smith, Arkansas
Hey guys I'm kind of new to php but have used it many times in the past for simple jobs and such. I have built a website at http://www.agencyequipment.com and everything is up and running except for the most important part of the site, the cart and checkout. I have read over this code about thirty time in the past hour and cannot find out what the problem is. This php code was in use on one of our other websites with the exact same database structure and pretty much the same layout. For some reason when a user adds an item to their cart it shows up on the right side menu with the quantity and subtotal, but when the user presses checkout it always returns the message saying that the cart is empty. I know that their are a lot of areas in the code that could be the problem I am just having trouble finding it, also if you are willing to help with this and need to take a look at the dependent files just let me know. I would greatly appreciate any help with this because my boss does not understand how much of a pain coding can be and is telling me that if I don't get this working in 3 and a half hours that I will no longer have a job. So please please please help if you can.

Syntax: [ Download ] [ Hide ]
<?php

$cart->loadItemInfo();

require_once("customer.php");
$customers = new Customers($db);

require_once("order.php");
$orders = new Orders($db);

$pageSecure = FALSE;
$pageTitle = "Checkout";

require_once("heading.phtml");

?>

<div id="pagebody">
    <div class="box-wrapper three-main">
        <div class="box-left">
            <div class="box-middle">
                <div id="checkout" class="box-one">

    <?php if (count($cart->cart_items) == 0) { ?>
        <h1>Agency Equipment Order Submission</h1>

        <p>It appears that your current order is empty. Please browse the catalog to order items and
        add them to your cart. Return to checkout after you have your order ready. If you believe this message is in error,
        please contact us.</p>

        <p>You may also contact us between 8am and 5pm CST Monday through Friday or email any time to place your order.</p>

    <?php
    } else {
        if ((array_key_exists("cart_update", $_POST)) && (! empty($_POST["cart_update"]))) {
            // Update cart contents
            foreach ($_POST["cart_qty"] as $i => $q) {
                if (is_numeric($q)) {
                    if ((int) $q > 0) $cart->cart_items[$i]->item_quantity = (int) $q;
                    else unset($cart->cart_items[$i]);
                }
            }
            $cart->saveCart();
            if (count($cart->cart_items) > 0) {
                $cart->loadItemInfo();
                displayCheckoutForm($_POST);
            } else {
                unset($cart);
                header("Location: /");
            }
        } elseif ((array_key_exists("customer_order_new", $_POST)) && (! empty($_POST["customer_order_new"]))) {
            if ((! array_key_exists("customer_agreed", $_POST)) || (strcmp($_POST["customer_agreed"], "on"))) {
                echo "<p>You must first agree to the terms and conditions governing the use of this website.</p>\n";
                displayCheckoutForm($_POST);
            } else {
                $custid = 0;
                if (! $user->isAuthenticated()) {
                    if (! empty($_POST["customer_pass1"])) {
                        if (($cid = $customers->Create($_POST))) {
                            $custid = $cid;
                        } else {
                            echo "<p>" . $_SESSION["msg"] . "</p>\n";
                            unset($_SESSION["msg"]);
                            displayCheckoutForm($_POST);
                        }
                    }
                } else {
                    $customers->Fetch("customer_user = {$user->user_id}");
                    $cust = current($customers->customers);
                    if ($cust) {
                        $custid = $cust->customer_id;
                        if (! $customers->Edit($custid, $_POST)) {
                            echo "<p>" . $_SESSION["msg"] . "</p>\n";
                            unset($_SESSION["msg"]);
                            displayCheckoutForm($_POST);
                        }
                    } else {
                        if (($cid = $customers->Create($_POST))) {
                            $custid = $cid;
                        } else {
                            echo "<p>" . $_SESSION["msg"] . "</p>\n";
                            unset($_SESSION["msg"]);
                            displayCheckoutForm($_POST);
                        }
                    }
                }

                // Create new order
                if ($oid = $orders->Create($_POST, $custid)) {
                    echo "<p>Your order has been received as order number {$oid}. An email has been sent to " . htmlspecialchars($_POST["customer_email"]) . " confirming the order.</p>\n";
                    if ($_POST["customer_payment"] == "check") {
                        echo "<p>You have chosen to make your payment via check or money order. Please make it payable to Agency Equipment and remit to the address below:</p>Agency Equipment<br>PO Box 5819<br>Chino Valley, AZ 86323<br><p>The minimum payment due is \$"; printf("%1\$.2f", $cart->cart_deposit); echo ".</p>\n";
                    } else if ($_POST["customer_payment"] == "credit") {
                        echo "<p>We will attempt to bill your credit card. A processing fee of 2.5% will be automatically applied.</p>\n";
                    }
                    if (isset($_SESSION["msg"])) {
                        echo "<p>{$_SESSION["msg"]}</p>";
                        unset($_SESSION["msg"]);
                    }
                    echo "<p>You will receive an invoice in your email shortly. We appreciate the business and look forward to serving you. Please feel free to contact us if you need further assistance.</p>\n";
                } else {
                    echo "<p>There was an error while processing your order. Please try again shortly or contact us.</p>\n";
                    error_log("Error while creating new order - {$_SESSION["message"]}");
                    unset($_SESSION["message"]);
                    displayCheckoutForm($_POST);
                }
            }
        } else {
            displayCheckoutForm($user);
        }
    }
    ?>

                </div>

                <div class="box-two">
                    <?php require_once("templates/menu_left.phtml"); ?>
                </div>

                <div class="box-three">
                    <?php require_once("templates/menu_right.phtml"); ?>
                </div>
            </div>
        </div>
    </div>
</div>

<?php

require_once("footing.phtml");


function displayCheckoutForm($values = NULL)
{
    $cart = $GLOBALS["cart"];
    $products = $GLOBALS["products"];
    $mans = $GLOBALS["mans"];
    $customers = $GLOBALS["customers"];

    $keys = array("customer_fname", "customer_mname", "customer_lname", "customer_company", "customer_email", "customer_phone_main", "customer_phone_alt", "customer_phone_fax", "customer_pass1", "customer_pass2", "customer_billaddr_one", "customer_billaddr_two", "customer_billaddr_city", "customer_billaddr_state", "customer_billaddr_zipcode", "customer_shipaddr_one", "customer_shipaddr_two", "customer_shipaddr_city", "customer_shipaddr_state", "customer_shipaddr_zipcode", "customer_ffl", "customer_notes", "customer_payment", "customer_notes", "customer_agreed",
"customer_cctype", "customer_ccnum", "customer_cccvv", "customer_ccmm", "customer_ccyy");
    $v = array();
    foreach ($keys as $k) {
        if ((is_array($values)) && (array_key_exists($k, $values))) $v[$k] = stripslashes($values[$k]);
        elseif ((is_object($values)) && (property_exists($values, $k))) $v[$k] = stripslashes($values->$k);
        else $v[$k] = "";
    }

    if ($GLOBALS["user"]->isAuthenticated()) {
        $customers->Fetch("customer_user = {$GLOBALS["user"]->user_id}");
        $cust = current($customers->customers);
        foreach ($keys as $k)
            if (property_exists($cust, $k)) $v[$k] = $cust->$k;
    }
    $stock = array();
    $out = array();
    $quote = array();
    ?>
        <h1>Confirm Your Order</h1>
        <p>Please review your order for accuracy before submitting. While we make every effort to ensure the accuracy of this information, stock status, pricing, and available options may vary. Please <a href="/contact/">contact us</a> for current pricing and availability or for help placing your order.</p>
        <h2 id="phone">1-479-474-3434</h2>

        <form method="POST" action="">
            <fieldset id="customer_products">
                <legend>Products Ordered</legend>
                <table style="margin: 0 auto;">
                    <thead>
                    <tr>
                        <td>Part Number</td>
                        <td>Product Description</td>
                        <td>Quantity</td>
                        <td>Price</td>
                        <td>Shipping</td>
                        <td>Sub-Total</td>
                    </tr>
                    </thead>

                <?php
                foreach ($cart->cart_items as $i) {
                    if ($i->item_stock) $stock[] = $i->item_id;
                    else $out[] = $i->item_id;
                    if (strcmp($i->item_price, "Call") == 0) $quote[] = $i->item_id;
                    elseif ($i->item_shipping == -1) $quote[] = $i->item_id;
                    $p = $products->products[$i->item_id];
                    $m = $mans->manufacturers[$p->product_manufacturer];
                    $link = "/catalog/" . $m->getUrl() . "/" . $p->getUrl() . "/";
                    ?>
                    <tr>
                        <td><a href="<?php echo $link; ?>"><?php echo htmlspecialchars($i->item_title); ?></a></td>
                        <td><a href="<?php echo $link; ?>"><?php echo htmlspecialchars($m->manufacturer_name . " " . $p->product_name); ?></a></td>
                        <td><input type="text" size="1" id="cart_qty[<?php echo $i->item_id; ?>]" name="cart_qty[<?php echo $i->item_id; ?>]" value="<?php echo $i->item_quantity; ?>"></td>
                        <td><?php echo $i->item_price; ?></td>
                        <td><?php
                            if ($i->item_shipping == -1) echo "Call";
                            elseif ((int)$i->item_shipping == 0) echo "FREE";
                            else printf("\$%1\$.2f", $i->item_shipping); ?>
                        </td>
                        <td><?php
                            $price = (float) substr($i->item_price, 1) * (int) $i->item_quantity;
                            if ($i->item_shipping > 0) $price += (float) $i->item_shipping * $i->item_quantity; ?>
                            <?php printf("\$%1\$.2f", $price); ?>
                        </td>
                    </tr>
                <?php } ?>
                    <tr>
                        <td colspan="4">
                            <input type="submit" id="cart_update" name="cart_update" value="Update Order"><br>

                            <?php
                            if (count($out)) {
                                echo "<p>The following items are currently out-of-stock: ";
                                $str = "";
                                foreach ($out as $id) {
                                    $i = $cart->cart_items[$id];
                                    $str .= htmlspecialchars($i->item_title) . ", ";
                                }
                                echo substr($str, 0, -2) . "</p>\n";
                                echo "<p>When items are not in stock, we only require a 10% non-refundable deposit to place the order. The remaining balance is due once the item is in stock. You will only be billed for the deposit amount at this time.</p>\n";
                            }
                            ?>
                        </td>
                        <td colspan="2">
                            <table style="text-align: right;">
                                <tr>
                                    <td><em>Sub-Total</em>:</td>
                                    <td><?php printf("\$%1\$.2f", $cart->cart_total - $cart->cart_shipping); ?></td>
                                </tr>
                                <tr>
                                    <td><em>Shipping</em>:</td>
                                    <td><?php printf("\$%1\$.2f", $cart->cart_shipping); ?></td>
                                </tr>
                                <tr>
                                    <td><em>Discount Total</em>:</td>
                                    <td><?php printf("\$%1\$.2f", $cart->cart_total); ?></td>
                                </tr>
                                <tr>
                                    <td><em>Grand Total</em>:</td>
                                    <td><?php printf("\$%1\$.2f", $cart->cart_total + $cart->cart_procfee); ?></td>
                                </tr>
                                <?php if (count($out)) { ?>
                                <tr>
                                    <td><em>Deposit Due</em>:</td>
                                    <td><?php printf("\$%1\$.2f", $cart->cart_deposit); ?></td>
                                </tr>
                                <?php } ?>
                            </table>
                        </td>
                    </tr>
                </table>
            </fieldset>


        <fieldset id="customer_payment">
            <legend>Payment Information</legend>

            <?php if (count($quote)) { ?>
            <p>The following items are missing pricing information:
            <?php
            $str = "";
            foreach ($quote as $id) {
                $i = $cart->cart_items[$id];
                $str .= htmlspecialchars($i->item_title) . ", ";
            }
            echo substr($str, 0, -2) . "</p>\n";
            ?>
            <p>Our sales staff will update this order to provide accurate pricing, after which you will be notified by email or phone. Once updated, payment options will be available.</p>
            <?php } else { ?>
            <table>
                <colgroup>
                    <col width="40%">
                    <col width="20%">
                    <col width="40%">
                </colgroup>
                <tr>
                    <td><input type="radio" name="customer_payment" value="check" checked="CHECKED"> Check or Money Order</td>
                    <td></td>
                    <td><input type="radio" name="customer_payment" value="credit"> Credit Card</td>
                </tr>
                <tr>
                    <td>
                        <ul>
                            <li>Total: $<?php printf("%1\$.2f", $cart->cart_total); ?></li>
                            <?php if (count($out)) { ?> <li>Deposit: $<?php printf("%1\$.2f", $cart->cart_deposit); ?></li> <?php } ?>
                        </ul>
                        <p>If you would like to send a check or money order, please remit to the address below and be sure to include the order number which will be generated upon submission.</p>
                        Agency Equipment<br>PO Box 5819<br>Chino Valley, AZ 86323
                    </td>
                    <td>
                        <a href="https://seal.godaddy.com/verifySeal?sealID=PBjWMFsjMH8EtLsabEmOA70pBqD6q3cbUUiUP9JieXhUmoA3lQpBopgmav7z" title="Verified Secure Shopping" target="_blank"><img src="/images/gdseal.gif" alt="Verified SSL Encryption"></a><br>
                        <a href="https://seal.godaddy.com/verifySeal?sealID=PBjWMFsjMH8EtLsabEmOA70pBqD6q3cbUUiUP9JieXhUmoA3lQpBopgmav7z" title="Verified Secure Shopping" target="_blank"><img src="/images/cclogos.jpg" alt="Credit Cards Accepted"></a>
                    </td>
                    <td>
                        <ul>
                            <li>Total: $<?php printf("%1\$.2f", $cart->cart_total + $cart->cart_procfee); ?></li>
                            <?php if (count($out)) { ?> <li>Deposit: $<?php printf("%1\$.2f", $cart->cart_deposit + ($cart->cart_deposit * 0.025)); ?></li> <?php } ?>
                        </ul>
                        <p>To remain competitive, our pricing reflects a 2.5% discount for payment via cash or check.</p>
                        <table>
                            <tr>
                                <td>Card Type:</td>
                                <td><select name="customer_cctype" id="customer_cctype"><option></option><option value="visa">VISA</option><option value="mc">Mastercard</option><option value="disc">Discover</option><option value="amex">American Express</option></select></td>
                            </tr>
                            <tr>
                                <td>Card Number:</td>
                                <td><input type="text" id="customer_ccnum" name="customer_ccnum" value="<?php echo $v["customer_ccnum"]; ?>"></td>
                            </tr>
                            <tr>
                                <td>Expiration:</td>
                                <td><select id="customer_ccmm" name="customer_ccmm">
                                    <option>MM</option>
                                    <option value=1>01</option>
                                    <option value=2>02</option>
                                    <option value=3>03</option>
                                    <option value=4>04</option>
                                    <option value=5>05</option>
                                    <option value=6>06</option>
                                    <option value=7>07</option>
                                    <option value=8>08</option>
                                    <option value=9>09</option>
                                    <option value=10>10</option>
                                    <option value=11>11</option>
                                    <option value=12>12</option>
                                    </select>
                                    <select id="customer_ccyy" name="customer_ccyy">
                                    <option>YY</option>
                                    <option value=10>10</option>
                                    <option value=11>11</option>
                                    <option value=12>12</option>
                                    <option value=13>13</option>
                                    <option value=14>14</option>
                                    <option value=15>15</option>
                                    <option value=16>16</option>
                                    <option value=17>17</option>
                                    <option value=18>18</option>
                                    <option value=19>19</option>
                                    <option value=20>20</option>
                                    </select>
                                </td>
                            </tr>
                            <tr>
                                <td>Card CVV Number:</td>
                                <td><input type="text" id="customer_cccvv" name="customer_cccvv" value="<?php echo $v["customer_cccvv"]; ?>"></td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
            <?php } ?>
        </fieldset>

        <fieldset id="customer_info">
            <legend>Customer Information</legend>
            <table>
                <tr>
                    <td>
                        <table>
                            <caption>Personal Information:</caption>
                            <tr>
                                <td class="label"><label for="customer_fname">First Name:</label></td>
                                <td><input type="text" id="customer_fname" name="customer_fname" value="<?php echo $v["customer_fname"]; ?>"><td>
                            </tr>
                            <tr>
                                <td class="label"><label for="customer_mname">Middle Name:</label></td>
                                <td><input type="text" id="customer_mname" name="customer_mname" value="<?php echo $v["customer_mname"]; ?>"></td>
                            </tr>
                            <tr>
                                <td class="label"><label for="customer_lname">Last Name:</label></td>
                                <td><input type="text" id="customer_lname" name="customer_lname" value="<?php echo $v["customer_lname"]; ?>"></td>
                            </tr>
                            <tr>
                                <td class="label"><label for="customer_company">Company Name:</label></td>
                                <td><input type="text" id="customer_company" name="customer_company" value="<?php echo $v["customer_company"]; ?>"></td>
                            </tr>
                        </table>
                    </td>
                    <td>
                        <table>
                            <caption>Contact Information:</caption>
                            <tr>
                                <td class="label"><label for="customer_email">Email Address:</label></td>
                                <td><input type="text" id="customer_email" name="customer_email" value="<?php echo $v["customer_email"]; ?>"></td>
                            </tr>
                            <tr>
                                <td class="label"><label for="customer_phone_main">Main Phone:</label></td>
                                <td><input type="text" id="customer_phone_main" name="customer_phone_main" value="<?php echo $v["customer_phone_main"]; ?>"></td>
                            </tr>
                            <tr>
                                <td class="label"><label for="customer_phone_alt">Alt Phone:</label></td>
                                <td><input type="text" id="customer_phone_alt" name="customer_phone_alt" value="<?php echo $v["customer_phone_alt"]; ?>"></td>
                            </tr>
                            <tr>
                                <td class="label"><label for="customer_phone_fax">Fax Number:</label></td>
                                <td><input type="text" id="customer_phone_fax" name="customer_phone_fax" value="<?php echo $v["customer_phone_fax"]; ?>"></td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
        </fieldset>

        <fieldset id="customer_address">
            <legend>Customer Address</legend>
            <table>
                <tr>
                    <td>
                        <table>
                            <caption>Bill To:</caption>
                            <tr>
                                <td class="label"><label for="customer_billaddr_one">Billing Address:</label></td>
                                <td><input type="text" id="customer_billaddr_one" name="customer_billaddr_one" value="<?php echo $v["customer_billaddr_one"]; ?>"></td>
                            </tr>
                            <tr>
                                <td class="label"><label for="customer_billaddr_two">Address Line 2:</label></td>
                                <td><input type="text" id="customer_billaddr_two" name="customer_billaddr_two" value="<?php echo $v["customer_billaddr_two"]; ?>"></td>
                            </tr>
                            <tr>
                                <td class="label"><label for="customer_billaddr_city">City:</label></td>
                                <td><input type="text" id="customer_billaddr_city" name="customer_billaddr_city" value="<?php echo $v["customer_billaddr_city"]; ?>"></td>
                            </tr>
                            <tr>
                                <td class="label"><label for="customer_billaddr_state">State:</label></td>
                                <td><input type="text" id="customer_billaddr_state" name="customer_billaddr_state" value="<?php echo $v["customer_billaddr_state"]; ?>"></td>
                            </tr>
                            <tr>
                                <td class="label"><label for="customer_billaddr_zipcode">Zip Code:</label></td>
                                <td><input type="text" id="customer_billaddr_zipcode" name="customer_billaddr_zipcode" value="<?php echo $v["customer_billaddr_zipcode"]; ?>"></td>
                            </tr>
                        </table>
                    </td>
                    <td>
                        <table>
                            <caption>Ship To:</caption>
                            <tr>
                                <td class="label"><label for="customer_shipaddr_one">Shipping Address:</label></td>
                                <td><input type="text" id="customer_shipaddr_one" name="customer_shipaddr_one" value="<?php echo $v["customer_shipaddr_one"]; ?>"></td>
                            </tr>
                            <tr>
                                <td class="label"><label for="customer_shipaddr_two">Address Line 2:</label></td>
                                <td><input type="text" id="customer_shipaddr_two" name="customer_shipaddr_two" value="<?php echo $v["customer_shipaddr_two"]; ?>"></td>
                            </tr>
                            <tr>
                                <td class="label"><label for="customer_shipaddr_city">City:</label></td>
                                <td><input type="text" id="customer_shipaddr_city" name="customer_shipaddr_city" value="<?php echo $v["customer_shipaddr_city"]; ?>"></td>
                            </tr>
                            <tr>
                                <td class="label"><label for="customer_shipaddr_state">State:</label></td>
                                <td><input type="text" id="customer_shipaddr_state" name="customer_shipaddr_state" value="<?php echo $v["customer_shipaddr_state"]; ?>"></td>
                            </tr>
                            <tr>
                                <td class="label"><label for="customer_shipaddr_zipcode">Zip Code:</label></td>
                                <td><input type="text" id="customer_shipaddr_zipcode" name="customer_shipaddr_zipcode" value="<?php echo $v["customer_shipaddr_zipcode"]; ?>"></td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
        </fieldset>

        <fieldset id="customer_notes">
            <legend>Customer Notes</legend>
            <table>
                <tr>
                    <td>
                        <table>
                            <tr>
                                <td>FFL Transfer Dealer:</td>
                            </tr>
                            <tr>
                                <td><textarea id="customer_ffl" name="customer_ffl" rows="5" cols="22"><?php echo $v["customer_ffl"]; ?></textarea></td>
                            </tr>
                        </table>
                    </td>
                    <td>
                        <table>
                            <tr>
                                <td>Special Instructions:</td>
                            </tr>
                            <tr>
                                <td><textarea id="customer_notes" name="customer_notes" rows="5" cols="22"><?php echo $v["customer_notes"]; ?></textarea></td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
        </fieldset>

        <?php if (! $GLOBALS["user"]->isAuthenticated()) { ?>
        <fieldset id="customer_account">
            <legend>Account Information</legend>
            <table>
                <tr>
                    <td>
                        <table>
                            <tr>
                                <td class="label"><label for="customer_pass1">Password:</label></td>
                                <td><input type="password" id="customer_pass1" name="customer_pass1" value="<?php echo $v["customer_pass1"]; ?>"></td>
                            </tr>
                            <tr>
                                <td class="label"><label for="customer_pass2">Confirm:</label></td>
                                <td><input type="password" id="customer_pass2" name="customer_pass2" value="<?php echo $v["customer_pass2"]; ?>"></td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
            <p>By entering a password, you will be able to log in with your email address and access your order history, although it is not required to place the order.</p>
        </fieldset>
        <?php } ?>

        <div>
            <input type="checkbox" name="customer_agreed" id="customer_agreed"> I understand and agree to the <a href="/terms/">terms and conditions</a>  of this sale.<br><br>
            <input type="submit" name="customer_order_new" id="customer_order_new" value="Submit Order">
        </div>
    </form>

    <?php
}
 


Top
 Profile  
 
PostPosted: Fri Oct 08, 2010 2:16 pm 
Offline
Briney Mod
User avatar

Joined: Mon Jan 19, 2004 7:11 pm
Posts: 6446
Location: 53.01N x 112.48W
Duplicate post. Locking.

_________________
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group