Solved

Creating dynamic items to add to cart

Posted on 2014-10-17
7
118 Views
Last Modified: 2014-12-29
I am creating a "shopping cart" for my site. It really isn't a cart since there is nothing being purchased. It is more of a function to gather order details.

The product needs to be assembled in the order form and then added to the cart. Most of the stock/pre-made carts I have looked at out there all involve pulling an item from a database and adding it to the cart. Since every order is custom, I need to be able to dynamically build a product before adding it to the cart.

I was thinking about building this into the database I am using, building the order and putting each dynamic item in the cart via the database. I want to eventually get there, but not yet.

Does anyone have something quick and dirty in mind that could help shortcut through this without putting the order into a db? An example would help.
0
Comment
Question by:RaneCloud
  • 4
7 Comments
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 40387496
I think you would need to store the order details somewhere, and a database is exactly what we would use for this purpose.  Any reason why you wouldn't want to use one?
0
 
LVL 4

Accepted Solution

by:
Jernej Navotnik earned 500 total points
ID: 40410184
Dear RaneCloud,

as Ray Paseur already stated, databases are the "man" for the job.
But you could use native PHP sessions I suppose that store data in memory (keep in mind the session typically lasts only as long as the browser is not closed)...

Here is a really basic example (page1.php):
<?php
// Start the session
session_start();
?>
<html>
<body>
<?php
// Set session variables
$_SESSION["product"] = "car";
$_SESSION["color"] = "red";
echo "Session variables are set.";
?>
</body>
</html>

Open in new window


To get those stored variables (page2.php):
<?php
session_start();
?>
<html>
<body>
<?php
// Echo session variables that were set on previous page
echo "The product was: " . $_SESSION["product"] . ".<br>";
echo "The color was:  " . $_SESSION["color"] . ".";
//Or to display all session data:
print_r($_SESSION);
?>
</body>
</html>

Open in new window


Keep in mind, this is not the "best" way to go (to each his own I say), but it can be done...
You could also use normal files, but using these would be more complicated than a database.

Best regards!
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 40411656
If you decide that the PHP session is the way you want to store this information, you will want to know exactly how PHP sessions work.  It's not always intuitive and it can result in loss of data.  This article can help a bit.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11909-PHP-Sessions-Simpler-Than-You-May-Think.html
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 58

Expert Comment

by:Gary
ID: 40520713
I've requested that this question be closed as follows:

Accepted answer: 500 points for Jernej Navotnik's comment #a40410184

for the following reason:

This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 40520714
A shopping cart that uses the PHP session without a data base to back it up is a technically incompetent solution.  It can result in a loss of client data.  It would be better for E-E to delete this question than to keep this as an example of a "good idea."
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 40522800
Gary:  Please don't mischaracterize my concern -- I don't think the question is "stupid," as you say, and I never said anything like that.  It's a good question!  It's a question that many of us have dealt with over the years.  I think the accepted solution does not represent something any professional would choose and it does not belong where it can be discovered and ascribed to Experts-Exchange.

But as I wrote, if you feel strongly that this is a good answer, then I'm more than willing to listen to your side.   Personally, I could not defend this approach.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Sort Multidimensional Array 11 34
updating table data with inner join 9 24
Whether to store ID's or text values for detailed information 3 20
PHP warning 4 30
This article discusses four methods for overlaying images in a container on a web page
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now