Ecommerce site promotions system

Discussion in 'PHP' started by afonseca, May 24, 2007.

  1. #1
    Hi all!

    I need to develop a very complicated ecommerce site promotions system.
    It looks like this:

    I have a normal packing and price.

    packing price
    1 €2

    I want to make a promotion for 2 weeks that automaticaly revert to previous state as the date expiry.

    to 2007/06/07
    packing price
    1 €1

    But the problem starts here: I want to have a system thats presents the normal price, because the client will only have a promotion if it buys more then x quantaties.
    like this:

    to 2007/06/07
    packing price more then promotional price
    1 €1 10 €0,5

    Does anyone ever saw this? Any developed code, example?

    Thanks in advance!
    António
     
    afonseca, May 24, 2007 IP
  2. gibex

    gibex Active Member

    Messages:
    1,060
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    95
    #2
    go in sell/trade forum, maybe you can find a developer to do your system:)
     
    gibex, May 24, 2007 IP
  3. tinkerbox

    tinkerbox Peon

    Messages:
    55
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    It not very hard to do unless you new to programming.
    I think there is shopping cart system which able to do as what you explain.
    But normally cart is pack with many other things makes some ppl try to develop their own. And integrating or blend with your website is more difficult than you develop your own.

    If you put some of your code, its easier for us here to help
     
    tinkerbox, May 24, 2007 IP
  4. afonseca

    afonseca Peon

    Messages:
    48
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hi!

    Well below there is my shoping chart.
    I have a table products that has another table (subproducts) linked. The ideia is I have a product that as many references.
    In my system only some subproducts of a product will have promotion.
    My inicial idea was to add 4 new fields in subproducts table (new price, % of promotion, number of packs to have the promotion and a promotion on/off).
    So If I have a on in the promotion field the system will present the other 3 plus the other that already are there (including the price without the promotion)!

    Hope that I 've been clear. If not please let me know.
    António




    <td width="33%" colspan="2" class="bglinha"><br />
    <span class="titulo1">CARRO DE COMPRAS </span></td>
    </tr>

    <tr>
    <td height="19" colspan="2" align="center" valign="top" class="style4">
    <br />
    <?php
    mysql_select_db($database_medical, $medical);
    include("db.php");


    switch($_GET["action"])
    {
    case "add_item":
    {
    AddItem($_GET["id"], $_GET["qty"], $_GET["cod"]);
    ShowCart();
    break;
    }
    case "update_item":
    {
    UpdateItem($_GET["id"], $_GET["qty"]);
    ShowCart();
    break;
    }
    case "remove_item":
    {
    RemoveItem($_GET["id"]);
    ShowCart();
    break;
    }
    default:
    {
    ShowCart();
    }
    }

    function AddItem($itemId, $qty, $cod)
    {
    // Will check whether or not this item
    // already exists in the cart table.
    // If it does, the UpdateItem function
    // will be called instead

    global $dbServer, $dbUser, $dbPass, $dbName;

    // Get a connection to the database
    $cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);

    // Check if this item already exists in the users cart table
    $result = mysql_query("select count(*) from cart where cookieId = '" . GetCartId() . "' and itemId = $itemId ");
    $row = mysql_fetch_row($result);
    $numRows = $row[0];

    if($numRows == 0)
    {
    // This item doesn't exist in the users cart,
    // we will add it with an insert query

    @mysql_query("insert into cart(cookieId, itemId, qty, cod) values('" . GetCartId() . "', $itemId, $qty, '$cod')");
    }
    else
    {
    // This item already exists in the users cart,
    // we will update it instead

    UpdateItem($itemId, $qty);
    }
    }

    function UpdateItem($itemId, $qty)
    {
    // Updates the quantity of an item in the users cart.
    // If the qutnaity is zero, then RemoveItem will be
    // called instead

    global $dbServer, $dbUser, $dbPass, $dbName;

    // Get a connection to the database
    $cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);

    if($qty == 0)
    {
    // Remove the item from the users cart
    RemoveItem($itemId);
    }
    else
    {
    mysql_query("update cart set qty = $qty where cookieId = '" . GetCartId() . "' and itemId = $itemId");
    }
    }

    function RemoveItem($itemId)
    {
    // Uses an SQL delete statement to remove an item from
    // the users cart

    global $dbServer, $dbUser, $dbPass, $dbName;

    // Get a connection to the database
    $cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);

    mysql_query("delete from cart where cookieId = '" . GetCartId() . "' and itemId = $itemId");
    }

    function ShowCart()
    {
    // Gets each item from the cart table and display them in
    // a tabulated format, as well as a final total for the cart

    global $dbServer, $dbUser, $dbPass, $dbName;

    // Get a connection to the database
    $cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);

    $totalCost = 0;
    $result = mysql_query("select * from cart inner join sub_produto on cart.itemId = sub_produto.ID where cart.cookieId = '" . GetCartId() . "' order by sub_produto.codigo asc");

    $result1 = mysql_query("select * from cart where cookieId = '" . GetCartId() . "' order by cod asc");
    $num=mysql_num_rows($result1);

    if ($num == 0){
    print "O carro de compras encontra-se vazio.";
    }
    else{

    ?>
    <form name="frmCart" method="post">
    <table width="100%" cellspacing="0" cellpadding="0" border="0">
    <tr>
    <td width="12%" height="25" bgcolor="#CCCCCC">
    <div align="left"><font face="verdana" size="1" color="white"> <span class="linkum">&nbsp;</span><b>Nr. Emb.</b> </font> </div></td>
    <td width="13%" bgcolor="#CCCCCC"><div align="left" class="linkum"><font face="verdana" size="1" color="white"> <b>C&oacute;digo</b> </font> </div></td>
    <td width="26%" height="25" bgcolor="#CCCCCC"><div align="left"><strong><font color="white" size="1" face="verdana">Produto</font></strong></div></td>
    <td width="18%" bgcolor="#CCCCCC" class="linkum"><div align="left"><font face="verdana" size="1" color="white"> <span class="linkum"><b>Uni. venda </b></span> </font> </div></td>
    <td width="11%" bgcolor="#CCCCCC"><div align="left" class="linkum"><font face="verdana" size="1" color="white"> <b>Pre&ccedil;o uni. </b></font></div></td>
    <td width="11%" height="25" bgcolor="#CCCCCC"><div align="left"><font face="verdana" size="1" color="white"><b>Sub Total </b></font></div></td>
    <td width="9%" height="25" bgcolor="#CCCCCC">
    <div align="left" class="linkum"><font face="verdana" size="1" color="white">
    <b>Remover</b></font>&nbsp;</div></td>
    </tr>
    <?php

    while($row = mysql_fetch_array($result))
    {
    $id=$row['itemId'];
    $qtd=$row['qty'];
    $preco=$row['euro'];
    $preco_desc=$row['preco_desc'];
    $cod=$row['codigo'];
    $idprd=$row['produto'];
    $qry = mysql_query("select * from produto where id = $idprd ");
    $campos = mysql_fetch_array($qry);

    // Increment the total cost of all items
    if ($preco_desc<>"" and $row['promocao']==1){
    $preco = str_replace(",",".",$preco_desc);
    }
    else{
    $preco = str_replace(",",".",$preco);
    }

    $Subtotal=floatval($preco)*$qtd;
    $totalCost += floatval($preco)*$qtd;
    $Subtotal=str_replace(".",",",$Subtotal);

    //@mysql_query("insert into cart (cod) values(sdsdf) where cookieId = '" . GetCartId() . "' and itemId = $id");
    @mysql_query("update cart set preco = '$Subtotal' where cookieId = '" . GetCartId() . "' and itemId = $id");

    ?>
    <tr>
    <td width="12%" height="25">
    <div align="left"><font face="verdana" size="1" color="black">
    <?php $id=$row['itemId'];?>
    <? //print "<input type=\"text\" name=\"qty'.$id.'\" value='.$qtd.' size=\"3\" maxlength=\"3\" onChange='UpdateQty(this)'/>" ?>


    <input name="<?php echo $row["itemId"]; ?>" onChange='UpdateQty(this)' type="text" value="<?php echo $row["qty"]; ?>" size="1">

    </font> </div></td>
    <td width="13%"><div align="left"><font face="verdana" size="1" color="black"> <?php echo $row['codigo']; ?> </font> </div></td>
    <td width="26%" height="25"><div align="left"><font face="verdana" size="1" color="black"><? print"<a href='detalhe_prod.php?ler=$campos[id]&cod_cat=$campos[id_titulo]'> $campos[produto]</a>"?></font> </div></td>
    <td width="18%" height="25"><div align="left"><font face="verdana" size="1" color="black"><?php echo $row['empacotamento']; ?> </font> </div></td>
    <td width="11%"><div align="left"><font face="verdana" size="1" color="black"> &euro;<?php if ($row['preco_desc']<>"" and $row['promocao']==1){
    echo $row['preco_desc']; }
    else{
    echo $row['euro'];
    }
    ?>
    </font> </div></td>
    <td width="11%" height="25"><div align="left">&euro;<?php echo $Subtotal; ?></div></td>
    <td width="9%" height="25">
    <div align="center"><font face="verdana" size="1" color="black">
    <a href="cart.php?action=remove_item&id=<?php echo $row['itemId']; ?>"><img src="images/trash.gif" border=0 alt="remover"></a> </font> </div></td>
    </tr>
    <?php
    }

    // Display the total
    ?>
    <tr>
    <td colspan="7">
    <hr size="1" color="red" NOSHADE> </td>
    </tr>
    <tr>
    <td colspan="4"></td>
    <td colspan="3">
    <div align="right"><font face="verdana" size="2" color="black">
    <b>Total: &euro; <?php echo $totalCost=str_replace(".",",",$totalCost); ?><br />
    <br />
    </b> </font> </div></td>
    </tr>
    <tr>
    <td colspan="7"><div align="left">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td width="29%"><div align="center">
    <input type="button" name="Button" value="Actualizar" />
    </div></td>
    <td width="38%"><div align="center">
    <INPUT TYPE="button" VALUE="Voltar" onClick="history.back()">

    </div></td>
    <td width="33%"><div align="center"><a href="encomendar.php"></a>
    <input name="Submit3" type="submit" onclick="MM_goToURL('parent','encomendar.php');return document.MM_returnValue" value="Encomendar" />
    </div></td>
    </tr>
    </table>
    </div></td>
    </tr>
    </table>
    </form>
    <?php

    }
    }

    ?>
    <br />
    <br />
    <br />
    <br /></td>
     
    afonseca, May 25, 2007 IP