?
Solved

Creating dynamic items to add to cart

Posted on 2014-10-17
7
Medium Priority
?
123 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
7 Comments
 
LVL 111

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 2000 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 111

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
Put Machine Learning to Work--Protect Your Clients

Machine learning means Smarter Cybersecurity™ Solutions.
As technology continues to advance, managing and analyzing massive data sets just can’t be accomplished by humans alone. It requires huge amounts of memory and storage, as well as the high-speed power of the cloud.

 
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 111

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 111

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

800 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