00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "shoppingCart.hpp"
00013 #include "cgiTemplates.h"
00014
00015 int main( int iCount, char ** pchArgs )
00016 {
00017
00018 cgiScript script( "text/html", false);
00019 cgiTemplates htemplate;
00020 htemplate.load("Templates/ShoppingCart.html");
00021
00022
00023 uiShoppingCart cart( script );
00024 script.closeHeader();
00025
00026
00027 cgiInput & args = script.ClientArguments ();
00028
00029 if( args.count("action") )
00030 {
00031 if( args["action"] == "add" )
00032 {
00033 string productId = args["id"].c_str();
00034 cart.AddProduct( productId );
00035 }
00036 else if( args["action"] == "remove" )
00037 {
00038 string productId = args["id"].c_str();
00039 cart.RemoveProduct( productId );
00040 script << "<script type='text/javascript'>"
00041 "var loco=parent.location;"
00042 "parent.location = loco"
00043 "</script>";
00044 }
00045 }
00046 cart.stats();
00047
00048 ocString itemCount;
00049 itemCount.append(cart.items);
00050 if( cart.items != 1 )
00051 {
00052 itemCount += " items";
00053 }
00054 else
00055 {
00056 itemCount += " item";
00057 }
00058 ocString qs = "?crtid=";
00059 qs.append(cart.Id);
00060 ocString content = htemplate. getUnparsedHtml();
00061 script << content. replace("O Items", itemCount.c_str())
00062 . replace("$url",CHECKOUT)
00063 . replace("?qs",qs.c_str() );
00064 return 0;
00065 }
00066
00067
00068 #include "read_write_base.cpp"