Solved

Creating dynamic items to add to cart

Posted on 2014-10-17
7
121 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 110

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 110

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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 110

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 110

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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
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…
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

749 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