First, if you look at the web site, I need to be able to register a number
of values for one variable (array). So I guess my question is this: how do
you register an array?
This is my code so far:
<?php
session_start();
include("getup.php");
$_POST['Quantity,Size,Colour,Style,BrandName'];
$connection = mysql_connect($host, $user, $dbpassword)
or die ("Couldn't connect to server.");
$db = mysql_select_db($database, $connection)
or die ("Couldn't select databse.");
session_register('$itemcount');
$itemcount++;
$tempslot = $itemcount .= "item";
$tempslot = array ( "Style" => "$Style" , "Brand" => "$BrandName" ,
"Colour" => "$Colour" , "Size" => "$Size" ,
"Quantity" => "$Quantity" );
session_register('$tempslot');
header("Location: index.php?page=shoppingcart");
?>
If someone can tell me where I'm going wrong or if someone has an example
shopping cart for a clothing web site, please HELP ME!
I would really like to have this web site ready to go by October and the
shopping cart is the biggest obstacle I have to tackle as I have never
created a shopping cart using any programming language. I am decently versed
in PHP but the shopping cart is new to me.
Thanks in advance!
Dimitri Marshall
www.dmwebproductions.com/toque
(soon to be www.toquewear.com)
>If someone can tell me where I'm going wrong or if someone has an example
>shopping cart for a clothing web site, please HELP ME!
The only thing you really need to store is the quantity and the product
id Everything else can come from the database. I've just done one
(literally, last week ) and I stored the price as well so that I could
have a running total. From an individual item page I have an add to
cart button and a text box to choose the quantity. The product id comes
from the URL. So when the form is submitted:
session_start();
if(isset($_POST['qty'])){
$_SESSION['quantity'][$_GET['product_id']]=$_POST['qty'];
$_SESSION['price'][$_GET['product_id']=$_POST['price'];
}
Then there is a link to a cart page which shows the contents of the cart
I need to create a query that will fetch back the relevant rows
foreach($_SESSION['quantity'] as $key=>$value)
{
$cartitems[]="product_id = $key";
}
$q=implode(" or ",$cartitems);
$sql="SELECT * FROM products where $q";
...
I then loop through the results ans show the products. Each one has a
form with a text box showing the quantity, and two buttons, change and
delete. At the top of the file I have:
if(isset($_POST['change'])){
$_SESSION['quantity'][$_POST[$prodkey]]=$_POST['qty'];
}
if(isset($_POST['delete'])||$_POST['qty']<1){
unset($_SESSION['quantity'][$_POST[$prodkey]]);
}
Then you just need a bit of code to do the calculations
$qty=0;
$total_cost=0;
foreach($_SESSION['quantity'] as $pid=>$no){
$qty=$qty+$no;
$total_cost=$total_cost+($no*$_SESSION['price'][$pid]);
}
Obviously there is a bit more code than this, to check there is anything
in the cart for instance, but there you have the basics.
This site is a work in progress, but you can check it out here
www.playhifi.com
--
Geoff Berrow 0110001001101100010000000110
001101101011011001000110111101100111001011
100110001101101111001011100111010101101011
Thanks,
D
"Geoff Berrow" <blth...@ckdog.co.uk> wrote in message
news:ouncj19u48ajg0n9e...@4ax.com...
A product with optional components (size,colour) can be handled a number of
ways.
If a person adds an optioned product to their cart you need to maintain the
option to product association.
When a person adds an optioned product to their cart in my ecommerce system
they are posting a dynamically generated form which contains the following
Keys and their values:
ACTION,ID, CODE, PRICE, NAME, DESCRIPTION, QUANTITY, COLOUR and SIZE.
First I check to see if the cleint has already added this product to their
cart.
If true do the options match
if yes then increment quantity with the number being added to the cart
else
add this product to the cart with is unique options (1, SW01, 10.00,
Sweater, A Fabulous Sweater, Size=L, Colour=Red)
else
add this product to the cart with is unique options (1, SW01, 10.00,
Sweater, A Fabulous Sweater, Size=L, Colour=Red)
Same logic for modifying quantities in the shopping cart.
if match code AND options
change quantity
if quantity requested is zero(0)
delete item from cart
in your case you have ID and QUANTITY so you need to pass OPTIONS as well
SIZE and COLOUR.
then:
Things to be handled:
1, option exists for product.
2, each option type for given product is satisfied.
(0 options none selected, 1 option type and 1 selection of type, 2 option
types and 2 selections one of each type)
3a, add to cart if unique product and options
3b, update cart if added product matches existing cart item
I do hope that I have given you some insight into the logic required to
allow products with options for your website. I could write a book on this
very topic especially ecommerce system processes with payment gateway
integrations.
Joseph Melnick
JM Web Consultants
Toronto, ON Canada
>Hi there,
>thanks for the response. It looks like it might work for me but will it work
>for a product where I need to store the size, colour and quantity? For
>example, what if someone orders a large blue sweater and then the same
>sweater except also in green and XL?
Why not?
if(isset($_POST['qty'])){
$_SESSION['quantity'][$_GET['product_id']]=$_POST['qty'];
$_SESSION['price'][$_GET['product_id']=$_POST['price'];
$_SESSION['colour'][$_GET['product_id']]=$_POST['colour'];
$_SESSION['size'][$_GET['product_id']=$_POST['size'];
...
$tempslot = array ( "Style" => "$Style" , "Brand" => "$BrandName" , "Colour"
=> "$Colour" , "Size" => "$Size" ,
"Quantity" => "$Quantity" );
session_register('$tempslot');
is that wrong somehow?
Thanks again in advance.
Dimitri Marshall
"Joseph Melnick" <jmel...@jphp.com> wrote in message
news:qPidnXsFocDQvqre...@rogers.com...
>$tempslot = array ( "Style" => "$Style" , "Brand" => "$BrandName" , "Colour"
>=> "$Colour" , "Size" => "$Size" ,
> "Quantity" => "$Quantity" );
>
> session_register('$tempslot');
How about
$_SESSION['tempslot ']= array ( "Style" => "$Style" , "Brand" =>
"$BrandName" , "Colour" => "$Colour" , "Size" => "$Size" ,
"Quantity" => "$Quantity" );
--
D
"Geoff Berrow" <blth...@ckdog.co.uk> wrote in message
news:u12nj1p8aeqe9snc0...@4ax.com...