Php Shopping cart with Products length and size for each quantity

I Have a shopping cart on page order.php. Its a retail section for a company so that the stores can purchase dresses from that online section. So there are multiple dresses and people can chose any number of dresses. Furthermore on that shopping script there is a place to change the size and length of dresses.

Currently when you order a dress you can select single size and single length per order Ex : IF you order 4 Quantity of dress A you can select only one size and length for that dress A.

Now all i want to implement is When you order 4 quantity of dress A, you should be able to choose length and size for each quantity of Dress A means 4 Lengths and 4 Sizes. Maybe this sounds weird but that something i need very desperately

Following is the code :

Session Initialization

[php]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’ => array_fill(0, $_GET[‘qty’], $_GET[‘size’]),

'length' => array_fill(0, $_GET['qty'], $_GET['length']),

‘code’ => $_GET[‘code’]
);[/php]

Part which is supposed to update and store the values of quantity, size and length.

[php]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;

}[/php]

Thirdly the part that is supposed to display the values :

[php]<?php
//Print all the items in the shopping cart
foreach ($_SESSION[‘SHOPPING_CART’] as $itemNumber => $item) {
?>

remove <?php echo $item['name']; ?> <?php echo $item['price']; ?> <?php echo $item['qty'] * $item['price']; ?> <?php echo $item['size']; ?> 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 <?php foreach ($_SESSION['SHOPPING_CART'] as $item_id => $item) { echo '

Name: ' . $item['name'] . ' for ' . $item['price'] . '$

'; foreach($item['size'] as $j => $size) { echo '

#' . $j . ': size ' . $size . ', length ' . $item['length'][$j] . '

'; } } ?> <?php $order=strtotime("now");

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

?>

<?php echo $item['length']; ?> 46 48 50 <?php } ?>[/php]

This part was suggested to me by one of the forum member.

Also after adding the following lines to item array (1st section)

[php]‘size’ => array_fill(0, $_GET[‘qty’], $_GET[‘size’]),

'length' => array_fill(0, $_GET['qty'], $_GET['length']),[/php]

When i press update button after changing the quantity it doesnt update… It stays at one…

Now i really dont know or understand where to add what code. I am confused. Please help me

Sponsor our Newsletter | Privacy Policy | Terms of Service