SHOPCART.A5W

Purpose

A customer views the SHOPCART.A5W to see the items selected for purchase.

Description

The SHOPCART.A5W page verifies the shopping cart information is current. This test is done by including SHOPCART_UDF.A5W and running shopcart_chk().

Links

The Shopping Cart > View Cart entry of the NAV_MAIN navigation component displays the SHOPCART.A5W page.

SHOPCART.A5W in the WYSIWYG tab of the HTML Editor [Picture]

SHOPCART.A5W in the Browser [Picture]

SHOPCART.A5W in the Browser [Picture]

Edits to the Page Source

When you look at SHOPCART.A5W with the Source tab of the HTML Editor, you will see a large amount of HTML and Xbasic code. The HTML Editor placed almost all of it there automatically, as we used the WYSIWYG tab to place the tables, text, graphics, and components on the page. There are a few interesting exceptions, where we changed the page code through the Source tab.

The LOGINUSERDATA.A5W page returns values for LoginID, LoginType, and LoginLevel. If the LoginType is not "I" (internal), the user is sent to the LOGIN.A5W page. If the user fails the login test, the script loads the FRAMEEXIT.A5W page, which then opens the ASWINDEX.A5W page.

a5w_include("loginuserdata.a5w")

This code defines the welcome message for current user. If the user is a customer, the script gets his or her first name from the customer table. Otherwise, the script gets the first name from the user_names table.

welcome = "" '

if loginid <> "" ' someone is logged in

    if logintype = "C"

        welcome = alltrim(table.external_record_content_get("[PathAlias.ADB_Path]\customer", "Firstname", "", "alltrim(Customer_id) = " + quote(loginid)))

    else ' they are an internal user, get name from user table

        welcome = alltrim(table.external_record_content_get("[PathAlias.ADB_Path]\user_names", "user_name","", "alltrim(user_id) = " + quote(loginid)))

    end if

    welcome = "Welcome " + welcome + "!"

end if

The code stores "shopcart" style in the pgstyle variable. It will be needed to format the welcome and header messages.

pgstyle = "shopcart"

The cart_id value is unique for each browser session and identifies the current instance of the open browser. This is different from session.sessionID, which is same for every browser session from the same computer. If the cart_id variable does not exist or its value is NULL, the API_UUIDCREATE() function generates a unique number to identify the cart (or order). The RESPONSE.ADD_COOKIE() saves this value in a cookie.

if eval_valid("cart_id") = .F.

    cart_id = api_uuidcreate()

    response.add_cookie("cart_id", cart_id, 0)

elseif cart_id = ""

    cart_id = api_uuidcreate()

    response.add_cookie("cart_id", cart_id, 0)

end if

The page script calls shopcart_chk() loaded by a5w_include("shopcart_UDF.a5w"). This function will return a NULL value if there is no old cart. It will return shopcart_chk.html if old cart data was found. The following code prepares for the function call.

a5w_include("shopcart_UDF.a5w") ' include UDF page

request.variables.cart_id = cart_id

dim cartparms as P

cartparms.style_name = pgstyle

cartparms.DBF.table_name = "[PathAlias.ADB_Path]\shop_cart.dbf"

cartparms.product_table = "[PathAlias.ADB_Path]\product.dbf"

cartparms.product_table_display_fld = "description"

cartparms.product_table_id_fld = "prod_id"

cartparms.owner_id = loginid    

cartparms.user_type = logintype

cartparms.session = session

cartparms.request = request

cartparms.response = response

cartparms.popup = 0

cartparms.RedirectURL = "index.a5w"

cartparms.product_id = ""

cartparms.input_value_missing = ""

cartparms.emptycart_message = .T.

If data from an old cart is returned, code is returned in the shopcart_chk.html parameter.

dim tmpl_cart as P

tmpl_cart = shopcart_chk(cartparms)

if tmpl_cart.RedirectURL <> "" then

    response.redirect(tmpl_cart.redirectURL)

    end

end if

The location = "" statement clears all highlights from the menu.

with tmpl_NAV_MAIN

    location = ""

    componentName = "NAV_MAIN"

end with

The pgstyle saves the style of the GRD_PRODNAV grid component for later use.

pgstyle = tmpl_GRD_PRODNAV.style_name

The page script now tests to see if there was any HTML returned from shopcart_chk() function. If there was HTML returned, the script skips building a new component. It uses the output from the dot variable to populate the variables normally built by the component.

if tmpl_cart.html <> ""

    delete x_grd_cart

    dim x_grd_cart as p

    x_grd_cart.Output.Body.Grid_HTML = tmpl_cart.html

    x_grd_cart.Output.Body.UpdateErrors = ""

    goto show_page ' skip shop cart list component

end if

The following code overrides properties of the grid. The filter expression causes the grid to display only those records for the current value of cart_Id where the quantity is greater than zero. The order expression is set to descending. The style is set to match the navigation component.

with tmpl_grd_cart

    DBF.filter = "Cart_Id = \"" + cart_id + "\" .and. Quantity > 0"

    DBF.order = "Desc"

    style_name = pgstyle

    componentName = "DLG_CART"

end with

Later the pgstyle variable styles the heading of the page.

<tr>

    <td colspan="2" align="middle" class=" <%a5 ? pgstyle %> ErrorDataTD"><br><strong>Since 1982, Your Preferred Sporting Goods Supplier! Now with Many New Products</strong></td>

</tr>

If the welcome message is not NULL, the pgstyle variable styles the welcome message.

<%a5 if welcome <> "" %>

    <tr>

        <td class=" <%a5 ?pgstyle %> ErrorDataTD" align="middle"><strong><%a5 ?welcome %></strong></td>

    </tr>

<%a5 end if %>

See Also

Web Pages

Supported By

Alpha Five Version 7 and Above