• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

New Here ,
Aug 05, 2015 Aug 05, 2015

Copy link to clipboard

Copied

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

Views

343

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Aug 05, 2015 Aug 05, 2015

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 05, 2015 Aug 05, 2015

Copy link to clipboard

Copied

Thank you, I will post a sample of our code.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 05, 2015 Aug 05, 2015

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Aug 05, 2015 Aug 05, 2015

Copy link to clipboard

Copied

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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 05, 2015 Aug 05, 2015

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation