You are here: Re: Shopping Cart Program « All PHP « IT news, forums, messages
Re: Shopping Cart Program

Posted by Christa Lee on 09/29/05 06:11

So I would still have to ask you this question: How do you register and
array in a session?


$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" <jmelnick@jphp.com> wrote in message
news:qPidnXsFocDQvqrenZ2dnUVZ_tOdnZ2d@rogers.com...
> Crista Wrote:
> "Christa Lee" <Ck.lee@telus.net> wrote in message
> news:mHDZe.190667$wr.164531@clgrps12...
>> 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?
>>
>> Thanks,
>> D
>>
>> "Geoff Berrow" <blthecat@ckdog.co.uk> wrote in message
>> news:ouncj19u48ajg0n9eilkrtkps14ji8v1gf@4ax.com...
>>>I noticed that Message-ID: <XJpZe.269622$HI.141531@edtnps84> from
>>> Christa Lee contained the following:
>>>
>>>>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
>>
>>
>
> 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
>
>
>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация