Jump to content


Photo

Homemade Shopping Cart Question


  • Please log in to reply
2 replies to this topic

#1 ImJustBrndn

ImJustBrndn
  • Members
  • PipPip
  • Member
  • 28 posts

Posted 20 August 2006 - 08:27 AM

I need help making the output of my cart be sent via email or something that will allow me to know what the people ordered. I'm having problems doing this bc only one of the items show up, none of the others do. Any help would be really appreciated.

#2 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 20 August 2006 - 08:35 AM

How do you set the items in the cart? Session or ?

Please post your code so that I may look over it. Use the []code Tags

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#3 ImJustBrndn

ImJustBrndn
  • Members
  • PipPip
  • Member
  • 28 posts

Posted 20 August 2006 - 05:31 PM

It's set via session. This is the heart of the cart code minus the site its built around. Thanks again.

<?
include "functions_cart.php";
$totalvalue = 0;

session_start();
// If no sessions has been started $_SESSION["cart"] equals null, thus showing the message no items.
if (!isset($_SESSION["cart"])) {
	$_SESSION["cart"] = NULL;
}

if (validate() == TRUE && $_SESSION["cart"] != NULL) {
					
	foreach ($_SESSION["cart"] as $key => $session_data) {
		
		list($ses_id, $ses_quan) = $session_data;
						
			// call database connect function
			db_connect();
			$sel_products = mysql_query("SELECT * FROM $mysql_tablename WHERE id=".$ses_id."");
			$item = mysql_fetch_array($sel_products);
				
			$totalvalue = $totalvalue + $shipping + ($item["price"]*$ses_quan);
			$subtotal = ($item["price"]*$ses_quan);
			$shipping = (3.00*ses_quan);
					
	?>
				<tr>
				<td class="style11"><div align="center"><a href="<? echo "phpCart_manage.php?act=del&pid=".$ses_id; ?>"><img src="remove_button.gif" width="60" height="21" border="0"></a></div></td>
				<td class="style11"><input name="newquan[]" type="text" id="newquan[]3" value="<? echo $ses_quan; ?>" size="5" maxlength="4">
				<input name="eid[]" type="hidden" id="eid[]" value="<? echo $ses_id; ?>"></td>
				<td class="style11"><? echo $item["product"]; ?></td>
				<td class="style11"><? echo $cur_symbol."".number_format($item["price"], 2, '.', ''); ?></td>
				<td class="style11"><? echo $cur_symbol."".number_format($subtotal, 2, '.', ''); ?></td>
				</tr>
	<?
	} // end foreach loop
	
} elseif ($_SESSION["cart"] == NULL) {

	echo "<td colspan=\"5\"><center><p>Your basket is currently empty.</p></center></td>";
			
} else {
	
	echo "<td colspan=\"5\"><center><p>Unknown Error.</p></center></td>";

}
	?>
				<tr>
				<td class="style11">&nbsp;</td>
				<td class="style11">&nbsp;</td>
				<td class="style11">&nbsp;</td>
				<td class="style11"><strong>Shipping</strong></td>
				<td class="style11"><? echo $cur_symbol."".number_format($totalvalue, 2, '.', ''); ?>&nbsp;</td>
				</tr>
				<tr>
				  <td class="style11">&nbsp;</td>
				  <td class="style11"><? if ($_SESSION["cart"] != NULL) { echo "<input name=\"UpdateChg\" type=\"submit\" id=\"UpdateChg\" value=\"Update\">"; } ?></td>
				  <td class="style11"><a href="index.php">Continue Shopping</a></td>
				  <td class="style11"><strong>Total</strong></td>
				  <td class="style11"><? echo $cur_symbol."".number_format($totalvalue, 2, '.', ''); ?></td>
				</tr>
				<tr>
				  <td class="style11">&nbsp;</td>
				  <td class="style11">&nbsp;</td>
				  <td class="style11">&nbsp;</td>
				  <td class="style11">&nbsp;</td>
				  <td class="style11">&nbsp;</td>
				  </tr>
				<tr>
				  <td colspan="5" class="style11">&nbsp;</td>
				  </tr>
				</table>
				</form>






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users