Page 1 of 2

About to get fired over this

Posted: Fri Oct 08, 2010 1:43 pm
by lostinthecode
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.

Code: Select all

<?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
}

Re: About to get fired over this

Posted: Fri Oct 08, 2010 2:18 pm
by pickle
If that's your boss, I wouldn't be worried at all about losing your job. It's not a job worth keeping.

Re: About to get fired over this

Posted: Fri Oct 08, 2010 2:19 pm
by lostinthecode
I would agree with you but it is almost impossible to find a decent computer related job in Fort Smith, Arkansas, actually any decent job for that matter.

Re: About to get fired over this

Posted: Fri Oct 08, 2010 2:20 pm
by s.dot

Code: Select all

<?php

$cart->loadItemInfo();
How can that be the start of your file?
Where is $cart instantiated and the cart object and loadItemInfo() method defined?

Re: About to get fired over this

Posted: Fri Oct 08, 2010 2:23 pm
by lostinthecode

Code: Select all

<?php

class CatalogCartItem
{
    public $item_id = 0;
    public $item_quantity = 0;
    public $item_title = "";
    public $item_price = 0.0;
    public $item_shipping = 0.0;
    public $item_desc = "";
    public $item_total = 0.0;
    public $item_stock = FALSE;
    public $item_transfer = FALSE;

    public function __construct($i, $q)
    {
        $this->item_id = (int) $i;
        $this->item_quantity = (int) $q;
    }
}

class CatalogCart
{
    public $cart_id = 0;
    public $cart_total = 0.0;
    public $cart_shipping = 0.0;
    public $cart_procfee = 0.0;
    public $cart_deposit = 0.0;
    public $cart_items = array();

    public function __construct($content)
    {
        if ($content) {
            $this->cart_id = $content->cart_id;
            foreach($content->cart_items as $i) {
                $this->cart_items[$i->item_id] = new CatalogCartItem($i->item_id, $i->item_quantity);
            }
        }
    }

    public function loadItemInfo()
    {
        $products = $GLOBALS["products"];
        if (count($this->cart_items)) {
            $this->cart_total = 0.0;
            $this->cart_shipping = 0.0;
            $this->cart_deposit = 0.0;
            $this->cart_procfee = 0.0;
            $str = "";
            foreach ($this->cart_items as $i) $str .= $i->item_id . ", ";
            $str = substr($str, 0, -2);
            $products->Fetch("product_id IN ({$str})");
            foreach ($this->cart_items as $i) {
                $i->item_title = $products->products[$i->item_id]->product_partno;
                $i->item_price = $products->products[$i->item_id]->getPrice();
                $i->item_shipping = $products->products[$i->item_id]->product_shipping;
                $i->item_total = ((float) substr($i->item_price, 1));
                if ($i->item_shipping > 0) $i->item_total += ((float) $i->item_shipping);
                $i->item_transfer = $products->products[$i->item_id]->product_transfer;
                $i->item_desc = $products->products[$i->item_id]->product_name;
                // FIXME: Add real inventory quantity here
                $i->item_stock = 0;
                if ($products->products[$i->item_id]->product_status == 1001)
                    $i->item_stock = 1;
                if ($i->item_stock >= $i->item_quantity) {
                    $this->cart_deposit += ((float) $i->item_total * $i->item_quantity);
                } else {
                    for ($x = 1; $x <= $i->item_quantity; $x++) {
                        if ($x <= $i->item_stock) $this->cart_deposit += ((float) $i->item_total);
                        else $this->cart_deposit += ((float) $i->item_total * 0.1);
                    }
                }
                $this->cart_deposit = (float) sprintf("%1\$.2f", $this->cart_deposit);
                $this->cart_shipping += ($i->item_shipping > 0) ? $i->item_shipping * $i->item_quantity : 0;
                $this->cart_total += ((float) $i->item_total * $i->item_quantity);
            }
            $this->cart_procfee = (float) sprintf("%1\$.2f", $this->cart_total * 0.025);
        }
    }

    public function addToCart($product, $quantity)
    {
        if (array_key_exists($product, $this->cart_items)) {
            $this->cart_items[$product]->item_quantity = $quantity;
        } else {
            $this->cart_items[$product] = new CatalogCartItem($product, $quantity);
        }
        $this->saveCart();
    }

    public function saveCart()
    {
        $_SESSION["cart"] = serialize($this);
    }
}

this is a separate php file called cart.php, If it will help I can include a test account to the website so that someone can see the error firsthand.

Re: About to get fired over this

Posted: Fri Oct 08, 2010 2:25 pm
by s.dot
You will need to include the cart class before you can use the $cart variable.

Re: About to get fired over this

Posted: Fri Oct 08, 2010 2:30 pm
by lostinthecode
Test account for http://www.agencyequipment.com username: test@test.com password: test
Our other website http://www.tombstonetactical.com uses all the same php and phtml files and the cart is working just fine, however that website is hosted on godaddy and the other is on hostgator

Re: About to get fired over this

Posted: Fri Oct 08, 2010 2:34 pm
by lostinthecode
The main problem I have is that it will let me add to the cart but when I select checkout it says the cart is empty.

Re: About to get fired over this

Posted: Fri Oct 08, 2010 2:41 pm
by twinedev
Agreed, if that if the code you posted is the code that gets directly called when I hit http://www.agencyequipment.com/checkout/ then it is most likely an issue of missing code such as:

$cart = new CatalogCart to set the class to be used.

to verify this, right before $cart->loadItemInfo(); do this:

Code: Select all

var_dump($cart);
and then call the page (yeah it will look ugly, but see if it returns NULL (never defined), or it is says it is a instance of the class).

-Greg

Re: About to get fired over this

Posted: Fri Oct 08, 2010 2:44 pm
by lostinthecode
object(CatalogCart)#4 (6) { ["cart_id"]=> int(0) ["cart_total"]=> float(0) ["cart_shipping"]=> float(0) ["cart_procfee"]=> float(0) ["cart_deposit"]=> float(0) ["cart_items"]=> array(0) { } }  is what shows when I add the vardump

Re: About to get fired over this

Posted: Fri Oct 08, 2010 2:47 pm
by John Cartwright
Ugh, reminds me of a script I would have written 10 years ago!

All I can recommend is turn on error_reporting(E_ALL); and make sure you have called session_start() before any output.

Re: About to get fired over this

Posted: Fri Oct 08, 2010 2:52 pm
by Benjamin
I will reiterate what John said. Check the error log. Otherwise everyone is shooting in the dark.

Re: About to get fired over this

Posted: Fri Oct 08, 2010 3:49 pm
by Jonah Bron
s.dot wrote:

Code: Select all

<?php

$cart->loadItemInfo();
How can that be the start of your file?
Where is $cart instantiated and the cart object and loadItemInfo() method defined?
This page might be included by another file.

Re: About to get fired over this

Posted: Fri Oct 08, 2010 3:53 pm
by lostinthecode
I have set error_reporting = E_ALL and there are no errors coming up that relate to the checkout or cart the only error is an array error with one of the manufacturers that I deleted. So i'm back at square one :(

Re: About to get fired over this

Posted: Fri Oct 08, 2010 4:11 pm
by Obadiah
Jonah Bron wrote:
s.dot wrote:

Code: Select all

<?php

$cart->loadItemInfo();
How can that be the start of your file?
Where is $cart instantiated and the cart object and loadItemInfo() method defined?
This page might be included by another file.
indeed...i would look for a file that has

Code: Select all

include("shopping cart.php");
on it or something...it has to be included