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

URL Parameters & Shopping Cart

Guest
Jul 01, 2008 Jul 01, 2008

Copy link to clipboard

Copied

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
TOPICS
Advanced techniques

Views

1.5K

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
LEGEND ,
Jul 01, 2008 Jul 01, 2008

Copy link to clipboard

Copied

leemar99 wrote:
> 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
>
>

Where ever your logic is that returns to the page needs to include the
url paramaters in the logic.

On the product page, a couple of sources for these paramters would be
the URL scope and the cgi.query_string value. But neither of these are
going to be preserved from request to request unless you take steps to
do so.

There are many choice on how you preserve the values for use later. The
most common would be to make use of the Session scope. If this is the
first time you have heard of the Session scope it is too big of a topic
for a single e-mail. There are entire chapters on it in the
documentation and books such as Ben Forta's et al. ColdFusion books.

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
Guest
Jul 02, 2008 Jul 02, 2008

Copy link to clipboard

Copied

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

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
Advocate ,
Jul 02, 2008 Jul 02, 2008

Copy link to clipboard

Copied

Hi,

Are you storing your items as session variables?...

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
Guest
Jul 02, 2008 Jul 02, 2008

Copy link to clipboard

Copied

Hi

Yes

The returned error i get is;

Invalid data '' for CFSQLTYPE CF_SQL_NUMERIC.

when trying the above

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
Advocate ,
Jul 02, 2008 Jul 02, 2008

Copy link to clipboard

Copied

Hi,

Use the "StructClear" function inside,

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
Guest
Jul 02, 2008 Jul 02, 2008

Copy link to clipboard

Copied

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

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
Advocate ,
Jul 02, 2008 Jul 02, 2008

Copy link to clipboard

Copied

Hi Lee,

Try like this,

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
Advocate ,
Jul 02, 2008 Jul 02, 2008

Copy link to clipboard

Copied

then run the query by specifying the condition catid=#url.catid# in your where clause...

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
Guest
Jul 02, 2008 Jul 02, 2008

Copy link to clipboard

Copied

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

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
Advocate ,
Jul 02, 2008 Jul 02, 2008

Copy link to clipboard

Copied

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..


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
Guest
Jul 02, 2008 Jul 02, 2008

Copy link to clipboard

Copied

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

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
Advocate ,
Jul 02, 2008 Jul 02, 2008

Copy link to clipboard

Copied

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?

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
Guest
Jul 02, 2008 Jul 02, 2008

Copy link to clipboard

Copied

Now i feel stupid :P

Thanks for you help, much appreciated!

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
Advocate ,
Jul 02, 2008 Jul 02, 2008

Copy link to clipboard

Copied

Also,

Make sure that the "CatID" value persists in the page in where you have the "Empty Cart" button.

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
Guest
Jul 02, 2008 Jul 02, 2008

Copy link to clipboard

Copied

LATEST
Its working spot on now!

Cheers

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