Skip to main content
July 1, 2008
Question

URL Parameters & Shopping Cart

  • July 1, 2008
  • 11 replies
  • 1704 views
I have made a simple shopping cart from several resources, user comes onto the site and picks a category, the url coding is as follows;

<cfoutput query="catList">
<a href="products.cfm?CatID=#catList.CatId#">#CatName#</a>
</cfoutput>

Which works fine, all the products under the selected Category ID (#CatId#) are displayed. It’s when I click on the “add to cart” or “empty cart” links / button the problem start. It will add the item to the cart as its refreshing the page but the url goes to ../products.cfm so there are no items displayed.

So my question is how can I add the item to the cart but return to the same pages?

Thanks,
Lee
This topic has been closed for replies.

11 replies

July 2, 2008
Its working spot on now!

Cheers
Inspiring
July 2, 2008
Also,

Make sure that the "CatID" value persists in the page in where you have the "Empty Cart" button.
July 2, 2008
Now i feel stupid :P

Thanks for you help, much appreciated!
Inspiring
July 2, 2008
Hi Lee,

I thought you were appending the catID as,

<a href="../template/products.cfm?clear=yes&catID=#url.catid#">Empty Cart</a>

and in turn you can put the #url.catID# in the where clause of your products query (in product.cfm) which will fetch you the results you want to display..


July 2, 2008
Ok, i see.

Yes but when i add the &CatID=#URL.CatID# to the Empty Cart link, the CatID doesnt get carried accross, the link looks like so;

http://localhost:8500/hydrospace%20rev2/template/products.cfm?clear=yes&CatID=#URL.CatID#

Would it have anything to do with the Cart.cfm being an include, saying that the "add to cart" is an include and it works fine. Only seems to be when i add a second pereameter to the URL, then i get the following error;

Error Executing Database Query.

Which comes from WHERE CatID = <cfqueryparam value="#URL.CatID#"> because the CatID is not defined in the url.

Lee
Inspiring
July 2, 2008
quote:

Originally posted by: leemar99

Yes but when i add the &CatID=#URL.CatID# to the Empty Cart link, the CatID doesnt get carried accross, the link looks like so;

http://localhost:8500/hydrospace%20rev2/template/products.cfm?clear=yes&CatID=#URL.CatID#




Hi,

Did you put your <a href> statement inside <cfoutput></cfoutput> blocks?
July 2, 2008
Sorry Daverms but i dont understand where you taking me with this, can you explaine?

My cart works fine, products are displayed fine and emptying the cart works fine, but when i click empty cart;

<a href="../template/products.cfm?clear=yes">Empty Cart</a>

This works fine and the cart is empied and it returns be to a blank products page because is no CatID defined, i want to carry the previous CatID from before the empty link was click.

Thanks,
Lee

Inspiring
July 2, 2008
then run the query by specifying the condition catid=#url.catid# in your where clause...

July 2, 2008
I already have something similar to that;

<cfif isDefined('URL.clear') AND URL.clear EQ 'yes'>
<cfif isDefined('Session.Cart')>
<cfset junk = StructDelete(Session, 'Cart')>
</cfif>
</cfif>

That was working fine before i added &CatID=#URL.CatID# on the the end of the clear button.

I want to be able to clear the cart and return to the previous query results, chosen by the CatID

Cheers,
Lee
Inspiring
July 2, 2008
Hi Lee,

Try like this,

July 2, 2008
Hi

Yes

The returned error i get is;

Invalid data '' for CFSQLTYPE CF_SQL_NUMERIC.

when trying the above
Inspiring
July 2, 2008
Hi,

Use the "StructClear" function inside,

Inspiring
July 2, 2008
Hi,

Are you storing your items as session variables?...
July 2, 2008
Still bit of a newbie when it comes to ColdFusion!

How i resolved the problem was adding the #URL.CatID# on the end of the form action, like so.

<form action="#variables.ThisPage#?CatID=#URL.CatID#" method="post" name="form" id="form">

Are there any issues with doing it this way?

Still having the problem with the empy cart, i have tried the following;

<a href="../template/products.cfm?clear=yes&CatID=#URL.CatID#">

but its not making any difference and the idems dont empty from the cart.

Cheers,
Lee