updateordercart()
{
// build the cartlist string
l_cartlist ="c_prodid=:p_prodid,c_quantity=:p_quantity";
// Replaced by the following logic. by Bill Atchison 10/04/99
if (0) {
search( DB_DIR,
"*",
"ST_OPTION",
""){
l_option_id = "OPT" & ST_OPTION.ID;
l_cartlist = l_cartlist & "," & l_option_id & "=:" & l_option_id;
}
}
for(i=0; i 0 ) {
parmid = substring( parmid, 0, loc-1 );
if( substring( parmid,0,3)=="OPT" ) {
if( varget( parmid ) == "" ) {
l_option_id = parmid;
varset(parmid,parmid);
l_cartlist = l_cartlist & "," & l_option_id & "=:" & l_option_id;
}
}
}
}
cartadd("cart_orderid", l_cartlist, "c_prodid"); l_count = 0; while (l_count < cartcount("cart_orderid")) { if( cartcount("cart_orderid")== 0 ) break; l_prodid = cartget("cart_orderid", "c_prodid", l_count); l_quantity = cartget("cart_orderid", "c_quantity", l_count); if( (l_quantity=="") || (l_prodid=="") ) { cartdel("cart_orderid", l_count); l_count = l_count - 1; continue; } l_count = l_count + 1; }
}
// build the product name and product options string
getoptions(l_prodid, l_cartindex)
{
// structure to return
l_option.text = "";
l_option.formfield = "";
l_option.priceadjust = 0;
search( DB_DIR,
"*",
"ST_OPTION",
"PID=:l_prodid",
"", "NAME"){
l_count = 0;
l_option_id = "OPT" & ST_OPTION.ID;
l_valuecount = cartvalcount("cart_orderid", l_option_id, l_cartindex);
if( l_valuecount== 0 ) continue;
l_option.text = l_option.text & ", " & ST_OPTION.NAME & ": ";
if( l_valuecount == 0 )
continue;
while (l_count < l_valuecount) {
l_optionval_id = cartget("cart_orderid", l_option_id, l_cartindex, l_count);
l_option.formfield = l_option.formfield &
"";
if (ST_OPTION.TYPE == "TEXT") {
l_option.text = l_option.text & l_optionval_id;
} else {
// get the value name
search( DB_DIR,
"*",
"ST_OPTIONVAL",
"ID=:l_optionval_id") {
if (l_count > 0) {
l_option.text = l_option.text & ", ";
}
l_option.text = l_option.text & ST_OPTIONVAL.NAME;
l_option.priceadjust = l_option.priceadjust + ST_OPTIONVAL.PRICE;
}
}
l_count = l_count + 1;
}
}
if (SQLCODE!=0) printtag("SQL_ERROR", ERR_FILE);
return l_option;
}
updatedisplaycart()
{
inline=0;
if( null(DB_DIR) ) {
configread("config.ini");
if (REMOTE_DB == "True") {
inline=1;
gvarset("DB_DIR", connect(DATABASE, DB_USERID, DB_PASSWORD, DB_CONNECT));
if (SQLCODE!=0) printtag("SQL_ERROR",ERR_FILE);
}
}
// based on the current order, create a new cart for display purposes
// search the database to get the correct product prices and information
cartdel("cart_display");
l_subtotal = 0;
l_taxable_subtotal = 0;
// first get total product quantities for volume discounts
l_count = 0;
while (l_count < cartcount("cart_orderid")) {
l_prodid = cartget("cart_orderid", "c_prodid", l_count);
l_quantity = cartget("cart_orderid", "c_quantity", l_count);
l_quantity = format( "%d", l_quantity );
if (l_quantity < 0) l_quantity = 1;
// get the initial product inventory
if (null(varget("l_inventory_" & l_prodid))) {
search( DB_DIR,
"*",
"ST_PRODUCTS",
"ID=:l_prodid")
{
if (ST_PRODUCTS.QTYCHECK == "Y") {
varset("l_inventory_" & l_prodid, ST_PRODUCTS.INVENTORY);
} else {
varset("l_inventory_" & l_prodid, "NA"); // no inventory check
}
}
}
// if inventory is enabled for the product, check stock
l_inventory = varget("l_inventory_" & l_prodid);
if (l_inventory != "NA") {
l_new_inventory = l_inventory - l_quantity;
if (l_new_inventory < 0) {
// add as many products as you can
if (l_inventory > 0) {
l_quantity = l_inventory;
varset("l_inventory_" & l_prodid, 0);
} else {
l_quantity = 0;
}
} else {
varset("l_inventory_" & l_prodid, l_new_inventory);
}
}
// end inventory check
varset("l_stock_item_" & l_count, l_quantity);
l_total_quantity = varget("l_quantity_" & l_prodid);
if (null(l_total_quantity)) l_total_quantity = 0;
varset("l_quantity_" & l_prodid, l_total_quantity + l_quantity);
l_count = l_count + 1;
}
// now calculate discounts and build the display cart
l_count = 0;
while (l_count < cartcount("cart_orderid")) {
l_prodid = cartget("cart_orderid", "c_prodid", l_count);
l_quantity = cartget("cart_orderid", "c_quantity", l_count);
l_quantity = format( "%d", l_quantity);
if (l_quantity < 0) l_quantity = 1;
search( DB_DIR,
"*",
"ST_PRODUCTS",
"ID=:l_prodid")
{
// check inventory levels
l_outofstock = "False";
l_quantity_reduced = "False";
// test that inventory is enabled for this product
if (varget("l_inventory_" & l_prodid) != "NA") {
l_inventory_check = "True";
l_stock = varget("l_stock_item_" & l_count);
if (l_stock < l_quantity) {
if (l_stock == 0) {
l_quantity = 0;
l_outofstock = "True";
} else {
l_quantity = l_stock;
l_quantity_reduced = "True";
}
}
} else {
l_inventory_check = "False";
}
// build the product name and product options string
l_option = getoptions(l_prodid, l_count);
l_prodname = ST_PRODUCTS.NAME;
l_partnum = ST_PRODUCTS.PARTNUM;
if (!null(l_option.text)) {
l_prodname = l_prodname & l_option.text;
}
l_prod_opt = l_option.formfield;
l_price = format("%.2f", ST_PRODUCTS.PRICE + l_option.priceadjust);
l_total = format("%.2f", l_price * l_quantity);
l_shipweight = ST_PRODUCTS.SHIPWEIGHT;
l_shipextra = ST_PRODUCTS.SHIPEXTRA;
l_subtotal = l_subtotal + l_total;
if (ST_PRODUCTS.NONTAX != "Y") {
l_taxable_subtotal = l_taxable_subtotal + l_total;
l_taxable = "True";
} else {
l_taxable = "False";
}
cartadd("cart_display", "c_prodid = :l_prodid," &
"c_partnum = :l_partnum," &
"c_prod_opt = :l_prod_opt," &
"c_prodname = :l_prodname," &
"c_outofstock= :l_outofstock," &
"c_price = :l_price," &
"c_quantity = :l_quantity," &
"c_shipweight = :l_shipweight," &
"c_shipextra = :l_shipextra," &
"c_inventory_check= :l_inventory_check," &
"c_taxable= :l_taxable," &
"c_total = :l_total");
// calculate any discount if the product is in stock
if (!l_outofstock) {
l_discount = ::st_prod::getdiscount(
l_prodid,
ST_PRODUCTS.GID,
l_price,
varget("l_quantity_" & l_prodid)
);
if (l_discount.price > 0) {
// add discount item to the cart
l_discount_price = format("%.2f", -l_discount.price);
l_discount_text = vprinttag("PRICE_REDUCED", "st_strings.html");
l_prod_opt = "";
l_total = format("%.2f", l_discount_price * l_quantity);
l_shipweight = 0;
l_shipextra = 0;
l_subtotal = l_subtotal + l_total;
if (ST_PRODUCTS.NONTAX != "Y") {
l_taxable_subtotal = l_taxable_subtotal + l_total;
}
l_readonly = "True";
cartadd("cart_display", "c_prodid = '-'," &
"c_prod_opt = :l_prod_opt," &
"c_prodname = :l_discount_text," &
"c_price = :l_discount_price," &
"c_quantity = :l_quantity," &
"c_shipweight = :l_shipweight," &
"c_shipextra = :l_shipextra," &
"c_taxable = :l_taxable," &
"c_total = :l_total," &
"c_readonly=:l_readonly");
}
}
// if the quantity was reduced, add an out-of-stock item to the cart
if (l_quantity_reduced) {
cartadd("cart_display", "c_prodid = :l_prodid," &
"c_prod_opt = :l_prod_opt," &
"c_prodname = :l_prodname," &
"c_outofstock= 'True'," &
"c_price = :l_price," &
"c_quantity = '0'," &
"c_shipweight = '0'," &
"c_shipextra = '0'," &
"c_taxable = :l_taxable," &
"c_total = '0.00'");
}
}
if (SQLCODE!=0) printtag("SQL_ERROR", ERR_FILE);
l_count = l_count + 1;
}
// set the subtotal, not including tax and shipping
stateset("s_subtotal", format("%.2f", l_subtotal));
stateset("s_taxable_subtotal", format("%.2f", l_taxable_subtotal));
if ( (REMOTE_DB == "True") && (inline==1)) {
disconnect( DB_DIR);
if (SQLCODE!=0) printtag("SQL_ERROR",ERR_FILE);
}
}
buildordertable()
{
// print out the beginning of the table and the header
printtagarea("ORDER_TABLE", "st_orderview.html", "table", "begin,1");
l_count = 0;
while (l_count < cartcount("cart_display")) {
l_prodid = cartget("cart_display", "c_prodid", l_count);
l_readonly = cartget("cart_display", "c_readonly", l_count);
if (l_readonly) {
l_checkbox = l_prodid;
l_quantity = cartget("cart_display", "c_quantity", l_count);
l_prodname = cartget("cart_display", "c_prodname", l_count);
} else {
// check if an item is sold out
l_outofstock = cartget("cart_display", "c_outofstock", l_count);
if (l_outofstock) {
l_checkbox = "-";
l_quantity = "- sold out -";
l_prodname = ""
& cartget("cart_display", "c_prodname", l_count) & "";
} else {
// set the form contents (hidden) of the order
// now build the display form fields
l_checkbox = "" & cartget("cart_display", "c_prod_opt", l_count);
l_quantity = "";
l_prodname = cartget("cart_display", "c_prodname", l_count);
}
}
l_price = cartget("cart_display", "c_price", l_count);
l_total = cartget("cart_display", "c_total", l_count);
l_count = l_count + 1;
printtagarea("ORDER_TABLE", "st_orderview.html", "table", "2");
}
// print out the total and bottom of the table
printtagarea("ORDER_TABLE", "st_orderview.html", "table", "3");
printtagarea("ORDER_TABLE", "st_orderview.html", "table", "end");
}
main ()
{if( pos(toupper(HTTP_USER_AGENT),"WEBTV") > 0 ) {
redirect("webtv.html");
}
configread("config.ini");
if( SHOPPLUS_SECURE_STORE=="True" ) {
if( (stateget("VALIDLOGON")!="True") || (stateget("s_sys_userlogon")!="True") ) {
redirect("user_login.html?p_page=st_main.html");
}
}
if (REMOTE_DB == "True") {
gvarset("DB_DIR", connect(DATABASE, DB_USERID, DB_PASSWORD, DB_CONNECT));
if (SQLCODE!=0) printtag("SQL_ERROR",ERR_FILE);
}
if (p_returnpage == "")
p_returnpage = "st_main.html";
if (func == "Update") {
cartdel("cart_orderid");
}
if ((func=="Order") || (func == "Update")){
stateset("s_valid_order", "False"); // invalidate the order
// update order and display cart
updateordercart();
updatedisplaycart();
}
if ( (func=="Order") && (SHOPPLUS_AUTO_SHOP=="True") ) { redirect (p_returnpage & "?p_catid=" & p_catid & "&p_prodid=" & p_prodid & "&catid=" & p_catid & "&p_keyword=" & p_keyword & "&p_letter=" & p_letter); }
printtag("HEADER");
printtag("BODY");
// The cart is empty
if (cartcount("cart_display") == 0) {
if (func=="Update"){
printtag("VIEW_NO_ITEMS_ERASE");
} else {
printtag("VIEW_NO_ITEMS");
}
} else {
// display order table
buildordertable();
}
printtag("FOOTER");
if (REMOTE_DB == "True") {
disconnect( DB_DIR);
if (SQLCODE!=0) printtag("SQL_ERROR",ERR_FILE);
}
}