Re: [PHP] Re: Creating an OO Shopping Cart

2006-04-21 Thread Richard Lynch
On Fri, April 21, 2006 12:21 am, Steve wrote:
> So basically, on every page, be it a page that displays the contents
> of
> the cart, the checkout, or catalog pages, at the top of the code I
> always need to check if files are being added, deleted or changed qty.
> Is this correct?

Yes.

> This is my biggest concern. What's the best way to interact with the
> Cart class when adding/removing items?

Just include Cart.php which does all that.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Creating an OO Shopping Cart

2006-04-21 Thread Martin Alterisio
You don't need the unserialize(), it's done internally by the
session_start().
All the things you put inside $_SESSION, except for resources, will be
rebuilt when the session is regenerated. This way you don't need to worry
about serializing.
Read the manual section about sessions.

2006/4/21, Steve <[EMAIL PROTECTED]>:
>
> Hi
>
> Thanks for all your help so far.
>
> I've combined all your thoughts, and from what I understand, for every
> page I have that interacts with the cart, I need to have something like
> the following code.
>
> So basically, on every page, be it a page that displays the contents of
> the cart, the checkout, or catalog pages, at the top of the code I
> always need to check if files are being added, deleted or changed qty.
> Is this correct?
>
> This is my biggest concern. What's the best way to interact with the
> Cart class when adding/removing items?
>
> Thanks
> Steve
>
>
> 
> // This File: catalog.php
> require_once 'Cart.php';
> session_start();
>
> /* Establish connection to the cart
>  */
> if ( isset($_SESSION["cart"] )
> $cart = unserialize($_SESSION["cart"]);
> else
> $cart = new Cart();
>
> /* Modify the cart for this user
>  */
> if ( isset($_GET['add']) )
> $cart->addItem($_GET['add']);
> if ( isset($_GET['remove']) )
> $cart->removeItem($_GET['remove']);
>
> /* Save the cart's state
>  */
> $_SESSION['cart'] = $cart;
>
> /* Display the catalog
>  */
> echo << blah blah
> HEREDOCS;
>
> ?>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


[PHP] Re: Creating an OO Shopping Cart

2006-04-20 Thread Steve

Hi

Thanks for all your help so far.

I've combined all your thoughts, and from what I understand, for every 
page I have that interacts with the cart, I need to have something like 
the following code.


So basically, on every page, be it a page that displays the contents of 
the cart, the checkout, or catalog pages, at the top of the code I 
always need to check if files are being added, deleted or changed qty. 
Is this correct?


This is my biggest concern. What's the best way to interact with the 
Cart class when adding/removing items?


Thanks
Steve


addItem($_GET['add']);
if ( isset($_GET['remove']) )
   $cart->removeItem($_GET['remove']);

/* Save the cart's state
 */
$_SESSION['cart'] = $cart;

/* Display the catalog
 */
echo <<

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php