Jump to content

Recommended Posts

Hello.

I'm trying to figure out the most logical way to update my shopping cart (table).

When my checkout.php script loads, I need to run some checks on all cart items and take appropriate action.

For example, a "Trial Offer" is only available to non-Members, so if a Member somehow has a "Trial Offer" in his/her shopping cart then I'd like my checkout.php script to remove that automatically from the Member's cart.

So when checkout.php loads, one of the first things I do is to read the user's shopping cart items from the database.

But what is the most logical way to update the shopping cart table?

Do I load the shopping cart records into an array, then iterate through them, remove any non-applicable "Trial Offers" and then write things back to the shopping cart table?  (If so, then how do I merge things?  This is what is confusing me...)

Or do I somehow iterate through the shopping cart records for the user and update each record at a time and avoid loading things into memory like using an array?

Again, this seems like a simple enough task, but I'm not sure the smartest way to do things?!

 

Link to comment
https://forums.phpfreaks.com/topic/311487-how-to-update-shopping-cart/
Share on other sites

10 minutes ago, requinix said:

I'm sorry but it sounds like you're saying that your application is letting in bad data: invalid items in a non-member's shopping cart. That's the problem, isn't it? So how about fixing that problem?

Actually, no, I'm just trying to be a good developer and checking twice!

Yes, if a Member lands on the "Trial Offer" page, that script will prevent them from adding the "Trial Offer" to their shopping cart.  But I figured it would be a good idea in my checkout.php script to do an inventory of things and make sure everything is legit before I move forward.  (Bad data has a crazy way of sneaking in place you never expect?!)

 

So back to my OP...

I was looking at some old old code, and it looks like I could just use PHP to iterate through the user's shopping cart records, and then I can update each record that I come across - without necessarily needing an array - right?  

 

 

Edited by SaranacLake
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.