Solved

adding an identifier for a row

Posted on 2004-04-18
17
159 Views
Last Modified: 2013-12-24
http://www.englishtrunkshowco.com/antiques/china/china.cfm

i would like to add feature where people can add an item to a shopping cart, what is the best way to do that on this page and how can i do that??

thanks
0
Comment
Question by:finnstone
  • 6
  • 6
  • 5
17 Comments
 
LVL 17

Expert Comment

by:Tacobell777
ID: 10855169
If you are retrieving the items from a database then I assume they already have a Identifier, if not, first assign an identifier to the table.

Easiest way (for you) is to probably use CLIENT variables, if they click an item you just add the item to a list stored in the CLIENT. scope.

You could do something like, and this is the best I could do, if I need to write anymore I might as well write you a whole shopping cart ;-))

<cfif NOT isDefined("client.order")>
      <!--- initialize list --->
      <cfset client.order = "">
</cfif>

<!--- if we need to add the item to our order and it does not already exist --->
<cfif isDefined("url.addToOrder") AND NOT listFindNoCase(client.order, url.addToOrder)>
      <cfset client.order = listAppend(client.order, url.addToOrder)>
</cfif>

<!--- if we need to remove the item from the order --->
<cfif isDefined("url.removeFromOrder")>
      <cfset client.order = listDeleteAt(client.order, listFindNoCase(client.order, url.removeFromOrder))>
</cfif>

<!--- if we need to display the order --->
<cfif isDefined("url.showOrder")>
      <cfoutput>
      #listLen(client.order)# Item(s) ordered:<br>
      </cfoutput>
      <cfloop index="item" list="#client.order#">
            <!--- retrieve the item details here if need be --->
            Item number: #listGetAt(client.order, variables.item)#<br>
      </cfloop>
</cfif>

Don't forget to enable client variables in your cfapplication.

0
 
LVL 17

Expert Comment

by:Tacobell777
ID: 10855174
Another way would be to use one of the many free shopping carts offered on developers exchange on Macromedia.om
0
 

Author Comment

by:finnstone
ID: 10855529
sorry i am asking from a more simpler approach.

 i have a coldfusion cfc that can process adding something to a cart, i am using this for my flash web site. now i am just looking for a way to call this cfc for adding an item from the html version.. for instance, how can i identify the product that is clicked to be added to cart.
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 18

Accepted Solution

by:
Plucka earned 200 total points
ID: 10855935
<input type="button" value="Add to Cart" onclick="actionpage.cfm?productId=#productId#">

actionpage.cfm would do the necessary bits and call the cfc function. Let me know.
0
 
LVL 17

Expert Comment

by:Tacobell777
ID: 10855962
<a href="actionpage.cfm?productID=#yourProductID#"><img src="yourimage here"></a>
Better than using javascript, as that might be turned of and won't work for screen readers etc.

Or even use a button <input type="submit" name="product_45" value="Add">

And on the action page you loop through the form scope and see if the field start with "product_" if so do a listlast with delimeter "_" to get the product ID..

You might want to ask your question a bit clearer next time so people don't waste time ;-))
0
 

Author Comment

by:finnstone
ID: 10856040
how could i send the product to a javascript function and how can i call a cfc from that javascript function? then how can i reload the current page from the cfc

thanks for the continual support.
0
 
LVL 18

Expert Comment

by:Plucka
ID: 10856098
That's a totally different question again.

Why do you want to go via a javascript function exactly?

CFC's are normally not called from javascript functions, although it's possible, I think if we understood why you want to do this we could recommend a better solution.
0
 

Author Comment

by:finnstone
ID: 10856256
i want to update the cart using the cfc but i want to refresh the page so that the cart table shows that an item has been added.

i suppose i do not need javascript, all i have to do is call the cfc which will then reload the page.
0
 
LVL 18

Expert Comment

by:Plucka
ID: 10856265
Ok,

So lets say your first page has the add to order button. Which runs an ActionPage.

The actionpage would

1. Invoke the cfc using <CFINVOKE or similar
2. Use <CFLOCATION or a javascript redirect to return to the main page.

The main page would probably also call the cfc to determine the quantities ordered for each product.
0
 
LVL 17

Assisted Solution

by:Tacobell777
Tacobell777 earned 300 total points
ID: 10856283
If you post the page to itself and then at the top of the page call the CFC you do not need to do a refresh or relocation.

All you do at the top of the page is <cfif isDefined("url.productid")> call the cfc </cfif>
0
 

Author Comment

by:finnstone
ID: 10856330
taco, thats an awesome idea, thanks
0
 
LVL 18

Expert Comment

by:Plucka
ID: 10856342
You can also do it without the page refreshing at all, but taco's answer is the simplest.
0
 

Author Comment

by:finnstone
ID: 10864744
wait if i call the cfc, then wont i then go to the cfc, and then i will have to do a cflocation just to get back to the main page??

can you show me how this would e done
0
 
LVL 17

Expert Comment

by:Tacobell777
ID: 10866541
Page-----------

<cfif isDefined("url.productid")>
call your cfc here
</cfif>

<a href="thissamepage.cfm?productid=44">add me</a>
0
 
LVL 18

Expert Comment

by:Plucka
ID: 10866562
Calling a method in a CFC doesn't actually run the page like <CFLOCATION. It just calls the function and returns to the calling page, passing back paramaters if they exist.

Taco's example is correct.

I assume the cfc will return an array or structure of ordered items. So you will need to check this when redisplaying the page to display the current qty in the order.
0
 

Author Comment

by:finnstone
ID: 10924109
i am getting an error message from this line of code - it says expression required

 <td width="24%"><div align="center"><input type="button" value="Add to Cart" onclick="antique_lamps.cfm?addprodId=#PRODUCT.productoid#"></div></td>
0
 
LVL 18

Expert Comment

by:Plucka
ID: 10924149
Sorry, must have abreviated this.

 <td width="24%"><div align="center"><input type="button" value="Add to Cart" onclick="window.location.assign('antique_lamps.cfm?addprodId=#PRODUCT.productoid#');"></div></td>
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SSL sertificate 5 75
Linux Hosting 16 81
web & database SERVERS -- PHYSICAL & VM ? 5 81
Link failure 16 71
Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question