Shopping cart function, need help...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
WithHisStripes
Forum Contributor
Posts: 131
Joined: Tue Sep 13, 2005 7:48 pm

Shopping cart function, need help...

Post by WithHisStripes »

Heya,
I need to create a way that a user can click a checkbox (that's in a seperate JS window) and click an "add to cart" button where it is then sent to a temporary shopping cart. Can anyone help?

Thanks!
-Spence
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

That's a very vague question.

But, from what I gather you want to be able have a separate window/frame where a user can select a product that would then add an item to a shopping cart (I assume the cart is "housed" on the parent window/frame).

if that's the case, you'll need JS to do it:

something like:

this assumes a separate "pop-up" window

Code: Select all

<script>
updateParent(what)
{
    if(what.checked)
        opener.document.someForm.item.value = what.value
}
</script>
<input type="checkbox" name="someProduct" value="myProduct" onClick="updateParent(this)">
WithHisStripes
Forum Contributor
Posts: 131
Joined: Tue Sep 13, 2005 7:48 pm

Post by WithHisStripes »

Yeah, that's exactly what I'm trying to accomplish.
Thanks, that code brings me a little closer. Now, that's just the code for my checkbox and the code to update my parent directory once they hit the submit button, but I don't have a parent directory either. Can you help me figure out how to create that parent directory? I'm not using a user login or any of that, simply their order needs to be cached until they leave the site.
I am building this thing from scratch and I'm not experienced, so bear with me. Thanks a ton

-Spence
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

the best way to do it would be to set up sessions (not to log in, but to "capture" and "hold" the cart info). So if you used my example above, you could update the form field on the parent page then submit the form to add the item to the cart. Using that method will allow you to add something to a session variable as well (perhaps the cart ID from a DB or the like) and then rebuild the page from the server side.

the alternative (and the way that I *personally* would do it) would be to use DHTML to modify the parent page and reflect the updated cart information on the client side. They could then click the shopping cart to see details about info in the cart, or proceed to a checkout... etc etc.
WithHisStripes
Forum Contributor
Posts: 131
Joined: Tue Sep 13, 2005 7:48 pm

Post by WithHisStripes »

Okay, yeah that's what some other people suggested, using sessions. Now, I understand how it works, but I don't know where to begin, and I'm not experienced with PHP enough to write my own code that is that complex, are there some resources that you could point me to that could help me build it as simply as possible? Do you have a script I could use maybe? Thanks so much bud!

-Spence
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

check out hotscripts.com. I'm certain they'll have a shopping cart there.
Post Reply