Topic: Auto add to session with checkout button.


SemiCFDev    -- 04-15-2013 @ 11:06 PM
  I'm new to CF and could use a some perspective. I have a shopping cart I'm working on and I currently have an "add to cart" button and then a "checkout" form button.


I would like to automatically add the product to the session when the checkout button is clicked, instead of having a visitor click add to cart first.

Can anyone give me a hand with a Cfif statement that will check to see if the session is 0 and will +1 to the session when the checkout button is clicked automatically.




Cfdevshop    -- 04-17-2013 @ 10:23 PM
  I use bellow code when ADDTOCART button is pressed.
product qty,id are stored in session.

<cfset TotalItem=0>
                                             
<cfset TotalCost=0>
                                    <cfset TotalQty=0>
                                    <cfset
totalshipping=0>
       <cfloop LIST="#session.StoreItems#"
INDEX="CurrentItemID">

               <!--- Find the quantity of each
item --->
               <CFSET ItemPosition =
ListFind(session.StoreItems, CurrentItemID)>
               <CFSET Quantity =
ListGetAt(session.StoreItemsQty, ItemPosition)>               
               <CFSET cartsize =
ListGetAt(session.StoreItemssize, ItemPosition)>

               <!--- This query is just to get
the name and price of the current item so that we can
display that data in the table --->
               <cfquery name="GetData"
datasource="#Application.ds#" dbtype="ODBC"
username="#Application.UserName#"
password="#Application.Password#">
                    SELECT top 1 *
                    FROM Products
                    Where ProductID =
#CurrentItemID#                    
               </cfquery>
            
               <cfif GetData.recordcount eq 0>
                    <cfquery name="GetData"
datasource="#Application.ds#" dbtype="ODBC"
username="#Application.UserName#"
password="#Application.Password#">
                         SELECT top 1 *
                         FROM Products
                         Where ProductID
= #CurrentItemID#
                    </cfquery>
               </cfif>
            <cfoutput query="GetData">

                    <cfset
TotalItem=val(price)*val(Quantity)>
                    <cfset
TotalCost=val(TotalCost)+val(TotalItem)>
                    <cfset
TotalQty=val(TotalQty)+val(Quantity)>
                </cfoutput>
        </cfloop>
        
<cfquery name="Getdata2" datasource="#Application.ds#"
dbtype="ODBC" username="#Application.UserName#"
password="#Application.Password#">
               SELECT
                  sm.ShippingTypeID, sm.ShippingMethod,
                    sp.ShippingPriceID,
sp.PriceUnder, sp.Amount
               FROM
                 ShippingPrices sp, ShippingMethods sm
               WHERE
                 sp.ShippingTypeID = sm.ShippingTypeID
               AND
                 <cfqueryparam value="#TotalCost#"
cfsqltype="cf_sql_numeric"> <= sp.PriceUnder
               Order by
                 sm.ShippingTypeID, sp.PriceUnder
                    
          </CFQUERY>
        
<cfif session.logon EQ "TRUE" AND Session.UserLevelID
NEQ 1>
     <cfquery name="GetDataC"
datasource="#Application.ds#" maxrows=1 dbtype="ODBC"
username="#Application.UserName#"
password="#Application.Password#">
          SELECT *
          FROM  Users
          WHERE UserID = #session.UserID#
          AND UserLevelID <> 1
     </cfquery>
    <cfoutput query="GetDataC">
          <cfset title = "#title#">
          <cfset company = "#company#">
          <cfset firstname = "#firstname#">
          <cfset Lastname = "#Lastname#">
        <cfset apartment = "#apartment#">     
          <cfset address = "#address#">
        <cfset address2 = "#address2#">          
          <cfset city = "#city#">
          <cfset state = "#state#">
          <cfset country = "#country#">
          <cfset zipcode = "#zipcode#">
          <cfset homephone = "#homephone#">
          <cfset Workphone = "#workphone#">
          <cfset email = "#email#">
     <cfset ccln = "#creditcardlastname#">
     <cfset ccfn = "#creditcardfirstname#">
     <cfset ccn = "#creditcardnumber#">
     <cfset ccem = "#CreditCardExpMonth#">
     <cfset ccey = "#CreditCardExpYear#">
    <cfset ccecvv = "#creditCardCVV#">
     <cfset cct = "#CreditCardType#">
     <cfif ccln eq "">
          <cfset ccln = "#lastname#">
     </cfif>
     <cfif ccfn eq "">
          <cfset ccfn = "#firstname#">
     </cfif>
     </cfoutput>
<cfelse>
<cfset session.userid = -1>
          <cfset title = "">
          <cfset company = "">
          <cfset firstname = "">
          <cfset Lastname = "">
        <cfset apartment = "">
          <cfset address = "">
        <cfset address2 = "">
          <cfset city = "">
          <cfset state = "">
          <cfset country = "">
          <cfset zipcode = "">
          <cfset homephone = "">
          <cfset workphone = "">
          <cfset email = "">
    <cfset ccln = "">
     <cfset ccfn = "">
     <cfset ccn = "">
     <cfset ccem = "">
     <cfset ccey = "">
    <cfset ccecvv = "">
     <cfset cct = "">     
     <cfset ccln = "">
     <cfset ccfn = "">     
</cfif>

Coldfusiondevshop


EasyCFM.COM ColdFusion Forums : http://archive.easycfm.com/forums
Topic: http://archive.easycfm.com/forums/viewmessages.cfm?Forum=12&Topic=15309