Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Shopping Cart Summary

Status
Not open for further replies.

Bungdaddy

Programmer
Mar 16, 2007
1
US
I am trying to write a sidebar that lists all the contents of a shopping cart, adds the items together, offers a subtotal and then enter a coupon to subtract an amount giving the final total. The code that I have listed below works to an extent..here is an example how it would display:

Series Title 1
2 A tickets = $480

Series Title 2
2 B Tickets =$230

Subtotal:$480
$230

I would like to be able to add the two subtotal numbers together and also add an input field that would allow for a coupon code whose value could come from the DB. Then finally total it all up.

-------------------------------------------
Code
------------------------------------------

<cfquery name="getMerch" datasource="#APPLICATION.dataSource#"
cachedWithin="#createTimeSpan(0,1,0,0)#">
SELECT
m.MerchName
,m.MerchDescription
,m.MerchPrice
,m.ImageNameSmall
,f.SeriesID
,f.SeriesTitle
FROM
merchandise m INNER JOIN films f
ON m.SeriesID = f.SeriesID
WHERE
m.MerchID = #ATTRIBUTES.merchID#
</cfquery>

<!--- Get current cart contents, as a query object --->
<cfset getCart = SESSION.myShoppingCart.List()>

<!---Your Order--->
<cfloop query="getCart">
<!--- Now display information of what is in the cart --->
<cfoutput>
<table cellspacing="0" cellpadding="0">
<tr>
<td colspan="3">
<span style="color:##ffb505;">#getMerch.SeriesTitle#</span>
</td>
</tr>
<tr>
<td style="padding:0 5px 0 0">#getCart.Quantity#</td>
<td style="padding:0 5px 0 0">
<p>#getMerch.MerchName#</p>
</td>
<td class="price">
<p>#lsCurrencyFormat(getMerch.MerchPrice * getCart.Quantity)#</p>
</td>
</tr>
</table>
</cfoutput>
</cfloop>

<!---Display the subtotal of the cart--->
<cfloop query="getCart">
<cfoutput>
<table cellspacing="0" cellpadding="0">
<tr>
<td colspan="3">
<p>#lsCurrencyFormat(getMerch.MerchPrice * getCart.Quantity)#</p>
</td>
</tr>
</table>
</cfoutput>
</cfloop>
 
Sorry, I misread your question


Code:
<cfset totalPrice = 0>
<cfoutput query="getCart"> 
	<cfset subPrice = getMerch.MerchPrice * getCart.Quantity>
	<cfset totalPrice = totalPrice + subPrice>
<!--- Now display information of what is in the cart --->
<table cellspacing="0" cellpadding="0">
            <tr>
                  <td colspan="3">
                  <span style="color:##ffb505;">#getMerch.SeriesTitle#</span>
                  </td>
            </tr>
            <tr>
                  <td style="padding:0 5px 0 0">#getCart.Quantity#</td>
              <td style="padding:0 5px 0 0">
              <p>#getMerch.MerchName#</p>
                  </td>
                  <td class="price">
                   <p>#lsCurrencyFormat(subPrice)#</p>
                  </td>
            </tr>
 </table>
</cfoutput>

<cfoutput>
 totalPrice = #totalPrice#
 subtract any discounts from this price
</cfoutput>

Kevin

Phase 1: Read the CFML Reference
Phase 2: ???
Phase 3: Profit!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top