// ---------------------------------------------------------------------------
// ShopZone ShopPlus 3.5
// (c) 1999-2002 by AutomatedShops.com, Inc. All Rights Reserved
// AutomatedShops.com
// http://www.automatedshops.com
//
// GiftRegistryEnhanced version 1
//
// To use the decimal cart feature set DECIMAL_QTY in CONFIG.INI
//
// For example:
// DECIMAL_QTY=2
//
// ---------------------------------------------------------------------------
updateordercart()
{
// build the cartlist string
l_cartlist ="c_prodid=:p_prodid,c_quantity=:p_quantity,c_giftreg=:p_giftreg";
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_quantity, l_cartindex)
{
// structure to return
l_option.text = "";
l_option.formfield = "";
l_option.priceadjust = 0;
// search for product options
search( DB_DIR, "*","ST_OPTINDEX","PID = :l_prodid","","SEQNUM ASC") {
l_oid=ST_OPTINDEX.OID;
search( DB_DIR,
"*",
"ST_OPTION",
"ID=:l_oid",
"", "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;
while (l_count < l_valuecount) {
l_optionval_id = cartget("cart_orderid", l_option_id, l_cartindex, l_count);
varset("l_opt_list." & l_option_id, l_optionval_id );
l_option.formfield = l_option.formfield &
"";
if (ST_OPTION.TYPE == "TEXT") {
if( l_optionval_id != "" ) {
l_option.text = l_option.text & ", " & ST_OPTION.NAME & ": " & 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 & ", " & ST_OPTION.NAME & ": ";
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;
} // search
} //else
l_count = l_count + 1;
} // while
} // search
if (SQLCODE!=0) printtag("SQL_ERROR", ERR_FILE);
} // end OPTINDEX
if (SQLCODE!=0) printtag("SQL_ERROR", ERR_FILE);
l_opts=verifyoption_list(l_prodid,l_opt_list);
if( l_opts!="") {
cartdel("cart_orderid", l_cartindex);
redirect ("st_prod.html?p_missing=Y&p_prodid=" & l_prodid & "&p_quantity=" & l_quantity & l_opts );
}
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( "%."&DECIMAL_QTY&"f", l_quantity );
if (l_quantity < 0) l_quantity = 1;
// BEGIN Gift Registry Mod
// if purchasing for gift registrant, check to make sure that l_quantity <= QTY_NEED - QTY_SOLD
l_giftreg = cartget("cart_orderid", "c_giftreg", l_count);
if (l_giftreg != "")
{
search( DB_DIR,
"*",
"GIFTREGISTRY",
"USERID=:l_giftreg AND PRODID=:l_prodid")
{
if (l_quantity > GIFTREGISTRY.QTY_NEED - GIFTREGISTRY.QTY_SOLD)
l_quantity = GIFTREGISTRY.QTY_NEED - GIFTREGISTRY.QTY_SOLD; // Can't order more than Registry Specifies
}
}
// END Gift Registry Mod
// 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
}
l_thumbnail = ST_PRODUCTS.THUMBNAIL;
if (!null(l_thumbnail)) {
l_thumbnail = ::util::getimagetag(l_thumbnail, ST_PRODUCTS.NAME);
varset("l_thumbnail_" & l_prodid, l_thumbnail);
}
}
}
// 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( "%."&DECIMAL_QTY&"f", l_quantity );
if (l_quantity < 0) l_quantity = 1;
l_giftreg = cartget("cart_orderid", "c_giftreg", l_count);
search( DB_DIR,
"*",
"ST_PRODUCTS",
"ID=:l_prodid")
{
// check inventory levels
l_outofstock = "False";
l_quantity_reduced = "False";
// BEGIN Gift Registry Mod
// if purchasing for gift registrant, check to make sure that l_quantity <= QTY_NEED - QTY_SOLD
if (l_giftreg != "")
{
search( DB_DIR,
"*",
"GIFTREGISTRY",
"USERID=:l_giftreg AND PRODID=:l_prodid")
{
if (l_quantity > GIFTREGISTRY.QTY_NEED - GIFTREGISTRY.QTY_SOLD)
l_quantity = GIFTREGISTRY.QTY_NEED - GIFTREGISTRY.QTY_SOLD; // Can't order more than Registry Specifies
}
}
// END Gift Registry Mod
// 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_quantity, 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";
}
l_thumbnail=varget("l_thumbnail_" & l_prodid);
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_giftreg = :l_giftreg," &
"c_thumb = :l_thumbnail," &
"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_giftreg = :l_giftreg," &
"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_giftreg = :l_giftreg," &
"c_total = '0.00'");
}
}
if (SQLCODE!=0) printtag("SQL_ERROR", ERR_FILE);
l_count = l_count + 1;
}
// Call coupons if it's installed
l_callback = "::st_coupon::AddCouponToCart";
if (funcexists(l_callback)) {
l_subtotal=call(l_callback,l_subtotal);
}
// 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
l_html=vprinttagarea("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);
l_thumbnail= ""
& cartget("cart_display", "c_thumb", 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 = cartget("cart_display", "c_quantity", l_count);
l_quantity = format( "%."&DECIMAL_QTY&"f", l_quantity );
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;
l_html=l_html & vprinttagarea("ORDER_TABLE", "st_orderview.html", "table", "2");
}
// print out the total and bottom of the table
l_html=l_html & vprinttagarea("ORDER_TABLE", "st_orderview.html", "table", "3");
l_html=l_html & vprinttagarea("ORDER_TABLE", "st_orderview.html", "table", "end");
return(l_html);
}
main ()
{
configread("config.ini");
::st_main::CheckStore();
// If a session Cookie isn't detected enable the
// ShopZone 3 style URL session tracking
if( checksession()=="False" ) {
enablesession();
}
::st_shopplus_util::GetLocalVars(); // Localization
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( p_registry!="" ) {
// If registry is installed
if ( !funcexists("::gr_giftregistry::main")) {
print("ERROR: Install the ShopZone Gift Registry to use this feature
");
exit();
}
if ( !funcexists("::user_login::main")) {
print("ERROR: Install the ShopZone User Logon to use this feature
");
exit();
}
l_op="&";
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_query=l_query & l_op & parmname(i) & "=" & parmval;
}
}
}
}
l_query=escape(l_query);
l_opts=verifyoptions();
if( l_opts!="")
redirect ("st_prod.html?p_missing=Y&p_catid=" & p_catid & "&p_prodid=" & p_prodid.1 & "&p_quantity=" & p_quantity.1 & l_opts );
redirect( "gr_giftregistry.html?func=ADD&p_prodid=" & p_prodid.1 & "&p_quantity=" & p_quantity.1 & "&p_option=" & l_query);
}
if (func == "Update") {
cartdel("cart_orderid");
}
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);
}
// The cart is empty
if (cartcount("cart_display") == 0) {
printtag("HEADER");
printtag("BODY");
if (func=="Update"){
printtag("VIEW_NO_ITEMS_ERASE");
} else {
printtag("VIEW_NO_ITEMS");
}
} else {
// display order table
l_html=buildordertable();
::st_shopplus_util::GetLocalVars(); // Localization
printtag("HEADER");
printtag("BODY");
print(l_html);
}
printtag("FOOTER");
if (REMOTE_DB == "True") {
disconnect( DB_DIR);
if (SQLCODE!=0) printtag("SQL_ERROR",ERR_FILE);
}
}
// verify all options set....
verifyoptions()
{
// structure to return
l_option.text = "";
l_option.formfield = "";
l_option.priceadjust = 0;
l_opts="";
l_prodid=p_prodid.1;
l_parmcount=0;
if( l_prodid=="" )
return( "" );
l_required=0;
search( DB_DIR,
"*",
"ST_OPTINDEX",
"PID=:l_prodid",
"", "")
{
l_oid=ST_OPTINDEX.OID;
search( DB_DIR, "*","ST_OPTION","ID=:l_oid","","NAME ASC")
{
l_name=ST_OPTION.NAME;
l_count = 0;
l_option_id = "OPT" & ST_OPTION.ID;
parmval = parm( l_option_id & ".1" );
if( ST_OPTION.REQUIRED=="Y" ) {
if( parmval=="" )
l_required=1;
}
if( ( parmval>"" ) )
{
l_parmcount=l_parmcount+1;
l_opts=l_opts & "&" & l_option_id & "=" & escape(parmval);
}
}
}
if (SQLCODE!=0) printtag("SQL_ERROR", ERR_FILE);
if( l_required==0 ) {
return( "" );
} else {
if( l_opts=="" )
l_opts="&l_blank=y";
return( l_opts );
}
}
// verify all options set....
verifyoption_list(l_prodid,l_opt_list)
{
// structure to return
l_option.text = "";
l_option.formfield = "";
l_option.priceadjust = 0;
l_opts="";
l_parmcount=0;
if( l_prodid=="" )
return( "" );
l_required=0;
search( DB_DIR,
"*",
"ST_OPTINDEX",
"PID=:l_prodid",
"", "")
{
l_oid=ST_OPTINDEX.OID;
search( DB_DIR, "*","ST_OPTION","ID=:l_oid","","NAME ASC")
{
l_name=ST_OPTION.NAME;
l_count = 0;
l_option_id = "OPT" & ST_OPTION.ID;
parmval = varget( "l_opt_list." & l_option_id );
if( ST_OPTION.REQUIRED=="Y" ) {
if( parmval=="" )
l_required=1;
}
if( ( parmval>"" ) )
{
l_parmcount=l_parmcount+1;
l_opts=l_opts & "&" & l_option_id & "=" & escape(parmval);
}
}
}
if (SQLCODE!=0) printtag("SQL_ERROR", ERR_FILE);
if( l_required==0 ) {
return( "" );
} else {
if( l_opts=="" )
l_opts="&l_blank=y";
return( l_opts );
}
}