5 Replies Latest reply on Aug 5, 2015 10:50 AM by cshafer2

    Cart incrementing item quantity by one when cart is refreshed or back button is clicked

    cshafer2

      We recently upgraded to CF11 from CF9 and have ran into a challenge. I understand this is probably very fundamental but I am at a loss to figure it out because our cart worked so well for years before. I pass a url variable to the cart containing the sku number and it populates my preorder table with a quantity of one unless I also pass the quantity variable in the same string at which I use if isdefined to detect. My cart works but upon page refresh or if the back button is hit, it will increment one to the quantity field. Can someone tell me the way to eliminate this issue? In the address box of the old cart we hid the variable in the url string when passing the call to the cart but the same code not with CF11 does indeed show the variable(sku) in the url which is passed causing the cart to update. Looking for help here please?

       

      Thanks

        • 1. Re: Cart incrementing item quantity by one when cart is refreshed or back button is clicked
          haxtbh Level 4

          Without seeing some code its very hard to tell you what needs to be done. We don't know if you have done something in your code that worked in CF9 but should be done another way and now works as intended in CF11 etc

           

          If you are unable to post the actual code, then you will have to write a example based on what you have done.

          • 3. Re: Cart incrementing item quantity by one when cart is refreshed or back button is clicked
            cshafer2 Level 1

            This is how we send the variable to the page that processes the data transaction:

            <label onClick="location.href='shop/?sku=#sku#'">Add to Cart</label>

             

            From there it is simply a SQL statement:

            <cfif CheckCart.RecordCount GT "0">
            <cfset myqty = (#CheckCart.Qty# + #Qty#)>
            <!--- If there are already items in the cart then increment quantity --->
            <CFQUERY datasource="Product" name="IncrementQuantity">
              UPDATE tblTempOrders
              SET Qty = <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#myqty#">
              WHERE CartID = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#Cookie.CartID#">
              AND PartNo = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#PartNo#">
            </cfquery>

            <!--- Otherwise, just add it to the basket --->
            <cfelse>

              <cfquery datasource="Production" NAME="CartInfo">
               SELECT tblProduct.ShortDesc, tblFlagProduct.ShipType
               FROM tblgProduct
               WHERE tblProduct.NPart = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#PartNo#">
                        AND CurrentWeb = 'Y'
              </cfquery>

            </cfif>

             

            What is puzzling to me is that the url in the address bar does not show the sku number but when mouse is hover over submit button it does show. So in the address bar is indicates : http://mysite.local/force.cfm but hovering over the "ATC" button is shows https://mysite.local/shop/?sku=X12345

             

            I hope this helps and appreciate your reply

            • 4. Re: Cart incrementing item quantity by one when cart is refreshed or back button is clicked
              Dave Ferguson Level 3

              The one thing I would to is eliminate all the different queries and do the update/insert as one statement.  The query you show in your sample to add to the basket is a select so I am not sure how you are doing the insert.

               

               

              <CFQUERY datasource="Product" name="IncrementQuantity">

                if exists(select 1 from tblTempOrders where CartID = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#Cookie.CartID#">

                  AND PartNo = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#PartNo#">)

                begin

                  UPDATE tblTempOrders

                  SET Qty = qty+<cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#qty#">

                  WHERE CartID = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#Cookie.CartID#">

                  AND PartNo = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#PartNo#">

                end

                else

                  <!--- do insert query here --->

                begin

                end

              </cfquery>

              • 5. Re: Cart incrementing item quantity by one when cart is refreshed or back button is clicked
                cshafer2 Level 1

                Thank you for your replies. There are multiple reason we use this type of if / else cart functions. Many products will trigger different events upon qty so the segregation was necessary, at least at the time we built this, and has worked very well up until this upgrade. The url variable is also a triggered event in as much as if it is present (isdefined) in the transaction or it is not. I do appreciate the ideas but I am still at a loss. Thank you all again.