Php Shopping cart - Tamanho e comprimento para cada quantidade de um tipo de produto

Eu tenho trabalhado em uma loja online. O objetivo do projeto é adicionar produtos a um carrinho de compras. O cliente deve poder alterar o tamanho e o tamanho de cada quantidade para um produto. Exemplo:

Eu vendo um produto chamado Apedido do cliente 5 peças do produto AEntão ele deve ser capaz de definir 5 tamanhos e comprimentos para o produto A, pois a quantidade é 5.

Então o TCPDF também está lá para enviar a fatura criada por e-mail.

Eu só quero alguma ajuda com a configuração de tamanhos e comprimento para cada quantidade. Por favor, por favor me ajude ..

Além disso, se o seu possível por favor me ajude com a adição desses comprimentos e tamanhos para o pdf criado que está sob a função sendmail

A seguir está o código que escrevi até agora ...

<?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 : '.'

Eu tentei fazê-lo através da criação de outra sessão, mas não consigo fazê-lo sozinho.

Eu queria fazer como ... quando você vai mudar a quantidade para 5 ... então deve aparecer 5 dropdowns para o tamanho e 5 para o comprimento. Eu poderia fazer os dropdowns, mas não consegui armazenar o valor selecionado na sessão.

Qualquer ajuda é apreciada.

Para ajudar a explicar isso, existe uma sessão chamada Carrinho de compras. Agora que tem itens de matriz como quantidade de tamanho de preço etc. Agora há uma função: -

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;


}
} 

Aqui está atualizando o tamanho e o comprimento de cada produto. Eu quero isso para cada quantidade. Por ex, se você selecionar 5 quantidade de clientes deve ser capaz de selecionar 5 tamanhos e 5 comprimentos atual só pode escolher 1 cada, não importa quão grande é a quantidade .. Talvez isso ajude você a entender

.$totamt; $tot2='VAT Total : '.'

Eu tentei fazê-lo através da criação de outra sessão, mas não consigo fazê-lo sozinho.

Eu queria fazer como ... quando você vai mudar a quantidade para 5 ... então deve aparecer 5 dropdowns para o tamanho e 5 para o comprimento. Eu poderia fazer os dropdowns, mas não consegui armazenar o valor selecionado na sessão.

Qualquer ajuda é apreciada.

Para ajudar a explicar isso, existe uma sessão chamada Carrinho de compras. Agora que tem itens de matriz como quantidade de tamanho de preço etc. Agora há uma função: -

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;


}
} 

Aqui está atualizando o tamanho e o comprimento de cada produto. Eu quero isso para cada quantidade. Por ex, se você selecionar 5 quantidade de clientes deve ser capaz de selecionar 5 tamanhos e 5 comprimentos atual só pode escolher 1 cada, não importa quão grande é a quantidade .. Talvez isso ajude você a entender

.$vat; $tot5='TOTAL : '.'

Eu tentei fazê-lo através da criação de outra sessão, mas não consigo fazê-lo sozinho.

Eu queria fazer como ... quando você vai mudar a quantidade para 5 ... então deve aparecer 5 dropdowns para o tamanho e 5 para o comprimento. Eu poderia fazer os dropdowns, mas não consegui armazenar o valor selecionado na sessão.

Qualquer ajuda é apreciada.

Para ajudar a explicar isso, existe uma sessão chamada Carrinho de compras. Agora que tem itens de matriz como quantidade de tamanho de preço etc. Agora há uma função: -

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;


}
} 

Aqui está atualizando o tamanho e o comprimento de cada produto. Eu quero isso para cada quantidade. Por ex, se você selecionar 5 quantidade de clientes deve ser capaz de selecionar 5 tamanhos e 5 comprimentos atual só pode escolher 1 cada, não importa quão grande é a quantidade .. Talvez isso ajude você a entender

.$final; $tot3='Payments/Credits : $0.00'; $tot4='Balance Due : '.'

Eu tentei fazê-lo através da criação de outra sessão, mas não consigo fazê-lo sozinho.

Eu queria fazer como ... quando você vai mudar a quantidade para 5 ... então deve aparecer 5 dropdowns para o tamanho e 5 para o comprimento. Eu poderia fazer os dropdowns, mas não consegui armazenar o valor selecionado na sessão.

Qualquer ajuda é apreciada.

Para ajudar a explicar isso, existe uma sessão chamada Carrinho de compras. Agora que tem itens de matriz como quantidade de tamanho de preço etc. Agora há uma função: -

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;


}
} 

Aqui está atualizando o tamanho e o comprimento de cada produto. Eu quero isso para cada quantidade. Por ex, se você selecionar 5 quantidade de clientes deve ser capaz de selecionar 5 tamanhos e 5 comprimentos atual só pode escolher 1 cada, não importa quão grande é a quantidade .. Talvez isso ajude você a entender

.$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>

Eu tentei fazê-lo através da criação de outra sessão, mas não consigo fazê-lo sozinho.

Eu queria fazer como ... quando você vai mudar a quantidade para 5 ... então deve aparecer 5 dropdowns para o tamanho e 5 para o comprimento. Eu poderia fazer os dropdowns, mas não consegui armazenar o valor selecionado na sessão.

Qualquer ajuda é apreciada.

Para ajudar a explicar isso, existe uma sessão chamada Carrinho de compras. Agora que tem itens de matriz como quantidade de tamanho de preço etc. Agora há uma função: -

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;


}
} 

Aqui está atualizando o tamanho e o comprimento de cada produto. Eu quero isso para cada quantidade. Por ex, se você selecionar 5 quantidade de clientes deve ser capaz de selecionar 5 tamanhos e 5 comprimentos atual só pode escolher 1 cada, não importa quão grande é a quantidade .. Talvez isso ajude você a entender

questionAnswers(1)

yourAnswerToTheQuestion