473,841 Members | 1,674 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

[ASP/vbScript] Shopping Cart - removing items by quantity - theory..

Hi all,

Ok - so I've got the array thing going on, and the session thing going on,
and up until now its all been ok.

I've got my view basket page which is displaying 3 rows (as an example) - I
have an input box on each row enabling the user to update the quantity.

If the enter a zero I need to remove the item from the array....

Without getting too much into code - I was hoping for an "in words" reply as
to how to get around my problem...

I have 2 loops - one outer, one inner, which are iterating through 2 arrays,
the outer array is that of the "quantities " as posted by the form, the inner
array is that of the items in the basket as populated from the session.

Now - I've tried implementing my code that removes items from the array, but
I've discovered a problem....beca use I need to remove the item I end up
using a temporary array to store the items that are NOT being removed, then
I resize the original array and pop 'em back in. Because the size of the
original array has now changed, if there are more than one item in the
basket which are being removed (by entering a zero for quantity) when it
gets to the next zero to deal with, the index has changed on the array -
thus buggering my loops a tad...

Any thoughts/theories on the approach to this - again, ideally in words
rather than code - its late and my eyes hurt :o(

Thanks in advance for any help.

Regards

Rob
Jun 13 '06 #1
9 2591
oooh...dont you just hate it when you have a good idea you think might be
the solution just AFTER posting to the group (or am I the only one that does
this - still nice to talk to myself!)..

Ok - how's this sound...

I iterate through the outer array (items in the basket), and the inner array
(quantities) - I update the quantities accordingly...

Then, I iterate through the basket items array again, this time, taking
products from it where the quantity is greater than zero and placing them
into a new array.

At the end of it I should have an array with just the basket items with a
quantity > 0 ...

Sound ok?

Regards

Rob
Jun 13 '06 #2

"Rob Meade" <te************ *********@edaem .bbor> wrote in message
news:Mz******** **********@text .news.blueyonde r.co.uk...
Hi all,

Ok - so I've got the array thing going on, and the session thing going on,
and up until now its all been ok.

I've got my view basket page which is displaying 3 rows (as an example) - I have an input box on each row enabling the user to update the quantity.

If the enter a zero I need to remove the item from the array....

Without getting too much into code - I was hoping for an "in words" reply as to how to get around my problem...

I have 2 loops - one outer, one inner, which are iterating through 2 arrays, the outer array is that of the "quantities " as posted by the form, the inner array is that of the items in the basket as populated from the session.

Now - I've tried implementing my code that removes items from the array, but I've discovered a problem....beca use I need to remove the item I end up
using a temporary array to store the items that are NOT being removed, then I resize the original array and pop 'em back in. Because the size of the
original array has now changed, if there are more than one item in the
basket which are being removed (by entering a zero for quantity) when it
gets to the next zero to deal with, the index has changed on the array -
thus buggering my loops a tad...

Any thoughts/theories on the approach to this - again, ideally in words
rather than code - its late and my eyes hurt :o(

Thanks in advance for any help.

Regards

Rob


Have you considered not using arrays but using XML instead. You can safely
store a FreeThreadedDOM Document in the session object.
Jun 14 '06 #3
"Anthony Jones" wrote ...
Have you considered not using arrays but using XML instead. You can
safely
store a FreeThreadedDOM Document in the session object.


Hi Anthony,

Thank you for your reply - I have to confess that I've not considered using
XML - at the time the array seemed the obvious way to go.

What would be the advantage of using XML? In addition -is this actually an
XML "file" or a string of XML elements? I only ask as potentially there
could be lots of carts being used at once and if files are involved I'm not
entirely sure how that would work.

Any further info is appreciated.

Regards

Rob
Jun 14 '06 #4
>> What would be the advantage of using XML?
XML has a higher "cool factor".

The original intent behind XML was that it is simply text, used to
communicate between disparate systems, especially via HTTP.

Now-a-days, even if your application only communicates with itself, if your
app doesn't use XML, you run the risk of being found guilty of non-buzzword
compliance by the PHB or someone in Marketing & Sales.

Bob Lehmann

"Rob Meade" <ku************ ***@edaem.bor> wrote in message
news:e$******** ******@TK2MSFTN GP04.phx.gbl...
"Anthony Jones" wrote ...
Have you considered not using arrays but using XML instead. You can
safely
store a FreeThreadedDOM Document in the session object.
Hi Anthony,

Thank you for your reply - I have to confess that I've not considered

using XML - at the time the array seemed the obvious way to go.

What would be the advantage of using XML? In addition -is this actually an XML "file" or a string of XML elements? I only ask as potentially there
could be lots of carts being used at once and if files are involved I'm not entirely sure how that would work.

Any further info is appreciated.

Regards

Rob

Jun 15 '06 #5
"Bob Lehmann" wrote...
What would be the advantage of using XML?

XML has a higher "cool factor".


ROTFL!

Nice reply :oD

I was expecting a reply more a long the lines of "arrays are more costly on
the servers resources" or something like that - hehe.. :o)

Rob
Jun 15 '06 #6
> I was expecting a reply more a long the lines of "arrays are more costly

:>)

Invariably, the usual flow with XML is ...

Load the XML document
Parse and loop through the tags and their children
Place values in an array
Loop through the array
Process the data

Cool!

I'm not saying that XML doesn't have its place, but it *is* highly overused
/ abused.

Bob Lehmann

"Rob Meade" <te************ *********@edaem .bbor> wrote in message
news:Jm******** **********@text .news.blueyonde r.co.uk...
"Bob Lehmann" wrote...
What would be the advantage of using XML? XML has a higher "cool factor".


ROTFL!

Nice reply :oD

I was expecting a reply more a long the lines of "arrays are more costly

on the servers resources" or something like that - hehe.. :o)

Rob

Jun 16 '06 #7
Rob Meade wrote:
"Anthony Jones" wrote ...
Have you considered not using arrays but using XML instead. You can
safely
store a FreeThreadedDOM Document in the session object.
Hi Anthony,

Thank you for your reply - I have to confess that I've not considered
using XML - at the time the array seemed the obvious way to go.

What would be the advantage of using XML?


1. Using the selectSingleNod e and selectNodes methods combined with XPATH
queries, xml domdocuments () aka "xml documents" for shortare easily
searchable.
2. Nodes can easily be removed from and inserted into the body of the xml
document.

If you don't need either of these functions (as well as the other
functionality provided by the MS XML Parser), then use arrays. However, in
your case, xml documents seem to be what you need.
In addition -is this
actually an XML "file" or a string of XML elements?


Neither.
No files need to be involved, although they can be.
An xml document is an object provided by the MS XML Parser library. It has
properties, collections and methods which can be used to work with the xml
contained in the document object. Its free-threaded version can be safely
stored in session or application. It has a Save method which can be used to
save its xml to a file, or to stream it to Response or an ADO Stream
(allowing it to be serialized into a recordset object). ADO recordsets also
have a Save method which allow their contents, metadata and data, to be
saved to a file as xml, or streamed into an xml document. I have an example
of this here:
http://www.davidpenton.com/testsite/...ver2client.asp

Here is another example of using xml documents:
http://www.davidpenton.com/testsite/...ta.islands.asp
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jun 16 '06 #8
Bob Lehmann wrote:
I was expecting a reply more a long the lines of "arrays are more
costly
)


Invariably,


Invariable? :-)
the usual flow with XML is ...

Load the XML document
Parse and loop through the tags and their children
Place values in an array


Huh??
Why would anyone ever do that?

I think you're exaggerating here to be funny.
I have made extensive use of xml documents and not once have I ever moved
data from a document into an array.
Neither have I ever seen any examples of anyone doing this.
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jun 16 '06 #9

"Rob Meade" <ku************ ***@edaem.bor> wrote in message
news:e$******** ******@TK2MSFTN GP04.phx.gbl...
"Anthony Jones" wrote ...
Have you considered not using arrays but using XML instead. You can
safely
store a FreeThreadedDOM Document in the session object.
Hi Anthony,

Thank you for your reply - I have to confess that I've not considered

using XML - at the time the array seemed the obvious way to go.

What would be the advantage of using XML? In addition -is this actually an XML "file" or a string of XML elements? I only ask as potentially there
could be lots of carts being used at once and if files are involved I'm not entirely sure how that would work.

Any further info is appreciated.

Regards

Rob


Sorry Rob I went offline for a few days. I think Mr Barrows has pretty much
covered it though.

Here's a really noddy example of an order entry page. (Note I'm just
demonstrating FreeThreadedDOM , avoiding other techniques and other good
practices a real world solution would use.)

Create an empty default.asp file in a folder somewhere and paste in the
below:-

<%
Option Explicit

Dim goOrderDOM
Dim goProductDOM

Dim goLine
Dim i

If IsEmpty(Session ("OrderDOM") ) Then
Set goOrderDOM = Server.CreateOb ject("MSXML2.Fr eeThreadedDOMDo cument.3.0")
goOrderDOM.asyn c = False
goOrderDOM.load XML "<order />"
Set Session("OrderD OM") = goOrderDOM
Else
Set goOrderDOM = Session("OrderD OM")
End If

If IsEmpty(Applica tion("ProductDO M")) Then
Set goProductDOM =
Server.CreateOb ject("MSXML2.Fr eeThreadedDOMDo cument.3.0")
goProductDOM.as ync = False
goProductDOM.lo ad Server.MapPath( "Products.x ml")
Set Application("Pr oductDOM") = goProductDOM
Else
Set goProductDOM = Application("Pr oductDOM")
End If

If Request.ServerV ariables("REQUE ST_METHOD") = "POST" Then ProcessPost

%>
<html>
<head>
<title>Simple Order Entry</title>
</head>
<body>
<form method="POST" action="default .asp">
<table rules="all">
<thead>
<tr>
<th>Product</th><th>Quantity </th>
</tr>
</thead>
<tbody>
<%
i = 0
For Each goLine In goOrderDOM.docu mentElement.chi ldNodes
%>
<tr>
<td><%=GetProdu ctName(goLine)% ></td>
<td class="quantity "><%=goLine.get Attribute("quan tity")%></td>
</tr>
<%
i = i + 1
Next
%>
<tr>
<td>
<select name="cboProduc t">
<option>- Select Product -</option>
<%DrawProductOp tions()%>
</select>
</td>
<td><input type="text" value="0" name="txtQty" /></td>
</tr>
</tbody>
</table>
<input type="submit" value="Post" />
</form>
</body>
</html>
<%

Function GetProductName( roLine)

Dim sProdID
Dim oProduct

sProdID = roLine.getAttri bute("productID ")

Set oProduct = goProductDOM.se lectSingleNode( "//product[@ID=""" & sProdID &
"""]")

GetProductName = Server.HTMLEnco de(oProduct.Tex t)

End Function

Sub DrawProductOpti ons

Dim oProd

For Each oProd in goProductDOM.do cumentElement.c hildNodes
Response.Write "<option value=""" & oProd.getAttrib ute("ID") & """>" & _
Server.HTMLEnco de(oProd.Text) & "</option>"
Next

End Sub

Sub ProcessPost()

Dim sProdID
Dim lQty
Dim oLine

sProdID = Request.Form("c boProduct")
lQty = CLng(Request.Fo rm("txtQty"))

If sProdID <> Empty Then

Set oLine = goOrderDOM.sele ctSingleNode("/order/line[@productID=""" &
sProdID & """]")

If lQty > 0 Then
If oLine Is Nothing Then
Set oLine =
goOrderDOM.docu mentElement.app endChild(goOrde rDOM.createElem ent("line"))
oLine.setAttrib ute "productID" , sProdID
End If
oLine.setAttrib ute "quantity", lQty
Else
If Not oLine Is Nothing Then
goOrderDOM.docu mentElement.rem oveChild(oLine)
End If
End If

End If

End Sub
%>
In the sample folder paste the following into a Products.xml file:-

<products>
<product ID="1">Widgets </product>
<product ID="2">Gizzmos </product>
<product ID="3">Thingama bobs</product>
</products>
That's it. Note that once a object holding the Order lines is added to the
session object it's never done again in that session. There's no need to
retrieve the object then put it back when finished (like you do with an
array). Most of the time a simple object pointer is retrieved from the
session object.

Note also the list of products is held in the application object. Hence
this in only done once for the whole application and all sessions can share
the same instance of the product list.
FWIW, I don't use standard HTML forms at all. If I were to develop an
application like this in the real world the order XML would be built client
side and only posted to the server on completion (XMLHTTPRequest ). The
receiving ASP page might to do some pre-processing/validation of the XML
then passed to SQL Server batch or SP as a NTEXT parameter which is parsed
up with OPENXML.

Anthony.
Jun 18 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2723
by: Phil Powell | last post by:
I need a back-to-basics shopping cart tutorial in PHP/mySQL. I thought I had it down and I failed, as usual. Here is what I mapped out as a spec: 3) initial work on bestilling.php to contain the following plan: 1) Cookie: 'nordicnet_bestilling' to contain unique, random 16-char string 2) Table: nnet_produkt_bestilling to contain ordering information bundled by unique bestilling_id (16-char string) a) produkt_id
4
1925
by: Adil Akram | last post by:
I've developed a shopping cart app in ASP, to secure transaction by SSL, it 've put only the checkout page in SSL but all other pages i.e. product, cart etc remains on non SSL connection. How can I track user session from non SSL to SSL checkout page as the SessionID changes when shifting to SSL (to prevent session stealing/ hijacking). I'm tracking user session by putting SessionID in cart DB with products. Given below the preview of cart...
17
5022
by: Roland Hall | last post by:
I eliminated cookies from my shopping cart this morning. I'm now using sessions to keep track of users. In my global.asa I have the following: sub Session_onStart session.Timeout = 20 session("ticket") = CInt(0) end sub sub Session_onEnd
2
2148
by: Mark Hannon | last post by:
I am designing a PayPal shopping cart/store for a client and have placed several of PayPal's shopping cart forms on the page to correspond with different products. Each form has a unique name though each of the form's elements have to use PayPal's required naming conventions to pass the data to their server. Many of the forms have hard-coded data in them and these have not caused me any problems. The problems I am having are with 3 forms...
1
1975
by: Paul Goodley | last post by:
Typically, shopping carts add a single item at a time, so it's easy to prompt the user for information needed for the order, but what if the shopping cart needs to process thirty items at once? I am working on a shopping cart for a wholesale project and have run into trouble. Retailers log into the site, click a link to take them to the category, and get table with images and a checkbox. They click the checkbox of each item they want to...
0
951
by: psb | last post by:
imagine a shopping cart application. I am on the product details page. this page has a cart summary on the right hand side of the page. the cart summary is a webcontrol that sits in the aspx page like this: <GSG:CARTSUMMARY id="CartSummary" runat="server"></GSG:CARTSUMMARY> in this webcontrol is a datagrid of all items in the cart. this particular application has a Max Order Quantity Limit. At the bottom of the product details page...
4
2416
by: Winshent | last post by:
I am having problems with adding items to my shopping cart. The problem occures when adding items that already exists in the cart. When a user adds to cart, they are automatically redirected to the cart, where they can update quantities. If the item already exists in the cart, i want to update the quantity by adding 1 to the quantity of that item. The code all works fine when i step thru the code, however when running it without...
1
7304
by: jecha | last post by:
I'm implementing a shopping cart but am having a problem in checking out a person who has added item in his/her shopping busket.The code for the checkout.php script is given below <? require_once('functions.inc.php'); session_start(); do_html_header("Checkout"); $cart = $_SESSION; if($cart&&array_count_values($cart)) { display_cart($cart,false,0); display_checkout_form($HTTP_POST_VARS);
0
9706
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10927
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10667
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10303
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7848
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7025
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5691
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5880
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3140
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.