parameter . "
"; // determine if the cart already exists in the database $cart = get_cart_data ($hmSQL, $st_tbShoppingCarts, $sc_cart_id); if (is_object($cart) == true and $REQUEST_METHOD == "GET" and $product_id != "") // we have the cart information in a cart object { // we now have the cart information in the cart object. first get the product information and then add the item to the cart. //echo $product_id; $product = get_product_data($hmSQL, $st_tbProducts, $product_id, $cart->coupon_id); // item is added to the cart $cart_item = new_cart_item($hmSQL, $st_tbCartItems, $cart, $product); // we get the available open package $package = get_open_package ($hmSQL, $st_tbPackages, $cart->id); // echo "PACKAGE_TYPE: " . gettype($package) . "
"; if (is_string($package) != true) // an error occured in the process { if (is_integer($package) == true and $package == 0) // there are no open packages, must create a new package { // create a new package $package = new_package ($hmSQL, $st_tbPackages, $cart->id, $ar_store_configuration, 1); // add the item to the package new_package_item ($hmSQL, $st_tbPackageItems, $package->id, $product->id); } else if (is_object($package) == true) { // if this item is a freight item, i.e. it's weight is equal or greater than the threshold freight weight, close the package if (isset($ar_store_configuration["fw"]) == true and $product->weight >= $ar_store_configuration["fw"]->parameter_value) { // create a new package first $package = new_package ($hmSQL, $st_tbPackages, $cart->id, $ar_store_configuration, 0); // add the item to the package new_package_item ($hmSQL, $st_tbPackageItems, $package->id, $product->id); // update the package information, closing the package /*$package->is_open = 0; if (($tmp = update_table ($hmSQL, $st_tbPackages, "is_open", $package->is_open, "numeric", "id", $package->id, "numeric")) != true) $st_database_error .= $tmp . "
";*/ }else { // add the item to the package new_package_item ($hmSQL, $st_tbPackageItems, $package->id, $product->id); } }else $st_database_error .= $package . "
"; }else $st_database_error .= $package . "
"; }else if(is_integer($cart) == true and $cart == 0 and $REQUEST_METHOD == "GET" and $product_id != "") // the cart information is not found in the database { // create the new cart item, return an object. $cart = new_cart ($hmSQL, $st_tbShoppingCarts, $sc_cart_id, $ar_store_configuration); if (is_object($cart) == true ) { // first get the product information and then add the item to the cart. $product = get_product_data($hmSQL, $st_tbProducts, $product_id, $cart->coupon_id); if (is_object($product) == true) { // item is added to the cart $cart_item = new_cart_item($hmSQL, $st_tbCartItems, $cart, $product); // now we can create the first package for the shopping cart $package = new_package ($hmSQL, $st_tbPackages, $cart->id, $ar_store_configuration, 1); if (is_object($package) == true) { // add the item to the package new_package_item ($hmSQL, $st_tbPackageItems, $package->id, $product->id); }else $st_database_error .= $package . "
"; // if this item is a freight item, i.e. it's weight is equal or greater than the threshold freight weight, close the package if (isset($ar_store_configuration["fw"]) == true and $product->weight >= $ar_store_configuration["fw"]->parameter_value) { // update the package information, closing the package $package->is_open = 0; if (($tmp = update_table ($hmSQL, $st_tbPackages, "is_open", $package->is_open, "numeric", "id", $package->id, "numeric")) != true) $st_database_error .= $tmp . "
"; } }else $st_database_error .= $product . "
"; }else $st_database_error .= $cart . "
"; }else if (is_object($cart) == true and $REQUEST_METHOD == "POST") // this is a post operation, update the database { // first we do the update sequence , then we do the delete sequence; we have the cart data in the cart object // echo "
update_cart_item: " . count($update_cart_item); // echo "
update_quantity: " . count($update_quantity); // echo "
update_remove_item: " . count($update_remove_item); // echo "

"; if ($cmdEstimate == "") // Make sure the user updated the card and not shipping info { // first: we update the cart items with quantity > 0 and recalculate totals for ($in_A = 1; $in_A <= count($update_cart_item); $in_A++) { // dynamically generate the unique identifier name for the remove check box $tmp = "update_remove_item" . $update_cart_item[$in_A-1]; // if (isset($$tmp) == true) echo "KEY update_remove_item: " . $$tmp . "
"; // echo "KEY update_cart_item : " . $update_cart_item[$in_A-1] . "
"; // echo "KEY update_quantity : " . $update_quantity[$in_A-1] . "
"; // we set items with quantity <= 0 to be deleted if (isset($$tmp) == true) { $update_quantity[$in_A-1] = 0; } // get the cart item's information $cart_item = get_cart_item_data ($hmSQL, $st_tbCartItems, $update_cart_item[$in_A-1]); if (is_object($cart_item) == true) { // update the packages accordingly; do this first update_cart_packages ($hmSQL, $st_tbProducts, $st_tbCartItems, $st_tbPackages, $st_tbPackageItems, $cart, $cart_item, $update_quantity[$in_A-1], $ar_store_configuration); // the cart item information is now in the cart_item object variable $cart_item->quantity = $update_quantity[$in_A-1]; // update information with the form submission $cart_item->total = $cart_item->quantity * $cart_item->price; // recalculate total for cart item in cart object // update the database record; if quantity is not zero, else remove the cart item record if ($cart_item->quantity > 0) $st_sql = "update $st_tbCartItems set quantity = $cart_item->quantity, total = $cart_item->total where id = $cart_item->id"; else $st_sql = "delete from $st_tbCartItems where id = $cart_item->id"; // echo "UPDATE CART ITEMS INFORMATION: $st_sql
"; if (mysql_query($st_sql, $hmSQL) == 0) $st_database_error .= mysql_error() . "
"; }else $st_database_error .= mysql_error() . "
"; } } }else if (is_object($cart) == true and $REQUEST_METHOD == "GET") ; // do nothing // else $st_database_error .= $cart . "
"; // START: GET ALL THE CART INFORMATION FROM THE DATABASE AND PUT INTO MEMERY FOR DISPLAY. if (is_object($cart) == true) { // At this point, we have a valid cart that may or may not have any items in it // Now we retrieve all the items in the cart and display store it in an array. $st_sql = "select $st_tbCartItems.id, $st_tbCartItems.item_id, $st_tbCartItems.quantity, $st_tbCartItems.price, $st_tbCartItems.total, $st_tbProducts.description, "; $st_sql .= "$st_tbProducts.title, $st_tbProducts.sku, $st_tbProducts.name from $st_tbProducts, $st_tbCartItems "; $st_sql .= "where $st_tbProducts.id = $st_tbCartItems.item_id and $st_tbCartItems.cart_id = $cart->id "; $st_sql .= "order by $st_tbCartItems.price"; // echo "GET CART_ITEMS: $st_sql
"; $hSQL = mysql_query($st_sql, $hmSQL); if ($hSQL > 0) { $in_rows = mysql_num_rows($hSQL); $cart->sub_total = $cart->total_tax = $cart->total_shipping = $cart->grand_total = $cart->weight = 0; //echo "WEIGHT1: $cart->weight
"; for ($in_A = 1; $in_A <= $in_rows; $in_A++) { if (mysql_data_seek($hSQL, $in_A-1) == 0) { $st_database_error .= mysql_error(); continue; } $ar_row = mysql_fetch_array($hSQL); $ar_cart_items[$in_A-1] = new CCartItem; $ar_cart_items[$in_A-1]->id = $ar_row["id"]; $ar_cart_items[$in_A-1]->item_id = $ar_row["item_id"]; $ar_cart_items[$in_A-1]->quantity = $ar_row["quantity"]; $ar_cart_items[$in_A-1]->title = $ar_row["title"]; $ar_cart_items[$in_A-1]->price = $ar_row["price"]; $ar_cart_items[$in_A-1]->total = $ar_row["total"]; $ar_cart_items[$in_A-1]->description = $ar_row["description"]; $ar_cart_items[$in_A-1]->sku = $ar_row["sku"]; $ar_cart_items[$in_A-1]->weight = $ar_row["weight"]; //$cart->sub_total += $ar_cart_items[$in_A-1]->total; // See below $cart->weight += $ar_cart_items[$in_A-1]->weight * $ar_cart_items[$in_A-1]->quantity; // echo "
TEST: " . $ar_row["description"]; // ******************************************************************* // If the customer has a coupon, see if this item is discounted, // otherwise charge the normal price if (is_int($cart->coupon_id)) { $item_price = get_product_coupon_price ($ar_row["id"], $cart->coupon_id); if (($item_price > 0) && ($item_price < $ar_row["price"])) $cart->sub_total += $item_price; else $cart->sub_total += $ar_cart_items[$in_A-1]->total; } else $cart->sub_total += $ar_cart_items[$in_A-1]->total; // ******************************************************************* } // update the database cart records:... update_table ($hmSQL, $st_tbShoppingCarts, "sub_total", $cart->sub_total, "numeric", "id", $cart->id, "numeric"); update_table ($hmSQL, $st_tbShoppingCarts, "total_tax", $cart->total_tax, "numeric", "id", $cart->id, "numeric"); update_table ($hmSQL, $st_tbShoppingCarts, "total_shipping", $cart->total_shipping, "numeric", "id", $cart->id, "numeric"); update_table ($hmSQL, $st_tbShoppingCarts, "grand_total", $cart->grand_total, "numeric", "id", $cart->id, "numeric"); }else $st_database_error .= mysql_error() . "
"; } // END:GET ALL THE CART INFORMATION FROM THE DATABASE AND PUT INTO MEMERY FOR DISPLAY. // get the courier services if ($estimation_zipcode != "") { $ar_courierservices = get_courier_services ($hmSQL, $st_tbCourierServices); if (is_array($ar_courierservices) == false) { $st_database_error .= $ar_courierservices . "
"; unset($ar_courierservices); } } // get the tax_rate if we have the state and zipcode if ($estimation_zipcode != "" and $estimation_state != "") { // get the estimated cart tax rate $cart->tax_rate = tax_rate ($hmSQL, $st_tbTax, $estimation_zipcode, $estimation_state); if (is_string($cart->tax_rate) == true) { $st_database_error .= $cart->tax_rate . "
"; $cart->tax_rate = 0; } // echo "RATE: $cart->tax_rate
"; $cart->total_tax = $cart->sub_total * $cart->tax_rate; // echo "TAX: $cart->total_tax
"; } // require "$st_web_root" . "/includes/common/mySQL.close.inc"; if ($return_to_referer == true) { echo ""; exit; }else if ($redirect != "") { echo ""; exit; } // get the cart footer object and selectively dissable the icons that we do not want displayed $cart_footer = get_shopping_cart_footer_object (); $cart_footer->display_view_cart = 0; ?>
" method="post"> 0) { echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; for ($in_A = 1; $in_A <= count($ar_cart_items); $in_A++) // also initialize cart_total variable { if ($in_A % 2 == 1) $bgcolor = "#DDDDDD"; else $bgcolor = "#FFFFFF"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; $tmp = "update_remove_item" . $ar_cart_items[$in_A-1]->id; // echo $tmp ; echo " \n"; } echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo ""; echo ""; echo " \n"; }else { echo " \n"; echo " \n"; echo " \n"; } ?> \n"; // echo " \n"; //echo " \n"; echo " \n"; echo " \n"; echo " \n"; ?>
Shopping Cart
\n"; echo " If you want to add additional items to your cart, please use the \n"; echo " navigational menu at the left to continue shopping. To remove an item from your cart, set the quantity to zero.

\n"; echo "
DescriptionItem #Unit PriceQuantityTotal
"; echo "" . $ar_cart_items[$in_A-1]->manufacturer . " "; echo $ar_cart_items[$in_A-1]->title . "" . $ar_cart_items[$in_A-1]->sku . " $ " . $ar_cart_items[$in_A-1]->price . "$ " . $ar_cart_items[$in_A-1]->total . "
 
Sub-Total$ " . sprintf ("%01.2f", $cart->sub_total) . "
"; echo ""; //echo "
"; echo "


Your cart is empty.

\n"; echo "

"; echo "

\n"; // require "$st_web_root" . "/includes/site/shopping_cart.inc"; // echo "
\n"; echo "