popup.js << mi JS
me_amp01.php << el archivo principal
carrito.php << lib carrito compras
colores.php << ventana colores
Archivo : popup.js
Código HTML:
function colores_window (pagina) { var opciones="toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=550,height=590,top=10,left=10"; window.open(pagina,"",opciones); }
Código PHP:
<?
include("carrito.php");
if(isset($Submit)) {
if (($cant>0) AND isset($cant)) {
$_SESSION["ocarrito"]->introduce_producto($_GET["id"], $_GET["col"], $_GET["cant"], $_GET["precio"]);
}
else {
header("location:".$PHP_SELF."?error=1");
}
}
if(isset($opc)) {
$_SESSION["ocarrito"]->elimina_producto($_GET["linea"]);
}
?>
<HTML>
<HEAD>
<TITLE>CARRITO COMPRAS</TITLE>
</HEAD>
<SCRIPT language=javascript src="popup.js">
</SCRIPT>
<BODY>
<TABLE width=100% border="0" cellPadding="0" cellSpacing="0">
<TBODY>
<TR bgcolor="#000000">
<TD height="115" valign="top" colspan="8" bgColor=#000000> <div align="center">
</div></TD>
</TR>
<TR>
<TD colspan="8"><font color="#FFCC00" size="3">Women's Apparel</font> <div align="center">Click
photo to see larger picture.</div>
<div align="center"><font size="2" face="Times New Roman, Times, serif">Our
solid color classic cardigan in 100 % alpaca is soft and luxurious and
as comfortable as your favorite old pair of shoes !<br>
Select your style, color and size below.</font></div></TD>
</TR>
<TR>
<TD width="4" height="17"></TD>
<TD colspan="3" rowspan="6" valign="top" align="center"><b><font size="3" color="#FF0000"><br>
<br>
Item Code - </font>WA142 - SH</b></TD>
<TD width="49" rowspan="4"></TD>
<TD colspan="3"> </TD>
</TR>
<TR>
<TD height="104"></TD>
<TD width="381" rowspan="4" valign="top">
<!-- form -->
<form name="form" method="GET" action="<?=$PHP_SELF?>">
<table width="90%" border="1" cellpadding="0" cellspacing="1" bordercolor="#666666">
<tr>
<td width="106" height="23" align="left" valign="middle">Color</td>
<td width="237" valign="middle"><input name="col" type="text" id="col" size="4" maxlength="7">
<a href="javascript:colores_window('colores.php')">Select color</a></td>
</tr>
<tr>
<td height="15" colspan="2"></td>
</tr>
<tr>
<TD height="28" align="left" valign="middle">Quantity</TD>
<TD valign="top"> <input name="cant" type="text" id="cant" size=5>
</TD>
</tr>
<tr>
<TD height="15" colspan="2" valign="top"> </TD>
</tr>
<tr>
<TD height="20" valign="middle"> Price</TD>
<TD valign="middle" align="center"><b>$us 80.00</b></TD>
</tr>
<tr>
<TD height="19" colspan="2" valign="top">
<?
if($error==1) echo "<div align='center'><br><font color='#FF0000' size='3'><marquee>Enter the amount</marquee><br></font></div>";
?>
</TD>
</tr>
<tr>
<TD height="20" colspan="2" align="right"> <input name="id" type="hidden" value="WA142">
<input name="precio" type="hidden" value="80"> <input type="submit" name="Submit" value="Add to card" class="boton">
</TD>
</tr>
</table>
</form></TD>
<TD width="29" rowspan="4"></TD>
<TD width="370" valign="top"> <div align="center">
<p><u><b><font size="2">Customize this sweater !</font></b></u></p>
<p><font size="2">Select the style that suits you;<br>
Cardigan, crewneck, turtleneck, button down or pullover vest</font><br>
<br>
<br>
</p>
</div></TD>
</TR>
<TR>
<TD height="28"></TD>
<TD rowspan="3" align="center" valign="top"><u><font size="2">Our Satisfaction
Guarantee</font></u> </TD>
</TR>
<TR>
<TD height="46"></TD>
</TR>
<TR>
<TD height="2"></TD>
<TD></TD>
</TR>
<TR>
<TD height="2"></TD>
<TD colspan="4" align="center" valign="top">
<?
$_SESSION["ocarrito"]->imprime_carrito();
?>
</TD>
</TR>
</TBODY>
</TABLE>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="24%" valign="bottom"><div align="center"></div></td>
<td width="76%" align="center" valign="top"> </td>
</tr>
</table>
</BODY></HTML>
Código PHP:
<?
class carrito {
var $num_productos;
var $array_id_prod;
var $array_col_prod;
var $array_cant_prod;
var $array_pu_prod;
var $array_precio_prod;
function carrito () {
$this->num_productos=0;
}
function introduce_producto($id_prod, $col_prod, $cant_prod, $pu_prod){
// echo $id_prod." ".$nombre_prod." ".$col_prod." ".$tam_prod." ".$cant_prod." ".$pu_prod."<br> ";
$this->array_id_prod[$this->num_productos]=$id_prod;
$this->array_col_prod[$this->num_productos]=$col_prod;
$this->array_cant_prod[$this->num_productos]=$cant_prod;
$this->array_pu_prod[$this->num_productos]=$pu_prod;
$this->array_precio_prod[$this->num_productos]= $this->array_cant_prod[$this->num_productos] * $this->array_pu_prod[$this->num_productos];
$this->num_productos++;
// echo "Numero productos: ".$this->num_productos;
}
//Muestra el contenido del carrito de la compra
//ademas pone los enlaces para eliminar un producto del carrito
function imprime_carrito(){
$sw=0;
for ($i=0;$i<$this->num_productos;$i++) if (!$this->array_id_prod[$i]==0) $sw=1;
if ($sw){
$suma = 0;
echo '
<table border="1" cellpadding="3" cellspacing="0" bordercolor="#000000" bgcolor="#FFFFCE">
<form name="form" method="post" action="compras.php" align="center">
<tr align="center">
<td class="rojo">Id Product</td>
<td class="rojo">Color</td>
<td class="rojo">Quan</td>
<td class="rojo">P/U</td>
<td class="rojo">Price</td>
<td> </td>
</tr>';
for ($i=0;$i<$this->num_productos;$i++){
if (!$this->array_id_prod[$i]==0){
echo '<tr>';
echo "<td>" . $this->array_id_prod[$i] . "</td>";
echo "<td align='center'>" . $this->array_col_prod[$i] . "</td>";
echo "<td align='center'>" . $this->array_cant_prod[$i] . "</td>";
echo "<td align='right'>" . $this->array_pu_prod[$i] ." \$us</td>";
echo "<td align='right'>" . $this->array_precio_prod[$i] . " \$us</td>";
echo "<td align='center'><a href='".$PHP_SELF."?opc=deleteproducto&linea=$i'>Delete Product</td>";
echo '</tr>';
$suma += ($this->array_precio_prod[$i]);
}
}
echo "<tr><td colspan='4'><b>TOTAL PRICE:</b></td><td> <b>$suma \$us</b></td><td>";
echo "<input type='hidden' name='total' value='".$suma."'>";
echo "<input type='submit' name='Submit' value='Buy Product' class='boton'></td></tr>";
echo "</form>";
echo "</table>";
} // if sw valida
}
function elimina_producto($linea){
$this->array_id_prod[$linea]=0;
}
}
session_start();
if (!isset($_SESSION["ocarrito"])){
$_SESSION["ocarrito"] = new carrito();
}
?>
Código HTML:
<HTML><HEAD> <TITLE>Colores</TITLE> </HEAD><BODY> <TABLE width=393 border="0" align="center" cellPadding="0" cellSpacing="0"> <TBODY> <TR> <TD height="62" colspan="3" align="center"> </TD> </TR> <TR> <TD width="110" height="25" align="center" > <a href="#" onclick="opener.document.forms['form']['col'].value='001'; window.close(); return false">COD 001</a></TD> <TD width="110" > <a href="#" onclick="opener.document.forms['form']['col'].value='002'; window.close(); return false">COD 002</a></TD> <TD width="110" > <a href="#" onclick="opener.document.forms['form']['col'].value='003'; window.close(); return false">COD 003</a></TD> </TR> <TR> <TD height="62" colspan="3" > </TD> </TR> <TR> <TD height="25"> <a href="#" onclick="opener.document.form.col.value='006'; window.close(); return false">COD 006</a></TD> <TD > <a href="#" onclick="opener.document.form.col.value='007'; window.close(); return false">COD 007</a></TD> <TD > <a href="#" onclick="opener.document.form.col.value='008'; window.close(); return false">COD 008</a></TD> </TR> </TBODY> </TABLE> </BODY></HTML>
Denme una manito por favor