Ver Mensaje Individual
  #13 (permalink)  
Antiguo 20/01/2009, 13:49
Avatar de kimmy
kimmy
 
Fecha de Ingreso: julio-2008
Mensajes: 841
Antigüedad: 15 años, 9 meses
Puntos: 15
Respuesta: Pasar datos de una función a otra página

Hola:

He logrado pasar todos los datos menos los de la cantidad de productos que es el valor $qty. No se como guardarlos dentro del array. Lo que comentaba iba asi.

Esta es la funcion del carrito

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 "<table border = 0 width = 100% cellspacing = 0>
<form action = mostrar_cart.php method = post>
<tr><th colspan = ". (1+$images) ." bgcolor=\"#cccccc\">Item</th>
<th bgcolor=\"#cccccc\">Precio</th><th bgcolor=\"#cccccc\">Cantidad</th>
<th bgcolor=\"#cccccc\">Total</th></tr>";

//display each item as a table row
foreach ($cart as $sku => $qty)
{
$product = get_product_details($sku);
echo "<tr>";
if($images ==true)
{
echo "<td align = left>";
if (file_exists("images/$sku.jpg"))
{
$size = GetImageSize("images/".$sku.".jpg");
if($size[0]>0 && $size[1]>0)
{
echo "<img src=\"images/".$sku.".jpg\" border=0 ";
echo "width = ". $size[0]/3 ." height = " .$size[1]/3 . ">";
}
}
else
echo "&nbsp;";
echo "</td>";
}
echo "<td align = left>";
echo "<a href = \"mostrar_product.php?sku=".$sku."\">".$product o["title"]."</a> by ".$product["author"];
echo "</td><td align = center>$".number_format($producto["price"], 2);
echo "</td><td align = center>";
// if we allow changes, quantities are in text boxes
if ($change == true)
echo "<input type = text name = \"$sku\" value = $qty size = 3>";
else
echo $qty;
echo "</td><td align = center>$".number_format($producto["price"]*$qty,2)."</td></tr>\n";
}
// display total row
echo "<tr>
<th colspan = ". (2+$images) ." bgcolor=\"#cccccc\">&nbsp;</td>
<th align = center bgcolor=\"#cccccc\">
$items
</th>
<th align = center bgcolor=\"#cccccc\">
\$".number_format($total_price, 2).
"</th>
</tr>";
// display save change button
if($change == true)
{
echo "<tr>
<td colspan = ". (2+$images) .">&nbsp;</td>
<td align = center>
<input type = hidden name = save value = true>
<input type = image src = \"images/save-changes.gif\"
border = 0 alt = \"Save Changes\">
</td>
<td>&nbsp;</td>
</tr>";
}
echo "</form></table>";
}
?>

Esta es la página que lo muestra

<?
include ('sc_fns.php');

session_start();

if($new)
{
//nuevo artículo seleccionado
if(!session_is_registered("cart"))
{
$cart = array();
session_register("cart");
$items = 0;
session_register("items");
$total_price = "0.00";
session_register("total_price");
}
if($cart[$new])
$cart[$new]++;
else
$cart[$new] = 1;
$total_price = calculate_price($cart);
$items = calculate_items($cart);

}
if($save)
{
foreach ($cart as $sku => $qty)
{
if($$sku=="0")
unset($cart[$sku]);
else
$cart[$sku] = $$sku;
}
$total_price = calculate_price($cart);
$items = calculate_items($cart);
}

do_html_header("Tu carro de compras");

if($cart&&array_count_values($cart))
display_cart($cart);
else
{
echo "<p>No hay artículos en tu carro";
echo "<hr>";
}
$target = "index.php";
// si hemos añadido un artículo al carro, continuar comprando en esa categoría
?>
<br>
<table width="450" border="0" align="right">
<tr>
<td><? display_button("checkout.php", "go-to-checkout", "Go To Checkout"); ?>
<div align="right"></div>
<div align="right"></div>
<div align="center"></div>
<div align="center"></div></td>
</tr>
<tr>
<td><? display_button($target, "continue-shopping", "Continue Shopping");
$path = $PHP_SELF;
$path = str_replace("mostrar_cart.php", "", $path);
?>
<div align="right"></div>
<div align="right"></div>
<div align="center"></div>
<div align="center"></div></td>
</tr>
</table>
<?
do_html_footer();
?>

Cómo hago para que se arrastre la variable $qty; dentro del array $cart. No se como ponerlo. Por favor me pueden ayudar a solucionarlo pues llevo como una semana tratando y no lo logro.

Gracias.