Link to home
Start Free TrialLog in
Avatar of amir321
amir321

asked on

PHP SHoppiing cart without Database

Hello Dear Freinds

SO here i goes...

I would like to make a site for restuarent. People goes online and can order from website and send to email.

So what i want is that people can select from Pizza page some Items and when they go to other page(for eg salate) the information from first Page(Pizza) won't be deleted. Inshort User Surf lot of pages and can add varioud Items from various pages and can delete or Update Items and then after selecting Items he click on confirm Order then he will be able to see all items how much it cost and if he wantto add or delete Items and then he gave his name address and all deatils and when he send Send order the order must be send in Email. And ihave make some settings on Server email will be faxed to restuarent.

So what i want is that a shopping cart without any database any without any registration in php or CGi.
can anyone helpme.
thanx
Avatar of Arijit S
Arijit S
Flag of India image

Hi,

This can be done simply by using:
(A) Shopping Process:
1. Session (say, in PHP it will be $_SESSION) variable to keep the information (of user/products/cart)
2. Using text file to store user specifi events & upon successful completion of the process (i.e. user decides & send the order via email/fax) those text files can either be saved for future reference or upon a spefic period of time...can be deleted to save space

(B) Coming to the 2nd part i.e. email->fax, here you have to use some service providers like:
http://www.efax.com/
http://www.faxaway.com/about.shtml#internet_fax

[There are many more...just use Google]

As it stands...ideally you should use a scripting language like PHP/ASP/JSP to help you work with user activity (e.g. selecting & adding a product to his/her cart & moving on....& then finally placing the order...whereby sending an email...which in turn sends the fax).

So, by this process you will be able to eliminate the requirement of the Database for the time being...but if you really look for a robust structure, you should be looking forward to store user information in the Database when an user submits an order. Yes, you will collect that info & it will be sent to you via email->fax. But, what happens the 2nd time the same user comes bak to your site (which I am sure you will love to have...repeat business)? Coz. as per this structure...your user will again have to fill in all the information & then submit (to some extent this can be narrowed down by using cookies..but I will suggest using an economical DB like MySQL).

Hope this helps.
Regards
WC
Avatar of Marvin_Carredo
Marvin_Carredo

http://ph.php.net/session
http://ph.php.net/function.mail

you can use session in storing the data before sending it via email.
you can also mail() in sending an email.

additional hint:
//this means that the client others 2 boxes of pizza 1
$pizza1 = $_SESSION['Pizza1'] = 2;
$pizza2 = $_SESSION['Pizza2']   = 0;

$message ='Pizza 1 =' $pizza1. 'and Pizza 2 ='. $pizza2;
mail("oder@pizza.com", "Order Pizza",$message);

Just out of curiosity, how do you plan on avoiding abuse of this site without any login function or any user validation of some kind? If just anyone can go to this site and order a pizza how will the resteraunt know the legitimate orders from the fakes?


Alan
Avatar of amir321

ASKER

Dear Alan
You are right but the money which i will get from myclient won't be enough tomake site with database.if he wont cheap service then he will not get database andd if he need database then he must pay more.

So resturant or my client will get order my email and then they will phone him and confirm order.
I assume Amir plans to validate every order by confirming over the phone...then only delivering.
Else...if someone is paying (after placing an order)...no harm in delivering I guess. ;)

Regards
WC
Avatar of amir321

ASKER

all what is that i don't need database support bcz my client won't pay more for database support of the site. And the simple way is all Order or Details must send my email
Ok, I see. Thanks for the info. The reason I asked is I have written a similar system for some local resteraunts and I made it account based with logins because of the fear of abuse and fake orders and I was wondering if you had found a way around it that I didnt think of.

You are correct though, if the client doesn't want to pay for a "proper" site, then he gets what he pat he pays for.


Alan
Give this a go mate ;-)

<?php

define('PIZZA_SMTP','your.smtp.server');
define('PIZZA_EMAIL','Your Name <your.emailaddre.ss>');
define('PIZZA_FROM','Pizza Server <your.email@ddre.ss>');
define('PIZZA_LIVE',0);

session_start();
if(!isset($_SESSION['order'])){
      $_SESSION['order']=array();
}

$order =& $_SESSION['order'];

$db=array(
      "nap"=>array("Pizzas","Napoletana","famous naples pizza",10.95)
      ,"cap"=>array("Pizzas","Capricciosa","how do you spell this?",9.95)
      ,"mar"=>array("Pizzas","Marinara","with seafood",13.35)
      ,"sal"=>array("Salads","Garden salad","just leaves",4.50)
      ,"gks"=>array("Salads","Greek salad","blah",5.50)
      ,"cok"=>array("Drinks","Coke 2 L","Bottle",2.50)
);

$dbcat=array("Pizzas","Salads","Drinks");

$action="list";
if(isset($_GET['action'])){
      $action=$_GET["action"];
}

print("<h1>Pizza Restaurant</h1>");
print("<p>Select a category: ");
foreach($dbcat as $v){
      print("<a href=\"?action=list&cat=".urlencode($v)."\">".htmlspecialchars($v)."</a> ");
}
print("</p>");

switch($action){
      case "add":
            if(!isset($_GET['id'])){
                  die("No item select, please go back");
            }
            $id=$_GET['id'];
            if(isset($db[$id])){
                  $order[$id]++;
            }
            break;

      
      case "remove":
            if(!isset($_GET['id'])){
                  die("No item select, please go back");
            }
            $id=$_GET['id'];
            if(isset($order[$id]) && $order[$id]>1){
                  $order[$id]--;
            }else{
                  unset($order[$id]);
            }
            break;
      
      case "send":
            $name=$_POST['name'];
            $tel=$_POST['tel'];
            $addr=$_POST['addr'];
            
            $s="PIZZA ORDER\n\n";
            $s.="name: $name\n";
            $s.="tel: $tel\n\n";
            $s.="addr: \n$addr\n\n";
            $s.="--------------\n";
            $total = 0;
            foreach($order as $o=>$n){
                  $line = $db[$o][3] * $n;
                  $s.=$db[$o][1]." ($".$db[$o][3].") x ".$n." = $line\n";
                  $total+=$line;
            }
            $s.="total = ".$total."\n";
            $s.="end of order";
            
            ini_set('SMTP',PIZZA_SMTP);
            $headers=array("From: ".PIZZA_FROM);
            $headers[]="X-Mailer: PHP/" . phpversion();
            $headers[]="Date: ".date('r');

            if(PIZZA_LIVE){
                  print("Sending to ".htmlspecialchars(PIZZA_EMAIL)." via ".ini_get('SMTP').".");
                  if(mail(PIZZA_EMAIL,"ORDER FOR $name",$s,join("\r\n",$headers))){
                        print("Your order has been sent!");
                        
                        print("<pre>".htmlspecialchars($s)."</pre>");
                        
                        die("All done! Please wait for a phone call.");
                  }else{
                        die("An error occured: your order hasn't been sent");
                  }
            }else{
                  print("<pre>");
                  print("<font color=green>");
                  print(htmlspecialchars(join("\n",$headers))."</font><br>");
                  print($s);
                  print("</pre>");

                  die("<font color=red><b>TEST MODE - NO MESSAGE SENT TO THE PIZZA SHOP</b> (SET PIZZA_LIVE TO 1 WHEN YOU HAVE TESTED THIS)</font>");
            }
            
      case "clear":
            $order=array();
            break;
            
      case "list":
            break;
      
      default:
            die("Invalid action");
}

$cat="Pizzas";
if(isset($_GET['cat'])){
      $cat=$_GET['cat'];
}
print("<h2>".htmlspecialchars($cat)."</h2>");

print("<p>Click on the name of one of the following items and it will be added to your order (you can remove it later)</p>");

print("<dl>");
$found=0;
foreach($db as $k=>$v){
      if($v[0]==$cat){
            print("<dt><a href=\"?action=add&id=".urlencode($k)."\">".htmlspecialchars($v[1])."</a> $".htmlspecialchars($v[3])."</dt><dd>".htmlspecialchars($v[2])."</dd>\n");
            $found=1;
      }
}
print("</dl>");
if(!$found)print("<p>Nothing in this category :-(</p>");

//-------

if(!count($order)){
      print("No items in your order (yet)!");
}else{
      print("<h2>Your order</h2>");
      print("<p>Be sure to check out our <b>salads</b> and <b>drinks</b> before completing your order!</p>");
      print("<table border=1><tr><th>Item</th><th>Quantity</th><th>Total</th><td>");
      print("<a onclick=\"javascript:return confirm('this will clear your order');\" href=\"?action=clear\"><b>remove all</b></a>");
      print("</td></tr>");
      $total = 0;
      foreach($order as $o=>$n){
            $line = $db[$o][3] * $n;
            print("<tr><td>".$db[$o][1]." ($".$db[$o][3].")</td><td>".$n."</td><td align=right>".sprintf('%0.2f',$line)."</td><td><a href=\"?action=remove&id=".urlencode($o)."\">remove</a></td></tr>");
            $total+=$line;
      }
      print("<tr><td colspan=2><b>Total</b></td><td align=right>".sprintf('%0.2f',$total)."</td></tr>");
      print("</table><br>");
      

      print("<form method=post action=\"?action=send\">");
      print("Name: <input name=name><br>");
      print("Telephone: <input name=tel><br>");
      print("Address: <textarea rows=5 cols=40></textarea><br>");
      print("<input type=submit onclick=\"javascript:return confirm('your order will now be sent to our shop');\" value=\"send order\"></form>");
}
BTW maybe you would consider awarding 500 points for that effort, huh?
JP
While I agree that you have made a nice effrot, Begging for points is very unbecoming. Have some pride man!


Alan
woops second last line should read

print("Address: <textarea name=addr rows=5 cols=40></textarea><br>");
'Maybe you would like to give me some points as well Alan ;-)
Dignity? Bah!
You can have all my points, they are menaingless. If I could trade them in for a toaster oven or t-shirt or something that would be one thing. I am here stricly for the feeling I get when I help someone fix a problem. <;o)


Alan
Cool down guys. Let us ensure that a problem gets a proper solution. As long as the purpose is served...what teh heck with points. :D

Regards
WC

PS: Jdpipe...cool snippet. Loved it...didn't try that though ;)
Hey WC no worries it's cool. I just write that code then only afterwards realised I'd gone to all that effort for so few points, I thought wow that's so far beyond the call of. Blush.
JP
Not sure who needs to "cool down" but I hope my comments where not taken as inflamatory. They where not menat to be. I was just suggesting that we as experts offering answers shouldn't be asking for points as it makes us look like we are here begging for points. It was said in jest and menat to be 'humorous'. I apologize if it was taken wrong.


Alan
ASKER CERTIFIED SOLUTION
Avatar of bimal_linux
bimal_linux

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi there, just to add my 2c worth, or 2p worth in my case, although your client doesn't wish to pay more money for the use of a database and login system, it might be worth explaining to him fully why using such a system would be adventageous.  Such as the easily additional of new toppings, or changing prices of different pizzas, not to mention the security and order tracking and statistics and so on.  At least then you've done your part and informed him of how it could be and that security and fake orders might cause him problems if he uses the system this way.

Obviously you've probably already told him this, in which case I'm sorry for mentioning it again :)

It might also be an idea to use a CSV file format with the different pizza's and toppings in, at least then it's a bit easier for him to change prices and add new items.

Cheers

-Matt-
Avatar of amir321

ASKER

Hi bimal Linux

I have tryed quick.Cart but i don't know how to use same programming concepts with my existing site

http://www.royalpizzaonline.de/shop/chines.php
http://www.royalpizzaonline.de/shop/Indien.php

please let me know if youhave some idea

regards
amir
Avatar of amir321

ASKER

hi  jdpipe

So i have seen your code it#s work fine but i ghave no idea how i can fix your code toworks with my existing webpage.

http://www.royalpizzaonline.de/shop/chines.php
http://www.royalpizzaonline.de/shop/Indien.php

thanx
Hi Amir

I'm afraid I can give you much more than I've already given. The array '$db' defines the list of products along with their descriptions, prices, categories. The array '$dbcat' defines the categories which you will display. You can add extra HTML at the top and bottom of the file I gave you to improve the layout of the page.

Hope that helps
JP