Hi.  I am trying to set up a script for a custom shopping cart.  
I've set up
the catalog and the page to select a product, which leads to the 
script
below, which adds the product to the cart.  The product being sold 
is wigs;
so each product has an ID, but can be ordered in a variety of colors 
and
sizes.  I need this information in the shopping cart.  I captured it 
by
setting up a multidimensional array.  But I'm having trouble with a 
few
things:
First of all, when I come to the cart, the first item is always an 
empty
array- no product ID, price, etc.  shows up.  For some reason a 
blank set
must be entered into the array, but I can't figure out why.
Secondly, I want to be able to have an option to change quantities 
from the
shopping cart page and have that change saved to the array.  Any
suggestions?  So far everything I've tried has modified the 'qty' 
value for
every single product, not just the one being saved!

I've posted the script below, you can check out the actual pages at
www.customsheitel.com/store/show_cart_2.php

Thanks for your help!


<?php

require ('prod_sc_fns.php');

$new = $_POST['new'];
$prod_num = $_POST['prod_num'];
$color = $_POST['color'];
$cap = $_POST['cap'];
$lace = $_POST['lace'];
$qty= $_POST['qty'];

$i=0;


if($new!=="") //check if new item is selected
{
 if (!isset($_SESSION['cart']))
 {
  $_SESSION['cart']= array(array());
  $_SESSION['items']= 0;
  $_SESSION['total_price']= '0.00';
 }
 if (isset($_SESSION['cart'])&&$prod_num!=="")
 {
 $_SESSION['cart'][$new]['prod_num']= $prod_num;
 $_SESSION['cart'][$new]['color']= $color;
 $_SESSION['cart'][$new]['cap']= $cap;
 $_SESSION['cart'][$new]['lace']= $lace;
 $_SESSION['cart'][$new]['qty']= $qty;

 $_SESSION['total_price']= calculate_price_2($_SESSION['cart']);

 $_SESSION['items']=calculate_items_2($_SESSION['cart']);
 }
}

// if (isset($_POST['save']))
// {
//  foreach ($_SESSION['cart'] as $current)
//  {
//   if($_POST[$current.'_new_qty']=='0')
//    unset($current);
//   else
//    $current['qty']= $_POST[$current.'_new_qty'];
//  }
//  $_SESSION['total_price']= calculate_price_2($_SESSION['cart']);
//  $_SESSION['items']=calculate_items_2($_SESSION['cart']);
// }

echo '<h2>Your Shopping Cart:</h2>';

if (isset($_SESSION['cart']))
 {
   echo '<table border = 0 width = "100%" cellspacing = 0>
       <form action = "show_cart_2.php" method = "post">
       <tr><th colspan = '. (1+$images) .' 
bgcolor="#cccccc">Item</th><th
bgcolor="#cccccc" >Details</th>
       <th bgcolor="#cccccc">Price</th><th 
bgcolor="#cccccc">Quantity</th>
       <th bgcolor="#cccccc">Total</th></tr>';

 //display each item as a table row
 foreach($_SESSION['cart'] as $current)
   {
   $prod = get_prod_details($current['prod_num']);
 {
   echo '<tr>';
   if($images ==true)
   {
     echo '<td align = left>';
     if (file_exists("images/$isbn.jpg"))
     {
        $size = GetImageSize('images/'.$isbn.'.jpg');
        if($size[0]>0 && $size[1]>0)
        {
          echo '<img src="images/'.$isbn.'.jpg" border=0 ';
          echo 'width = '. $size[0]/3 .' height = ' .$size
[1]/3 . ' />';
        }
     }
     else
        echo '&nbsp;';
     echo '</td>';
   }
   echo '<td align="center">';
 echo $current['prod_num'];
 echo ' - ';
 echo $prod['prod_name'];
 echo '</td>';
 echo '<td align = "center">Color: ';
   echo $current['color'];
 echo ', Cap size: ';
 echo $current['cap'];
 echo ', Lace color: ';
 echo $current['lace'];
 echo '</td><td align = "center">$'.$prod['sale_price'];
   echo '</td><td align = "center">';
 echo $current['qty'];
   echo '</td><td align =
"center">$'.number_format($prod['sale_price']*$current
['qty'],2)."</td></tr>\n";

 }

 }
 // display total row
 echo "<tr>
         <th colspan = ". (3+$images) ." 
bgcolor=\"#cccccc\">&nbsp;</td>
         <th align = \"center\" bgcolor=\"#cccccc\">
             ".$_SESSION['items']."
         </th>
         <th align = \"center\" bgcolor=\"#cccccc\">
             \$".number_format($_SESSION['total_price'], 2).
         '</th>
       </tr>';

//       echo '<tr>
//            <td colspan = '. (3+$images) .'>&nbsp;</td>
//            <td align = "center">
//              <input type = "hidden" name ="save" value = "true">
//              <input type = "image" src = "
http://www.customsheitel.com/store/images/savechanges.bmp";
//                     border = 0 alt = "Save Changes">
//            </td>
//        </tr>';

 echo '</form></table>';

 {
 echo '<br />';
 echo '<table width="50%" align="center"><tr align="center">';
 echo '<td><a 
href="http://www.customsheitel.com/store/wigshop.html";>';
 echo '<img 
src="http://www.customsheitel.com/store/images/continue.bmp";
alt="Continue Shopping" border="0" /></td>';
 echo '<td><a 
href="http://www.customsheitel.com/store/checkout.html";>';
 echo '<img 
src="http://www.customsheitel.com/store/images/checkout.bmp";
alt="Checkout" border="0" /></td>';
 echo '</tr></table>';
}

 }
else
{
 echo '<p align="center" >There are no items in your 
cart<br /><br />';
 echo 'Click <a href="
http://www.customsheitel.com/store/shop_lace_2.php";>here</a> to begin
shopping</p>';
}


?>









The php_mysql group is dedicated to learn more about the PHP/MySQL web database 
possibilities through group learning.  
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/php_mysql/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to