GRD_CARTOUT Grid Component

Purpose

The GRD_CARTOUT grid component displays the contents of the customer's shopping cart. It allows the customer to change item quantities or remove items from the cart.

[Picture]

Description

The GRD_CART component is an updateable grid which displays a view with fields from the shop_cart, product, and specials tables. The view grid contains four calculated fields. Users may edit or delete, but not insert new records.

NPrice = if(Specials->Sale_Price > 0 .and. (cdate(Specials->Sale_Until) >= cdate(date()) .or. cdate(Specials->Sale_Until) = ""), Specials->Sale_Price, Product->Retail)

ext = Quantity * if(Specials->Sale_Price > 0 .and. (cdate(Specials->Sale_Until) >= cdate(date()) .or. cdate(Specials->Sale_Until) = ""), Specials->Sale_Price, Product->Retail)

avail = if(Product->Qty_In_Sto > 0, "In Stock!", alltrim(Product->Ship_Avail))

Sale_Until = if(Specials->Sale_Price > 0, cdate(Specials->Sale_Until), "00000000")

The grid's filter expression is quantity>0. The order expression lists items alphabetically by their descriptions.

Containers

CHECKOUTCART.A5W

Notable Grid Control Property Settings

Control

Property

Description

Qty_in_Sto

Display Settings > Control type

"Hidden". This value is used in the BeforeValidateExistingRecords event to make the quantity requested for any item does not exceed the available inventory.

Desc

Display Settings > Control type

"Link"

Link Properties > Display what in link

"Value in Field"

Link Properties > Link address type

"Computed from fields in the grid"

Link Properties > Link address

When clicked, displays the PRODUCTINFO.A5W  page showing the product defined by prod_id.

productinfo.a5w?pid={Prod_Id}

List

Display Settings > Display format

Only shows prices that are greater than zero.

if(<value>=0, "", str(<value>,20,2,"$,"))

Nprice

Display Settings > Control type

"Custom"

Custom Control Properties > Definition

See Price Custom Control

Sale_Until

Display Settings > Display format

If the end of sale date is greater than the current date, it displays the label "Special!".

if(<value>>=cdate(date()) .or. <value>="", "Special!","")

Ext

Display Settings > Display format

Only shows prices that are greater than zero.

if(<value>=0, "", str(<value>,20,2,"$,"))

Sale_Until

Column Properties > Hide column

"True"

Price Custom Control

The beginning of the custom control script sets new_price to NULL, if its value is zero or negative. Otherwise, it formats it as a dollar value.

function NPrice_render as c (data as p, args as p, PageVars as p)

with PageVars

    on error goto NPrice_xbasicError

    new_price = if(Data.NPrice > 0, alltrim(str(Data.NPrice, 20, 2, "$, ")), "")

If the product is still on sale, the next two statements create the HTML (NPrice_render) that will show the price with a bold red font.

    if Data.Sale_Until >= cdate(date())

        NPrice_render = <<%html%

<strong><font color=#ff0000>__price__</font></strong>

%html%

    elseif Data.Sale_Until = ""

        NPrice_render = <<%html%

<strong><font color=#ff0000>__price__</font></strong>

%html%

If the product is not on sale, the price is shown without highlighting.

    else

        NPrice_render = <<%html%

__price__

%html%

    end if

Finally, the script substitutes the value of new_price for __price__.

    NPrice_render = stritran(NPrice_render, "__price__", new_price)

    end

    NPrice_xbasicError:

    NPrice_render = "Error in custom control xbasic: " +     error_text_get()

end with

end function 'do not delete this line

Event Code

If the quantity requested for an item exceeds the number in inventory, the BeforeValidateExistingRecords event reduces the quantity to QTY_IN_STO.

function BeforeValidateExistingRecords as V

(DataSubmitted as P, Args as p, PageVariables as p)

with PageVariables

    if val(DataSubmitted.QUANTITY) > val(DataSubmitted.QTY_IN_STO)

        DataSubmitted.QUANTITY = alltrim(DataSubmitted.QTY_IN_STO)

    end if

end with

end function

See Also

Web Publishing Components

Supported By

Alpha Five Version 7 and Above