Re: [PHP] Here's a weird one!

2002-10-27 Thread @ Edwin
Hello,

I think the problem lies here:

> $qty = $formqty;
>  if($cart[$new])
>   //$cart[$new]++;
>$cart[$new] = $cart[$new] + $qty;
> else
>   $cart[$new] = 1;
> $total_price = calculate_price($cart);
> $items = calculate_items($cart);
>   }

It seems like you should be adding the $qty on the "else" part and NOT here:

--> $cart[$new] = $cart[$new] + $qty;

However, I just checked the site and it seems like it's working fine.

I'm using Netscape 7, by the way...

- E


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Here's a weird one!

2002-10-27 Thread Steve Jackson
I've been trying for ages to add a form field qty to an array to pass it to
my shopping cart and have finally managed it but not quite.
Please check this cart:
http://www.violasystems.com/shop_testing/

When you add an item using the form text box it doesn't add more than 1 on
the first submit. However if you go back and then add  further items it's
will add the multiple products to the cart? I have three functions which
control this and can't see where I'm going wrong:

Submitting the form:
echo " ";
   echo "";
   echo "Quantity required: ";
   echo "";
   echo "";
   echo "";
   echo "";
   echo " ";

Processing the form:

 $qty)
{
  if($$ItemCode=="0")
unset($cart[$ItemCode]);
  else
$cart[$ItemCode] = $$ItemCode;
}
$total_price = calculate_price($cart);
$items = calculate_items($cart);
  }

  do_html_header("Your shopping cart");
  //array de-bug
  //print_r($cart);
  if($cart&&array_count_values($cart))
display_cart($cart);
  else
  {
echo " There are
no items in your cart";
echo "";
  }
  $target = "index.php";

  // if we have just added an item to the cart, continue shopping in that
category
  if($new)
  {
$details =  get_product_details($new);
if($details["catid"])
  $target = "show_cat.php?catid=".$details["catid"];
  }
  $path = $PHP_SELF;
  $path = str_replace("show_cart.php", "", $path);
  echo " ";
  display_button($target, "continue-shopping", "Continue Shopping");
  display_button("http://".$SERVER_NAME.$path."checkout.php";,
"go-to-checkout", "Go To Checkout");
  echo "";
  do_html_footer();
?>


And displaying the cart:

function display_cart($cart, $change = true, $images = 1)
{
  // display items in shopping cart
  // optionally allow changes (true or false)
  // optionally include images (1 - yes, 0 - no)

  global $items;
  global $total_price;
  echo "

 Item
PriceQuantity
Total";

  //display each item as a table row
  $qty = $formqty;
  foreach ($cart as $ItemCode => $qty)
  {
 $product = get_product_details($ItemCode);
echo " ";
if($images ==true)
{
  echo "";
  if (file_exists("images/$ItemCode.jpg"))
  {
 $size = GetImageSize("images/".$ItemCode.".jpg");
 if($size[0]>0 && $size[1]>0)
 {
   echo "";
 }
  }
  else
 echo " ";
  echo "";
}
echo "";
echo "".$product["ItemName"]."
(Code) ".$product["ItemCode"];
echo "€ ".number_format($product["price"], 2);
echo "";
// if we allow changes, quantities are in text boxes
if ($change == true)
  echo "";
else
  echo $qty;
echo "€
".number_format($product["price"]*$qty,2)."\n";
  }
  // display total row
  echo " 
   
  
  $items
  
  
  € ".number_format($total_price, 2).
  "
";
  // display save change button
  if($change == true)
  {
echo " 
 

  
  

 
";
  }
  echo "";
}


Any help much appreciated.
rgds
Steve.