I have a shopping cart. I store the data for it in the Session table
and Users table. Why both? Well, when a user logs out or leaves the
site and his session expires, I want his cart to still be saved. So I
save the cart to both the session and users table upon a modification
and on logging out. Then when the user logs in, I merge any saved cart
in the users table with the cart in the session.

Why not create a separate Carts table? I have my reasons, but mainly
because I don't want to be bothered finding a way to update the
session_id in a Carts table when it changes. Other reasons too...

So what is my design question? Well, I would like to move the junk in
the UsersController relating to the cart out of that controller and
put it somewhere else more relevant. More specifically, the code
saving the cart on logout and the code merging the carts on login.

The problem I am running into is how to move it out...
[1] I could move it to a component (ex., CartComponent) but cake
doesn't want me accessing models from components (e.g., the User
model).
[2] I could move it to a model (ex., CartModel) but cake doesn't want
me accessing the session from models and because there is no
corresponding table, I could not access the necessary Users table.
[3] I could move it to the CartsController, but then I have to bite
the performance hit by calling requestAction (also, this action has
changed so any call to it creates a new session instance which costs 2
database hits, ouch).

I know that there are ways to load model instances, and I know there
are ways to do what cake doesn't want you to do. But this is a simple,
or should I say common, feature in design and it shouldn't be so
difficult to find a solution for...

So what do you guys think? Is there a way to successfully move this
code out while simultaneously respecting cake's design goals?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to