Php购物车-每种产品数量的大小和长度

时间:2022-08-18 09:49:44

I have been working on an online store. Project's aim is to add products to a shopping cart.. Customer should be able to change size & length for each quantity for a product. Example :

我一直在网上商店工作。项目的目标是将产品添加到购物车中。顾客应该能够为一个产品的每个数量改变尺寸和长度。例子:

  • I sell a Product named A
  • 我卖的产品叫a
  • customer order 5 pieces of product A
  • 客户订购5件产品A。
  • So he should be able to set 5 size and lengths for product A as the quantity is 5.
  • 所以他应该能够为产品A设定5的尺寸和长度因为数量是5。

Then TCPDF is also there to email the created invoice.

然后TCPDF也在那里以电子邮件的方式创建发票。

I just want some help with the setting of sizes and length for each quantity. Please Please help..

我只是需要一些帮助,为每一个数量的尺寸和长度的设置。请请帮. .

ALso if its possible please assist me with adding those lengths and sizes to the pdf created which is under function sendmail

如果可能的话,请帮助我将这些长度和大小添加到正在运行的sendmail中创建的pdf中。

Following is the code i have written till now...

下面是我写的代码……

<?php
include("include/session.php");
require_once('config/lang/eng.php');
require_once('tcpdf.php');

//Start the session
session_start();

//Create 'cart' if it doesn't already exist
if (!isset($_SESSION['SHOPPING_CART'])){ $_SESSION['SHOPPING_CART'] = array(); }


//Add an item only if we have the threee required pices of information: name, price, qty
if (isset($_GET['add']) && isset($_GET['price']) 
        && isset($_GET['qty']) && isset($_GET['size'])
        && isset($_GET['length'])&& isset($_GET['code']) ){
    //Adding an Item
    //Store it in a Array
    $ITEM = array(
        //Item name
        'name' => $_GET['add'],
        //Item Price
        'price' => $_GET['price'],
        //Qty wanted of item
        'qty' => $_GET['qty'],

        'size' => $_GET['size'],

        'length' => $_GET['length'],

        'code' => $_GET['code']
    );

    //Add this item to the shopping cart
    $_SESSION['SHOPPING_CART'][] =  $ITEM;
    //Clear the URL variables
    header('Location: ' . $_SERVER['PHP_SELF']);
}
//Allowing the modification of individual items no longer keeps this a simple shopping cart.
//We only support emptying and removing
else if (isset($_GET['remove'])){
    //Remove the item from the cart
    unset($_SESSION['SHOPPING_CART'][$_GET['remove']]);
    //Re-organize the cart
    //array_unshift ($_SESSION['SHOPPING_CART'], array_shift ($_SESSION['SHOPPING_CART']));
    //Clear the URL variables
    header('Location: ' . $_SERVER['PHP_SELF']);
}
else if (isset($_GET['empty'])){
    //Clear Cart by destroying all the data in the session
    session_destroy();
    //Clear the URL variables
    header('Location: ' . $_SERVER['PHP_SELF']);
}
else if (isset($_POST['update'])) {
    //Updates Qty for all items
    foreach ($_POST['items_qty'] as $itemID => $qty) {
        //If the Qty is "0" remove it from the cart
        if ($qty == 0) {
            //Remove it from the cart
            unset($_SESSION['SHOPPING_CART'][$itemID]);
        }
        else if($qty >= 1) {
            //Update to the new Qty
            $_SESSION['SHOPPING_CART'][$itemID]['qty'] = $qty;
        }
        foreach ($_POST['items_size'] as $itemID => $size) {
            //If the Qty is "0" remove it from the cart
            if($size >= 1) {
                //Update to the new Qty
                $_SESSION['SHOPPING_CART'][$itemID]['size'] = $size;
        }
    }
    foreach ($_POST['items_length'] as $itemID => $length) {
        //If the Qty is "0" remove it from the cart

        //Update to the new Qty
        $_SESSION['SHOPPING_CART'][$itemID]['length'] = $length;
    }
}
//Clear the POST variables
header('Location: ' . $_SERVER['PHP_SELF']);
}
$req_user = $session->username;
$req_user_info = $database->getUserInfo($req_user);
$need= $req_user;
/* Username */
$username=$req_user;

$q = "SELECT name, address, city, country, postal, email, number, account, counter "
."FROM ".TBL_USERS." WHERE username = '$username'";
$result = $database->query($q);
$num_rows = mysql_numrows($result);


for($i=0; $i<$num_rows; $i++){
$storename  = mysql_result($result,$i,"name");
$address  = mysql_result($result,$i,"address");
$city  = mysql_result($result,$i,"city");
$country  = mysql_result($result,$i,"country");
$postal  = mysql_result($result,$i,"postal");
$email  = mysql_result($result,$i,"email");
$number  = mysql_result($result,$i,"number");
$account  = mysql_result($result,$i,"account");
$counter  = mysql_result($result,$i,"counter");
}


?>
function sendmail($storename,$address,$city,$country,$postal,$number, $email, $account, $counter){
class MYP extends TCPDF {

// Load table data from file
public function LoadData($file) {
// Read file lines
$lines = file($file);
$data = array();
foreach($lines as $line) {
$data[] = explode(';', chop($line));
}
return $data;
}

// Colored table
public function ColoredTable($header, $account, $counter) {
// Colors, line width and bold font
$this->SetFillColor(255, 255, 255);
$this->SetTextColor(0);
$this->SetDrawColor(0, 0, 0);
$this->SetLineWidth(0.3);
$this->SetFont('', 'B');

// Header
$w = array(35, 40);
$num_headers = count($header);
for($i = 0; $i < $num_headers; ++$i) {
$this->Cell($w[$i], 7, $header[$i], 1, 0, 'C', 1);
}
$this->Ln();
// Color and font restoration
$this->SetFillColor(255, 255, 255);
$this->SetTextColor(0);
$this->SetFont('');
// Data
$fill = 0;

$ref = $account.$counter;
$today = date("m.d.y");


$this->Cell($w[0], 6, $today, 'LR', 0, 'C', $fill);
$this->Cell($w[1], 6, $ref, 'LR', 0, 'C', $fill);
$this->Ln();

$fill=!$fill;

$this->Cell(array_sum($w), 0, '', 'T');
}
public function ColoredTable2($header) {
// Colors, line width and bold font
$this->SetFillColor(255, 255, 255);
$this->SetTextColor(0);
$this->SetDrawColor(0, 0, 0);
$this->SetLineWidth(0.3);
$this->SetFont('', 'B');

// Header
$w = array(30, 40, 20,20,20,20);
$num_headers = count($header);
for($i = 0; $i < $num_headers; ++$i) {
$this->Cell($w[$i], 7, $header[$i], 1, 0, 'C', 1);
}
$this->Ln();

// Color and font restoration
$this->SetFillColor(255, 255, 255);
$this->SetTextColor(0);
$this->SetFont('');
// Data
$fill = 0;
$totalamount=0;
foreach ($_SESSION['SHOPPING_CART'] as $itemNumber => $item) {
$tot=$item['qty'] * $item['price'];
$this->Cell($w[0], 6, $item['name'], 'LR', 0, 'C', $fill);
$this->Cell($w[1], 6, $item['size'], 'LR', 0, 'C', $fill);
$this->Cell($w[2], 6, $item['qty'], 'LR', 0, 'C', $fill);
$this->Cell($w[3], 6, $item['length'], 'LR', 0, 'C', $fill);
$this->Cell($w[4], 6, $item['price'], 'LR', 0, 'C', $fill);
$this->Cell($w[5], 6, $tot, 'LR', 0, 'C', $fill);
$this->Ln();
$totalamount=$totalamount+$tot;
$fill=!$fill;
}


$this->Cell(array_sum($w), 0, '', 'T');
}
public function ColoredTable1($header,$txt2,$txt3,$txt4,$txt5) {
// Colors, line width and bold font
$this->SetFillColor(255, 255, 255);
$this->SetTextColor(0);
$this->SetDrawColor(0, 0, 0);
$this->SetLineWidth(0.3);
$this->SetFont('', 'B');

// Header
$w = array(70);
$num_headers = count($header);
for($i = 0; $i < $num_headers; ++$i) {
$this->Cell($w[$i], 7, $header[$i], 1, 0, 'C', 1);
}
$this->Ln();

// Color and font restoration
$this->SetFillColor(255, 255, 255);
$this->SetTextColor(0);
$this->SetFont('');
// Data
$fill = 0;

$this->Cell($w[0], 6, $txt2, 'LR', 0, 'L', $fill);
$this->Ln();
$this->Cell($w[0], 6, $txt3, 'LR', 0, 'L', $fill);
$this->Ln();
$this->Cell($w[0], 6, $txt4, 'LR', 0, 'L', $fill);
$this->Ln();
$this->Cell($w[0], 6, $txt5, 'LR', 0, 'L', $fill);

$this->Ln();
$fill=!$fill;


$this->Cell(array_sum($w), 0, '', 'T');
}
}
function curPageName2() {
return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);
}


$url= curPageName2();
$len=strlen($url);
$furl=substr($url,0,($len-4));
$furl1=$furl.';1;2;3;4;5;6'."\n";

$fp = fopen('cache/table_data_demo1.txt', 'w');
fwrite($fp, $furl1);
fclose($fp);



// create new PDF document
$pdf = new MYP(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nicola Asuni');
$pdf->SetTitle('TCPDF Example INVOICE');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');

//Print all the items in the shopping cart
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.'                                   INVOICE', PDF_HEADER_STRING);

// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

//set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

//set some language-dependent strings
$pdf->setLanguageArray($l);

// ---------------------------------------------------------

// set font
$pdf->SetFont('times', '', 10);

// add a page
$pdf->AddPage();



// set color for background
$pdf->SetFillColor(255, 255, 127);

// MultiCell($w, $h, $txt, $border=0, $align='J', $fill=0, $ln=1, $x='', $y='', $reseth=true, $stretch=0, $ishtml=false, $autopadding=true, $maxh=0)

// set some text for example
$txt = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.';
$header = array('Tax Date', 'Invoice No.');

$html = <<<EOD
<p>Suite-10<br/>3-11 Imperial Road<br/>London<br/>Greater London SW6 2AG<br/><br/></p>
EOD;

$pdf->writeHTMLCell($w=0, $h=0, $x='', $y='', $html, $border=0, $ln=1, $fill=0, $reseth=true, $align='L', $autopadding=true);

$pdf->ColoredTable($header, $account, $counter);
$html = <<<EOD
<br />
EOD;

$pdf->writeHTMLCell($w=0, $h=0, $x='', $y='', $html, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true);

$html = <<<EOD
<br />
EOD;
// Print text using writeHTMLCell()
$pdf->writeHTMLCell($w=0, $h=0, $x='', $y='', $html, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true);
$txt2=$storename;
$txt3=$address;
$txt4=$city.",".$country.",".$postal;
$txt5=$number;
$header=array('Invoice To');
$pdf->ColoredTable1($header,$txt2,$txt3,$txt4,$txt5);
$html = <<<EOD
<br />
EOD;

$pdf->writeHTMLCell($w=0, $h=0, $x='', $y='', $html, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true);



$html = <<<EOD
<br />
EOD;
$totamt = 0;
foreach ($_SESSION['SHOPPING_CART'] as $itemNumber => $item) {
$item['name'];
$item['price'];
$item['qty'];
$tot=$item['qty'] * $item['price'];
$item['size'];
$item['length'];
$totamt=$totamt+$tot;
}


// Print text using writeHTMLCell()
$pdf->writeHTMLCell($w=0, $h=0, $x='', $y='', $html, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true);

$header = array('Item', 'Size', 'Quantity','Length','Rate','Amount');
;
$data = $pdf->LoadData('cache/table_data_demo1.txt');
$pdf->ColoredTable2($header);

$html = <<<EOD
<br />
EOD;

$pdf->writeHTMLCell($w=0, $h=0, $x='', $y='', $html, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true);



$pdf->Ln(4);

// set color for background
$pdf->SetFillColor(220, 255, 220);
$vat=(($totamt*20)/100);
$final=$totamt+$vat;
$vat1='   RATE     VAT     NET   ';
$vat2='E@20%     '.$vat.'    '.$totamt;
$vat3='Terms of Payment: Invoice to be paid immediately. All goods remain the property of Intuzuri UK Ltd until full payment has been received. Copyright in the designs listed above remain the property of Intuzuri UK Ltd. Intuzuri UK Ltd Registered in England Company No. 07880714. Company VAT Number : GB 134 9206 21';

if(strtolower($country) == "usa" || strtolower($country) =="united states of america" || strtolower($country) == "america")
{
$tot1='SUBTOTAL : '.'$'.$totamt;
$tot2='VAT Total : '.'$'.$vat;
$tot5='TOTAL : '.'$'.$final;
$tot3='Payments/Credits : $0.00';
$tot4='Balance Due : '.'$'.$final;
}
else
{
$tot1='SUBTOTAL : '.'GBP '.$totamt;
$tot2='VAT Total : '."GBP ".$vat;
$tot5='TOTAL : '."GBP ".$final;
$tot3="Payments/Credits : GBP 0.00";
$tot4='Balance Due : '."GBP ".$final;
}
$pdf->MultiCell(105, 50, $vat1."\n".$vat2."\n\n".$vat3, 1, 'C', 0, 0, '', '', true, 0, false, true, 40, 'T');
$pdf->MultiCell(65, 50,"\n\n".$tot1."\n\n".$tot2."\n\n".$tot3."\n\n".$tot4."\n\n".$tot5, 1, 'C', 0, 0, '', '', true, 0, false, true, 40, 'M');

// move pointer to last page
$pdf->lastPage();

// ---------------------------------------------------------

//Close and output PDF document
$pdf->Output('example_005.pdf', 'F');





$date = $_POST["datepick"];
$info = $_POST["TextArea1"];

$fileatt = "example_005.pdf"; // Path to the file
$fileatt_type = "application/pdf"; // File Type
$fileatt_name = "Sales_Confirmation.pdf"; // Filename that will be used for the file as the attachment
$email_from = ""; // Who the email is from
$email_subject = "Sales Confirmation"; // The Subject of the email
$email_message = "  ";
$email_message .= "Retailer ".$storename.", has just placed an order. The Order Form is there in the attachment.<br>"
."Please Note Below are the additional details requested by the retailer. <br>"
."Expected Delivery Date : ".$date.".<br>"
."Additional Information : ".$info.".<br>"
."If you would like to Contact the seller, you can contact here : ".$email;
$email_to = ""; // Who the email is to
$headers = "From: ".$email_from;
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
$email_message .= "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$email_message .= "\n\n";
$data = chunk_split(base64_encode($data));
$email_message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
//"Content-Disposition: attachment;\n" .
//" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data .= "\n\n" .
"--{$mime_boundary}--\n";
$sent = @mail($email_to, $email_subject, $email_message, $headers);


}



if (isset($_POST['submit']))
{
$counter++;
$field = "counter";
$value= $counter;
$database->updatecounter($username,$field,$value );
//Everything is good, proceed
sendmail($storename,$address,$city,$country,$postal,$number, $email, $account, $counter);

$result_message = "Thank You, You order have been successfully placed, You will recieve an email shortly., ";
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Intuzuri Retail Online Order Form</title>
<script type="text/javascript" src="datepickr.js"></script>

<style type="text/css">

.calendar {
font-family: 'Trebuchet MS', Tahoma, Verdana, Arial, sans-serif;
font-size: 0.9em;
background-color: #EEE;
color: #333;
border: 1px solid #DDD;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
border-radius: 4px;
padding: 0.2em;
width: 14em;
}

.calendar a {
outline: none;
}

.calendar .months {
background-color: #F6AF3A;
border: 1px solid #E78F08;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
border-radius: 4px;
color: #FFF;
padding: 0.2em;
text-align: center;
}

.calendar .prev-month,
.calendar .next-month {
padding: 0;
}

.calendar .prev-month {
float: left;
}

.calendar .next-month {
float: right;
}

.calendar .current-month {
margin: 0 auto;
}

.calendar .months a {
color: #FFF;
text-decoration: none;
padding: 0 0.4em;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
border-radius: 4px;
}

.calendar .months a:hover {
background-color: #FDF5CE;
color: #C77405;
}

.calendar table {
border-collapse: collapse;
padding: 0;
font-size: 0.8em;
width: 100%;
}

.calendar th {
text-align: center;
}

.calendar td {
text-align: right;
padding: 1px;
width: 14.3%;
}

.calendar td a {
display: block;
color: #1C94C4;
background-color: #F6F6F6;
border: 1px solid #CCC;
text-decoration: none;
padding: 0.2em;
}

.calendar td a:hover {
color: #C77405;
background-color: #FDF5CE;
border: 1px solid #FBCB09;
}

.calendar td.today a {
background-color: #FFF0A5;
border: 1px solid #FED22F;
color: #363636;
}

</style>
<style type="text/css">
<!--
#formArea #orderForm #formColumns {
width:800px;
margin:auto;
}
#formArea #orderForm #formColumns #leftColumn {
float:left;
width:400px;
}
#orderForm {
height:500px;
}
#formArea #orderForm #formColumns #rightColumn {
float:right;
width:400px;
}
#formArea #orderForm #formColumns th {
text-align: left;
}
.copyright {
font-size: 9pt;
}
-->
</style>
</head>
<?
/**
* User has already logged in, so display relavent links, including
* a link to the admin center if the user is an administrator.
*/
if($session->logged_in){
?>
<body>
<div align="center">
<?
echo "<b>$session->username</b>, you are logged in. <br><br>"
."[<a href=\"userinfo.php?user=$session->username\">My Account</a>] &nbsp;&nbsp;"
."[<a href=\"useredit.php\">Edit Account</a>] &nbsp;&nbsp;"
."[<a href=\"process.php\">Logout</a>] &nbsp;&nbsp;"
."[<a href=\"index.php\">View Other Products</a>]";
?>
</div>
<div id="pageHeader">
<h1 align="center">View Your Order here</h1>
</div>
<div id="shoppingCartDisplay">
<form action="" method="post" name="shoppingcart">
<?php
//We want to include the shopping cart in the email
ob_start();
?>
<table align="center" width="800" border="1">
<tr align="center">
<th scope="col">&nbsp;</th>
<th scope="col">Item Name</th>
<td scope="col">Unit Price ( <?php if(strtolower($country) == "usa" || strtolower($country) =="united states of america" || strtolower($country) == "america")
{
echo "$";
}
else
{

echo '&#163;';
}
?> )</td>
<th scope="col">Qty</th>
<td scope="col">Cost ( <?php if(strtolower($country) == "usa" || strtolower($country) =="united states of america" || strtolower($country) == "america")
{
echo "$";
}
else
{

echo "&#163;";
}
?> )</td>
<th scope="col">Change Size</th>
<th scope="col">Change Length</th>

</tr>

<?php
//Print all the items in the shopping cart
foreach ($_SESSION['SHOPPING_CART'] as $itemNumber => $item) {
?>
<tr align="center" id="item<?php echo $itemNumber; ?>">
<td><a href="?remove=<?php echo $itemNumber; ?>">remove</a></td>
<td><?php echo $item['name']; ?></td>
<td><?php echo $item['price']; ?></td>
<td><input name="items_qty[<?php echo $itemNumber; ?>]" type="text" id="item<?php echo $itemNumber; ?>_qty" value="<?php echo $item['qty']; ?>" size="2" maxlength="3" /></td>
<td><?php echo $item['qty'] * $item['price']; ?></td>

<td><select name="items_size[<?php echo $itemNumber; ?>]" value="<?php echo $item['size']; ?>" type="text" id="item<?php echo $itemNumber; ?>_size" >
<option selected="selected" value="<?php echo $item['size']; ?>"><?php echo $item['size']; ?></option>
<option value="2">2</option>
<option value="4">4</option>
<option value="6">6</option>
<option value="8">8</option>
<option value="10">10</option>
<option value="12">12</option>
<option value="14">14</option>
<option value="16">16</option>
<option value="18">18</option>
<option value="20">20</option>
<option value="22">22</option>
<option value="24">24</option>
<option value="26">26</option>
<option value="28">28</option>
<option value="30">30</option>

</select>
<?php
$order=strtotime("now");

if($cntry == "USA" || $cntry =="United States Of America" || $cntry == "America")
{
$price=100;
}
else
{
$price=200;
}

?>
<td><select name="items_length[<?php echo $itemNumber; ?>]" type="text" select="<?php echo $item['length']; ?>" id="item<?php echo $itemNumber; ?>_length" >
<option selected="selected" value="<?php echo $item['length']; ?>"><?php echo $item['length']; ?></option>
<option value="46">46</option>
<option value="48">48</option>
<option value="50">50</option>


</select>

</tr>
<?php
}
?>
</table>
<?php $_SESSION['SHOPPING_CART_HTML'] = ob_get_flush(); ?>
<p>
<div align="center">
Please Make all you selections first (Quantity, Size, Length) and then update.<br /><br /><input type="submit" name="update" id="update" value="Update Cart" />&nbsp;&nbsp;&nbsp;&nbsp;<a href="index.php">Keep Shopping</a>

</div>
</p>
</form>
</div>


<div id="formArea">
<?php if (isset($result_message)) {?>
<div align="center"><h3><?php echo $result_message; ?></h3></div>
<?
}
else {
?>
<p align="center">Once selected all your dresses, please submit your order after reviewing your account details.</p>
<div id="orderForm">
<form action="" method="post" name="orderform">
<div id="formColumns">
<div id="leftColumn">

<table width="100%"  border="0" cellpadding="5" cellspacing="0">

<p align="center"><b>Your Account Information</b></p>
<tr height="21">
<td height="21"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><b>Store Name </b></font></td>
<td height="21"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><?php echo $storename; ?></font></td>
</tr>
<tr>
<td><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><b>Email Address </b></font></td>
<td><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><? echo $email; ?>
</font></td>
</tr>
<tr>
<td><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><b>Phone Number </b></font></td>
<td><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><? echo $number; ?>
</font></td>
</tr>
<tr>
<td><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><b>Billing Address</b></font></td>
<td><? echo $address.',&nbsp<br>'
."$city, $country, $postal"; ?>
</td>
</tr>

<tr>
<td>
</tr>
<tr>
</tr>
</table>
</div>

<div id="rightColumn">
<table width="100%" height="50%"  border="0" cellpadding="3" cellspacing="0">
<p align="center"><b>Additional Information</b></p>

<tr>
<td align="left">
<div align="left">
<font size="2" face="Verdana, Arial, Helvetica, sans-serif">Expected Delivery Date:&nbsp;&nbsp;</font></div>                                                </td>

<td>
<input required="required" id="datepick" name="datepick" class="date-pick" />

<script type="text/javascript">
new datepickr('datepick', { dateFormat: 'm-d-Y' });
</script>
</td>
</tr>
<tr>
<td>
<div align="left">
<font size="2" face="Verdana, Arial, Helvetica, sans-serif">Additional Details:&nbsp;&nbsp;</font></div>                                                </td>
<td>
<textarea  id="TextArea1" name="TextArea1" cols="20" rows="8"></textarea>
</td>
</tr>
<tr>
<td>
<div align="left">
<input name="submit" type="submit" id="submit" value="Submit"></div>                                                </td>
<td style="color: red;">
*Before submitting please verify that all details are correct.
</td>

</tr>

<tr>
<td>
<div align="left">                                                      </div>                                              </td>
</tr>
</table>
</div>
</div>
</div>
</div>
</div>
</form>
</div>
<?php } ?>
</div>
<?
}
else
{
echo '<META HTTP-EQUIV="Refresh" Content="0; URL=main.php">';

}
?>
</body>
</html> 

I tried to do it by creating another session but cant seem to get it done myself.

我试图通过创建另一个会话来实现它,但似乎我自己做不到。

I wanted to make it like... when you will change the quantity to 5... so there should appear 5 dropdowns for size and 5 for length. I could make the dropdowns but couldnt store the selected value in the session.

我想让它看起来……当你将数量改为5时……所以应该有5个下拉的尺寸和5个长度。我可以进行下拉,但是不能在会话中存储所选的值。

Any help is appreciated.

任何帮助都是感激。

To help this explain, Theres a session named Shopping Cart. Now that has array items like price size quantity etc. Now there a function :-

为了解释这一点,有一个名为Shopping Cart的会话。现在有了数组项,比如价格大小,数量等等。现在有了一个函数:-

else if (isset($_POST['update'])) {
//Updates Qty for all items
foreach ($_POST['items_qty'] as $itemID => $qty) {
//If the Qty is "0" remove it from the cart
if ($qty == 0) {
//Remove it from the cart
unset($_SESSION['SHOPPING_CART'][$itemID]);
}
else if($qty >= 1) {
//Update to the new Qty
$_SESSION['SHOPPING_CART'][$itemID]['qty'] = $qty;

}
foreach ($_POST['items_size'] as $itemID => $size) {
//If the Qty is "0" remove it from the cart
if($size >= 1) {
//Update to the new Qty
$_SESSION['SHOPPING_CART'][$itemID]['size'] = $size;

}
}
foreach ($_POST['items_length'] as $itemID => $length) {
//If the Qty is "0" remove it from the cart

//Update to the new Qty
$_SESSION['SHOPPING_CART'][$itemID]['length'] = $length;


}
} 

Here its updating the size and length for each product. I want it for each quantity. For ex if you select 5 quantity customer should be able to select 5 sizes and 5 lengths current can only chose 1 each no matter how big the quantity is.. Maybe this will help you understand

这里它更新每个产品的大小和长度。每个量我都要。对于ex,如果你选择5个数量的客户,应该能够选择5个大小,5个长度的电流只能选择1,不管数量多大。也许这能帮助你理解

1 个解决方案

#1


0  

First of all, you need to store items in session via their id, not via their name or automatically generated index. If name changes, you won't find them in your database. You want to use that id directly in $_SESSION['SHOPPING_CART'][ 'item_id' ] = array(), since that will allow you to quickly find the item and work with it.

首先,您需要通过它们的id在会话中存储项目,而不是通过它们的名称或自动生成的索引。如果名称发生变化,您将无法在数据库中找到它们。您希望在$_SESSION['SHOPPING_CART']['item_id'] = array()中直接使用该id,因为这将允许您快速找到该项并使用它。

Since you have multiple entities of the same item, you need to use more complex array to store them. Simple solution could be as follows:

由于同一项有多个实体,所以需要使用更复杂的数组来存储它们。简单的解决办法如下:

$ITEM = array(
    'name' => $_GET['add'],
    'qty' => $_GET['qty'],
    'price' => $_GET['price'] * $_GET['qty'],
    'size' => array_fill(0, $_GET['qty'], $_GET['size']),
    'length' => array_fill(0, $_GET['qty'], $_GET['length']),
    'code' => $_GET['code']
);
$_SESSION['SHOPPING_CART'][ $_GET['item_id'] ] =  $ITEM;

When user wants to change the data, you create dropdown for every row in size and length arrays and then save them accordingly.

当用户希望更改数据时,您将为每一行创建大小和长度数组的下拉菜单,然后相应地保存它们。

I would, however, suggest storing this data in database with some sort of user_id. In current design, if user closes his browser accidentally or simply comes back when session will expire, his whole order will be lost.

但是,我建议在数据库中使用某种user_id来存储这些数据。在当前的设计中,如果用户不小心关闭浏览器,或者只是在会话过期时返回,那么他的整个订单将丢失。

Edit: working with sizes and lengths.

编辑:处理大小和长度。

foreach ($_SESSION['SHOPPING_CART'] as $item_id => $item)
{
    echo '<p>Name: ' . $item['name'] . ' for ' . $item['price'] . '$</p>';
    foreach($item['size'] as $j => $size)
    {
        echo '<p>#' . $j . ': size ' . $size . ', length ' . $item['length'][$j] . '</p>';
    }
}

Replace echo with inputs for editing and put them into a form.

将echo替换为用于编辑的输入,并将其放入表单。

#1


0  

First of all, you need to store items in session via their id, not via their name or automatically generated index. If name changes, you won't find them in your database. You want to use that id directly in $_SESSION['SHOPPING_CART'][ 'item_id' ] = array(), since that will allow you to quickly find the item and work with it.

首先,您需要通过它们的id在会话中存储项目,而不是通过它们的名称或自动生成的索引。如果名称发生变化,您将无法在数据库中找到它们。您希望在$_SESSION['SHOPPING_CART']['item_id'] = array()中直接使用该id,因为这将允许您快速找到该项并使用它。

Since you have multiple entities of the same item, you need to use more complex array to store them. Simple solution could be as follows:

由于同一项有多个实体,所以需要使用更复杂的数组来存储它们。简单的解决办法如下:

$ITEM = array(
    'name' => $_GET['add'],
    'qty' => $_GET['qty'],
    'price' => $_GET['price'] * $_GET['qty'],
    'size' => array_fill(0, $_GET['qty'], $_GET['size']),
    'length' => array_fill(0, $_GET['qty'], $_GET['length']),
    'code' => $_GET['code']
);
$_SESSION['SHOPPING_CART'][ $_GET['item_id'] ] =  $ITEM;

When user wants to change the data, you create dropdown for every row in size and length arrays and then save them accordingly.

当用户希望更改数据时,您将为每一行创建大小和长度数组的下拉菜单,然后相应地保存它们。

I would, however, suggest storing this data in database with some sort of user_id. In current design, if user closes his browser accidentally or simply comes back when session will expire, his whole order will be lost.

但是,我建议在数据库中使用某种user_id来存储这些数据。在当前的设计中,如果用户不小心关闭浏览器,或者只是在会话过期时返回,那么他的整个订单将丢失。

Edit: working with sizes and lengths.

编辑:处理大小和长度。

foreach ($_SESSION['SHOPPING_CART'] as $item_id => $item)
{
    echo '<p>Name: ' . $item['name'] . ' for ' . $item['price'] . '$</p>';
    foreach($item['size'] as $j => $size)
    {
        echo '<p>#' . $j . ': size ' . $size . ', length ' . $item['length'][$j] . '</p>';
    }
}

Replace echo with inputs for editing and put them into a form.

将echo替换为用于编辑的输入,并将其放入表单。