0 Replies - 1386 Views - Last Post: 09 May 2005 - 04:10 PM

#1 wiredwizard   User is offline

  • D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 76
  • Joined: 07-May 05

cartdisplay.cfm

Posted 09 May 2005 - 04:10 PM

Description: # 1) Cart - An array of structs of the following form:
# (struct)
# puid = product unique id, corresponding to the database value
# of the same name.
# qty = the quantity of the item to purchase.
#
# 2) Datasource - The name of the database from which descriptive
# product information is drawn. The datasource name must be
# registered with the ColdFusion server to work properly.
#
# 3) Editable - The cart contents are editable, meaning quantities
# can be updated and products can be removed from the cart.
#
# 4) Action - The name of the page that should be jumped to when
# form elements are submitted.
#
# 5) Taxrate - Set to zero by default, if a non-zero value is given
# then tax is applied to the cart total calculation and is
# displayed as an item in that calculation.# Displays the contents currently held by the cart system.
<!---
#####################################################################
# Displays the contents currently held by the cart system.
# Parameters:
# 1)  Cart - An array of structs of the following form:
#     (struct)
#     puid = product unique id, corresponding to the database value
#            of the same name.
#     qty  = the quantity of the item to purchase.
#
# 2)  Datasource - The name of the database from which descriptive
#     product information is drawn.  The datasource name must be
#     registered with the ColdFusion server to work properly.
#
# 3)  Editable - The cart contents are editable, meaning quantities
#     can be updated and products can be removed from the cart.
#
# 4)  Action - The name of the page that should be jumped to when
#     form elements are submitted.
#
# 5)  Taxrate - Set to zero by default, if a non-zero value is given
#     then tax is applied to the cart total calculation and is
#     displayed as an item in that calculation.
#####################################################################
--->

<cfparam name="Attributes.tax"                   default="0">
<cfparam name="Attributes.subtotal"              default="0">
<cfparam name="Attributes.shipping"              default="0">
<cfparam name="Attributes.cart"                  default="0">
<cfparam name="Attributes.datasource"            default="null">
<cfparam name="Attributes.editable"              default="true">
<cfparam name="Attributes.action"                default="home.cfm">
<cfparam name="Attributes.taxrate"               default="0">
<cfparam name="Attributes.pricescheme"           default="price">

<cfif arrayLen( Attributes.cart ) EQ 0>
     <div class="cart-header" style="height: 100px; padding-top: 50px;" align="center">
          Your cart is empty!
     </div>
<cfelse>
     <table class="cart-display">
          <tr style="font-weight: bold; font-size: 12px;">
               <td>SKU#</td>
               <td width="35%">Product Name</td>
               <td align="right">Unit Price</td>
               <td align="right">Quantity</td>
               <td align="right">Item Total</td>
               <cfif #Attributes.editable#><td></td></cfif>
               <cfif #Attributes.editable#><td></td></cfif>
          </tr>
          <cfloop index="i" from="1" to="#arrayLen( Attributes.cart )#">
               <tr>
                    <cfquery name="product_info" datasource="#Attributes.datasource#">
                         select *
                         from products
                         where puid = #Attributes.cart[ i ].puid#
                    </cfquery>
                    <cfoutput query="product_info">
                         <td><cfif len( "#sku#" ) EQ 0>#puid#<cfelse>#sku#</cfif></td>
                         <td>#name#</td>
                         <td align="right">
                              <cfswitch expression="Attributes.pricescheme">
                                   <cfcase value="wholesale">
                                        #dollarFormat( wholesale )#
                                   </cfcase>
                                   <cfdefaultcase>
                                        #dollarFormat( price )#
                                   </cfdefaultcase>
                              </cfswitch>
                         </td>
                         <form method="post" action="#Attributes.action#?pid=cart&opt=update&pos=#i#">
                              <td align="right"><cfif #Attributes.editable#><input style="text-align: right;" type="text" size="1" name="qty" id="qty" value="#Attributes.cart[ i ].qty#" /><cfelse>#Attributes.cart[ i ].qty#</cfif></td>
                              <td align="right">
                                   <cfswitch expression="Attributes.pricescheme">
                                        <cfcase value="wholesale">
                                             #dollarFormat( wholesale * Attributes.cart[ i ].qty )#
                                        </cfcase>
                                        <cfdefaultcase>
                                             #dollarFormat( price * Attributes.cart[ i ].qty )#
                                        </cfdefaultcase>
                                   </cfswitch>
                              </td>
                              <cfif #Attributes.editable#><td align="right"><input type="submit" name="update" id="update" value="Update" /></td></cfif>
                         </form>
                         <form method="post" action="#Attributes.action#?pid=cart&opt=delete&pos=#i#">
                              <cfif #Attributes.editable#><td align="right"><input type="submit" name="delete" id="delete" value="Remove" /></td></cfif>
                         </form>

                         <!--- Perform Sub-Total Calculations --->
                         <cfswitch expression="Attributes.pricescheme">
                              <cfcase value="wholesale">
                                   <cfset Attributes.subtotal = Attributes.subtotal + (wholesale * Attributes.cart[ i ].qty)>
                              </cfcase>
                              <cfdefaultcase>
                                   <cfset Attributes.subtotal = Attributes.subtotal + (price * Attributes.cart[ i ].qty)>
                              </cfdefaultcase>
                         </cfswitch>
                    </cfoutput>
               </tr>
          </cfloop>
          <tr>
               <td colspan="4" align="right">Sub-Total:</td>
               <td align="right"><cfoutput>#dollarFormat( Attributes.subtotal )#</cfoutput></td>
               <td colspan="2"></td>
          </tr>
          <tr>
               <cfset shipping = 3>
               <cfloop index="i" from="1" to="#arrayLen( Attributes.cart )#">
                    <cfset Attributes.shipping = Attributes.shipping + ( 1 * Attributes.cart[ i ].qty )>
               </cfloop>
               <td colspan="4" align="right">Shipping:</td>
               <td align="right"><cfoutput>#dollarFormat( Attributes.shipping )#</cfoutput></td>
               <td></td>
          </tr>

          <cfif #Attributes.taxrate# NEQ 0>
               <tr>
                    <cfset Attributes.tax = Attributes.subtotal * 0.07>
                    <td colspan="4" align="right">Tax:</td>
                    <td align="right"><cfoutput>#dollarFormat( Attributes.tax )#</cfoutput></td>
                    <td></td>
               </tr>
          </cfif>

          <tr class="cart-header">
               <td colspan="4" align="right">Total:</td>
               <td align="right"><cfoutput>#dollarFormat( Attributes.subtotal + Attributes.shipping )#</cfoutput></td>
               <td></td>
          </tr>
     </table>
</cfif>



Is This A Good Question/Topic? 0
  • +

Page 1 of 1