Best approach to Semi-cart

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
rick.emmet
Forum Commoner
Posts: 70
Joined: Fri Aug 14, 2009 9:43 am

Best approach to Semi-cart

Post by rick.emmet »

Hello All,
I'm attempting to create functionality that allows users to update a sales figure by: adding one of two ad-ons (or both) and / or subtracting a promotional discount if one applies. I'm setting both of my ad-on variables as well as the discount to zero, then I'm using plain PHP to process the math.

When I first arrive on the page, from an editing page, the correct figure is displayed at the bottom of the form ($9.99), but when I click on the recalculate button (form action=”THIS_PAGE”) the base price disappears and the total at the bottom becomes “$0.”

These are $_SESSION variables, so it seems to me that they should remain persistent. I've been looking at JavaScript DOM Storage shopping carts, and the use of multidimensional arrays such as $_SESSION['cart'] to solve this problem. It seems to me that this should be very straightforward, but perhaps I'm approaching this incorrectly.

I would like to get input on the best approach to this problem – don't even want to bother anyone with code at this point. Do any of you have a very reliable approach or model to suggest? Thanks a bunch in advance.
Cheers,
Rick
Attachments
Semi-Cart.jpg
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Best approach to Semi-cart

Post by Christopher »

Not exactly clear what you are doing, but it seem like a little Javascript on that page could easily calculate the total based on the state of radio buttons. The Javascript could also define what gets sent to the Cart. Do you want individual SKUs for each option and the ad itself? Or to bundle it all into one SKU?
(#10850)
rick.emmet
Forum Commoner
Posts: 70
Joined: Fri Aug 14, 2009 9:43 am

Re: Best approach to Semi-cart

Post by rick.emmet »

Hello Christopher,
Thank you for the reply! My service provider has been changing out their equipment and I haven't had access for several days. I don't have SKUs for this app, the classifieds aren't identified in that manner. I use Session variables all the time, but have never created a cart before. JavaScript can of course do the work of adding the options in an On Click Event (may go that way), but I think I have to make the data session variables; and maybe I can do that in JavaScript (that functionality is new to me).

When I have a problem this messed up, it's usually a matter of having the wrong approach, so that's why I didn't post any code. Is there a specific type of functionality that you prefer to use in this kind of situation? Thanks again!
Cheers,
Rick
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Best approach to Semi-cart

Post by Christopher »

As I said, I would populate the possible values in the Javascript code and let it calculate the final value to submit. But SKU, I only mean some unique value/name to define what is being ordered.
(#10850)
rick.emmet
Forum Commoner
Posts: 70
Joined: Fri Aug 14, 2009 9:43 am

Re: Best approach to Semi-cart

Post by rick.emmet »

Hello Christopher,
Got it - I haven't been able to work on this for days, but will start in now. Thanks much for your assistance.
Cheers,
Rick
Post Reply