close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

using javascript to add item(s) to cart

Thread began 10/09/2012 8:17 am by CraigR | Last modified 10/10/2012 11:37 am by CraigR | 10850 views | 9 replies |

CraigRBeta Tester

using javascript to add item(s) to cart

I am playing around with jquery, using sortable with connected lists - to drag and drop elements into a list which I want to use as a 'pre-cart' so that when I add an add to cart behavior to my page, it takes all elements from my list and adds them to the cart.

I can store the 'pre cart' elements in a js array, and also store them in a cookie, but haven't worked out how to add them to the cart.

I guess that clicking the add to cart button will reload the page, so I need to store the elements in a cookie or session variable, (haven't worked the session variable bit out yet, but I can store a cookie ok).

Then I guess that when the page reloads, I take my cookie/session string values, and pass the values into the cart using a do while loop ?

Is this a sensible approach ?

Grateful for any ideas/advice

Sign in to reply to this post

Jason ByrnesWebAssist

it'll take a good amount of hand coding to accomplish this.

use JQUERY to store the items ID in a session array.

see this thread for details on saving to a session using jquery:
setting-a-php-sessionvar-using-jquery


create a recordset that will use the Session to return the selected items, and use the Add to Cart get contents from recordset to populate the cart with the selected items.

Sign in to reply to this post

CraigRBeta Tester

thanks for the reply Jason.

I got it working, (with a cookie for now), I am passing the selected id's back as a filter into a lookup recordset and the items are added to the cart in a loop.

Only thing is, with the ecart get from recordset server behavior, there is no option (i can see) if an item is already in the cart.

I tried adding _AddIfIn=0 manually, but this doesn't work, whatever I do, i can only add one of each item to the cart

Sign in to reply to this post

Jason ByrnesWebAssist

The quantity would need to be set on the cart display page.

Sign in to reply to this post

CraigRBeta Tester

Ok good enough.

Thanks for your help

Sign in to reply to this post

CraigRBeta Tester

Further from my question from yesterday...

I have a number of elements, stored in a session variable, which I am using to build up a filter criteria string.
This seems to work ok.

I can then use the resulting recordset to populate the cart using ecart get from recordset server behaviour.

What I also need to do is count the number of each itemid in my string or array, so that I can use this to put the appropriate quantities of the respective id’s in the cart.
I appreciate this will take a bit of hand coding, but need a shove in the right direction.

For example, my filter criteria may say something like
“SELECT ItemID, `Description`, Colour, Price FROM tblitems WHERE ItemID = 2 OR ItemID = 5”

But I may have 3 instances of itemid 2 and 1 instance of itemid 5 to add.

I can extract this information from my session variable by manipulating the string or array, but can’t work out how to add these values to the cart.

Sign in to reply to this post

Jason ByrnesWebAssist

the get contents from recordset behavior uses a recordset loop.

inside the loop, you will need to add code to check which ID is currently being added, look up the count of times that id occurs in your string, then use that value to set the quantity.


the first few lines look like this:

php:
<?php

// WA eCart Get Info From RS
if (eCart1->IsEmpty() && isset($totalRows_recordsetName) && $totalRows_recordsetName 0)     {
  
$Redirect_redirStr="";
  do     {
    
$eCart1_itemID floatval("".$row_recordsetName['ProductID']  ."");
}



$row_recordsetName['ProductID'] is the current ID being added, use that to look up the quantity in the session

Sign in to reply to this post

CraigRBeta Tester

thanks Jason, I'll look at that tomorrow.

One final question with respect to this.

my add to cart button now has 2 functions, on click it fires the javascript to set the session value, then posts the form.

it works, but I wondered, is this intrinsic behavior, will the javascript always fire before the form is posted or do I need to set this behavior.

Sign in to reply to this post

Jason ByrnesWebAssist

since your using onclik event, yes, it will always trigger the JS before the form is submitted. the click action happens first, the onClick action is otherwise known as the onMouseDown action. onMouseUp is the action that submits the form.

Sign in to reply to this post

CraigRBeta Tester

thanks Jason.

I'm really starting to get into jquery now, appreciate the help.

Sign in to reply to this post
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...