Jump to content

kusnan12

New Members
  • Posts

    2
  • Joined

  • Last visited

    Never

Everything posted by kusnan12

  1. hello all, i am a newbie on php scripting. and now i still learning more about php. i have some case in my shoping cart. the shoping cart that i use is Powered by Shop-Script FREE shopping cart software(that's a free shoping cart). my problem is when someone buy on my shoping cart, the buyer just know how much he has to pay. but he don't know the delivery price. i want to modify them, so if some one buy on this shopping cart, the buyer will get 2 information: the item price+delivery price. this is for the preview. and my ideas like this: and the template script is like here: <?php /* Smarty version 2.6.0, created on 2009-01-22 21:22:11 compiled from shopping_cart.tpl.html */ ?> <center> <?php if ($this->_tpl_vars['cart_total'] != ""): ?> <table width=75% border=0><tr><td><b><?php echo @constant('CART_TITLE'); ?> :</b></td> <td align=right><a href="index.php?shopping_cart=yes&clear_cart=yes"><img src="images/button_delete.gif" border=0 > <u><?php echo @constant('CART_CLEAR'); ?> </u></a></td></table> <form action="index.php" method=post> <table width=75% border=0 cellspacing=0 cellpadding=5> <tr align="center" bgcolor="#<?php echo @constant('CONF_MIDDLE_COLOR'); ?> "> <td class="menu"><?php echo @constant('TABLE_PRODUCT_NAME'); ?></td> <td class="menu"><?php echo @constant('TABLE_PRODUCT_QUANTITY'); ?></td> <td class="menu"><?php echo @constant('TABLE_PRODUCT_COST'); ?></td> <td width=20></td> </tr> <?php if (isset($this->_sections['i'])) unset($this->_sections['i']); $this->_sections['i']['loop'] = is_array($_loop=$this->_tpl_vars['cart_content']) ? count($_loop) : max(0, (int)$_loop); unset($_loop); $this->_sections['i']['name'] = 'i'; $this->_sections['i']['show'] = true; $this->_sections['i']['max'] = $this->_sections['i']['loop']; $this->_sections['i']['step'] = 1; $this->_sections['i']['start'] = $this->_sections['i']['step'] > 0 ? 0 : $this->_sections['i']['loop']-1; if ($this->_sections['i']['show']) { $this->_sections['i']['total'] = $this->_sections['i']['loop']; if ($this->_sections['i']['total'] == 0) $this->_sections['i']['show'] = false; } else $this->_sections['i']['total'] = 0; if ($this->_sections['i']['show']): for ($this->_sections['i']['index'] = $this->_sections['i']['start'], $this->_sections['i']['iteration'] = 1; $this->_sections['i']['iteration'] <= $this->_sections['i']['total']; $this->_sections['i']['index'] += $this->_sections['i']['step'], $this->_sections['i']['iteration']++): $this->_sections['i']['rownum'] = $this->_sections['i']['iteration']; $this->_sections['i']['index_prev'] = $this->_sections['i']['index'] - $this->_sections['i']['step']; $this->_sections['i']['index_next'] = $this->_sections['i']['index'] + $this->_sections['i']['step']; $this->_sections['i']['first'] = ($this->_sections['i']['iteration'] == 1); $this->_sections['i']['last'] = ($this->_sections['i']['iteration'] == $this->_sections['i']['total']); ?> <tr bgcolor=white> <td><a href="index.php?productID=<?php echo $this->_tpl_vars['cart_content'][$this->_sections['i']['index']]['id']; ?> "><?php if ($this->_tpl_vars['cart_content'][$this->_sections['i']['index']]['product_code'] != ""): ?>[<?php echo $this->_tpl_vars['cart_content'][$this->_sections['i']['index']]['product_code']; ?> ] <?php endif; echo $this->_tpl_vars['cart_content'][$this->_sections['i']['index']]['name']; ?> </a></td> <td align=center><input type="text" name="count_<?php echo $this->_tpl_vars['cart_content'][$this->_sections['i']['index']]['id']; ?> " size=5 value="<?php echo $this->_tpl_vars['cart_content'][$this->_sections['i']['index']]['quantity']; ?> "></td> <td align=center><?php echo $this->_tpl_vars['cart_content'][$this->_sections['i']['index']]['cost']; ?></td> <td align=center><a href="index.php?shopping_cart=yes&remove=<?php echo $this->_tpl_vars['cart_content'][$this->_sections['i']['index']]['id']; ?> "><img src="images/button_delete.gif" border=0 alt="<?php echo @constant('DELETE_BUTTON'); ?> "></a></td> </tr> <?php endfor; endif; ?> <tr bgcolor=white> <td><font class=cat><b><?php echo @constant('TABLE_TOTAL'); ?> </b></font></td> <td><br><br></td><td bgcolor=#<?php echo @constant('CONF_LIGHT_COLOR'); ?> align=center><font class=cat><b><?php echo $this->_tpl_vars['cart_total']; ?> </b></font></td> <td></td> </tr> <tr bgcolor=white> <td> </td> <td> </td> <td bgcolor=#<?php echo @constant('CONF_LIGHT_COLOR'); ?> align=center> </td> <td></td> </tr> </table> <input type=hidden name=update value=1> <input type=hidden name=shopping_cart value=1> <p> <label></label> <table width=75% border=0> <tr><td align=right><input type="submit" value="<?php echo @constant('UPDATE_BUTTON'); ?> "></td></tr> </table> </form> <form action="index.php" method=get> <table width=75% border=0> <tr> <td align=center><input type="button" value="<?php echo @constant('STRING_BACK_TO_SHOPPING'); ?> " onClick="history.go(-1);"></td> <td align=center><input type="submit" value="<?php echo @constant('CART_PROCEED_TO_CHECKOUT'); ?> " style="font-weight: bold; font-size: 120%;"></td> </table> <input type=hidden name=order_custinfo value=yes> </form> <?php else: ?> <p><font><?php echo @constant('CART_EMPTY'); ?> </font> <?php endif; ?> </center> and the mathematics function of shoping cart is here: <?php/***************************************************************************** * * * Shop-Script FREE * * Copyright (c) 2005 WebAsyst LLC. All rights reserved. * * * ****************************************************************************/ // shopping cart //calculate shopping cart value if (isset($_GET["shopping_cart"]) || isset($_POST["shopping_cart"])) { if (isset($_GET["add2cart"]) && $_GET["add2cart"]>0) //add product to cart with productID=$add { $q = db_query("select in_stock from ".PRODUCTS_TABLE." where productID='".$_GET["add2cart"]."'") or die (db_error()); $is = db_fetch_row($q); $is = $is[0]; //$_SESSION[gids] contains product IDs //$_SESSION[counts] contains product quantities ($_SESSION[counts][$i] corresponds to $_SESSION[gids][$i]) //$_SESSION[gids][$i] == 0 means $i-element is 'empty' if (!isset($_SESSION["gids"])) { $_SESSION["gids"] = array(); $_SESSION["counts"] = array(); } //check for current item in the current shopping cart content $i=0; while ($i<count($_SESSION["gids"]) && $_SESSION["gids"][$i] != $_GET["add2cart"]) $i++; if ($i < count($_SESSION["gids"])) //increase current product's quantity { $_SESSION["counts"][$i]++; } else //no item - add it to $gids array { $_SESSION["gids"][] = $_GET["add2cart"]; $_SESSION["counts"][] = 1; } header("Location: index.php?shopping_cart=yes"); } if (isset($_GET["remove"]) && $_GET["remove"] > 0) //remove from cart product with productID == $remove { $i=0; while ($i<count($_SESSION["gids"]) && $_SESSION["gids"][$i] != $_GET["remove"]) $i++; if ($i<count($_SESSION["gids"])) $_SESSION["gids"][$i] = 0; header("Location: index.php?shopping_cart=yes"); } if (isset($_POST["update"])) //update shopping cart content { foreach ($_POST as $key => $val) if (strstr($key, "count_")) { //select product's in stock level $q = db_query("select in_stock from ".PRODUCTS_TABLE." where productID='".str_replace("count_","",$key)."'") or die (db_error()); $is = db_fetch_row($q); $is = $is[0]; if ($val > 0) { for ($i=0; $i<count($_SESSION["gids"]); $i++) { if ($_SESSION["gids"][$i] == str_replace("count_","",$key)) { $_SESSION["counts"][$i] = floor($val); } } } else //remove { $i=0; while ($_SESSION["gids"][$i] != str_replace("count_","",$key) && $i<count($_SESSION["gids"])) $i++; $_SESSION["gids"][$i] = 0; } } header("Location: index.php?shopping_cart=yes"); } if (isset($_GET["clear_cart"])) //completely clear shopping cart { //clear cart unset($_SESSION["gids"]); unset($_SESSION["counts"]); header("Location: index.php?shopping_cart=yes"); } //shopping cart items count $c = 0; if (isset($_SESSION["gids"])) for ($j=0; $j<count($_SESSION["gids"]); $j++) if ($_SESSION["gids"][$j]) $c += $_SESSION["counts"][$j]; //not empty? if (isset($_SESSION["gids"]) && $c) { $k = 0; //total cart value $products = array(); for ($i=0; $i<count($_SESSION["gids"]); $i++) if ($_SESSION["gids"][$i]) { $q = db_query("SELECT name, Price, product_code FROM ".PRODUCTS_TABLE." WHERE productID='".$_SESSION["gids"][$i]."'") or die (db_error()); if ($r = db_fetch_row($q)) { $tmp = array("id"=>$_SESSION["gids"][$i], "name"=>$r[0], "quantity"=>$_SESSION["counts"][$i], "cost"=>show_price($_SESSION["counts"][$i]*$r[1]), "product_code"=>$r[2]); $products[] = $tmp; $k += $_SESSION["counts"][$i]*$r[1]; } } //total... $smarty->assign("cart_content", $products); $smarty->assign("cart_total", show_price($k)); } else { $smarty->assign("cart_total", ""); } $smarty->assign("main_content_template", "shopping_cart.tpl.html"); }?> some body help me...teach me to modify these....before and after i want to say thanks to you all. my master. best regards, kusnan hadinata
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.