<!--- Show header images, etc., for Online Store --->
<CFINCLUDE TEMPLATE="StoreHeader.cfm">

<!--- If MerchID was passed in URL --->
<CFIF IsDefined("URL.AddMerchID")>
  <!--- Add item to user's cart data, via custom tag --->
  <CF_ShoppingCart
    Action="Add"
    MerchID="#URL.AddMerchID#">

<!--- If user is submitting cart form --->    
<CFELSEIF IsDefined("FORM.MerchID")>
  <!--- For each MerchID on Form, Update Quantity --->
  <CFLOOP LIST="#Form.MerchID#" INDEX="ThisMerchID">
    <!--- Update Quantity, via Custom Tag --->
    <CF_ShoppingCart
      Action="Update"
      MerchID="#ThisMerchID#"
      Quantity="#FORM['Quant_#ThisMerchID#']#">
  </CFLOOP>
  
  <!--- If user submitted form via "Checkout" button, --->
  <!--- send on to Checkout page after updating cart. --->
  <CFIF IsDefined("FORM.IsCheckingOut")>
    <CFLOCATION URL="StoreCheckout.cfm">
  </CFIF>
</CFIF>

<!--- Get current cart contents, via Custom Tag --->
<CF_ShoppingCart
  Action="List"
  ReturnVariable="GetCart">
  
<!--- Stop here if user's cart is empty --->
<CFIF GetCart.RecordCount EQ 0>
  There is nothing in your cart.
  <CFABORT>
</CFIF>


<!--- Create form that submits to this template --->
<CFFORM ACTION="#CGI.SCRIPT_NAME#">
  <TABLE>
    <TR>
      <TH COLSPAN="2" BGCOLOR="Silver">Your Shopping Cart</TH>
    </TR>
    <!--- For each piece of merchandise --->
    <CFLOOP QUERY="GetCart">
      <TR>
        <TD>
          <!--- Show this piece of merchandise --->
          <CF_MerchDisplay
            MerchID="#GetCart.MerchID#"
            ShowAddLink="No">
        </TD>  
        <TD>
          <!--- Display Quantity in Text entry field --->
          <CFOUTPUT>
            Quantity: 
            <INPUT TYPE="Hidden" 
              NAME="MerchID" 
              VALUE="#GetCart.MerchID#">
            <INPUT TYPE="Text" SIZE="3" 
              NAME="Quant_#GetCart.MerchID#" 
              VALUE="#GetCart.Quantity#">
          </CFOUTPUT>
        </TD>
      </TR>
    </CFLOOP>
  </TABLE>
  
  <!--- Submit button to update quantities --->
  <INPUT TYPE="Submit" VALUE="Update Quantities">

  <!--- Submit button to Check out --->
  <INPUT TYPE="Submit" VALUE="Checkout" NAME="IsCheckingOut">
</CFFORM>