SaranacLake Posted September 15, 2020 Share Posted September 15, 2020 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?! Quote Link to comment https://forums.phpfreaks.com/topic/311487-how-to-update-shopping-cart/ Share on other sites More sharing options...
requinix Posted September 15, 2020 Share Posted September 15, 2020 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? Quote Link to comment https://forums.phpfreaks.com/topic/311487-how-to-update-shopping-cart/#findComment-1581401 Share on other sites More sharing options...
SaranacLake Posted September 15, 2020 Author Share Posted September 15, 2020 (edited) 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 September 15, 2020 by SaranacLake Quote Link to comment https://forums.phpfreaks.com/topic/311487-how-to-update-shopping-cart/#findComment-1581402 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.