[checkout] Saving multiple carts?

starflower

Joined: 2006-03-29
Posts: 53
Posted: Sat, 2008-11-08 23:25

To Alec or anyone else who can help me-

I was wondering about adding a "save cart" feature to the Checkout module - I am looking to give each user the ability to store and name multiple carts. From the way Checkout handles transactions (creating a new one for each "Continue to Checkout") it seems like this shouldn't be fantastically difficult. Is this something you're planning on doing? If so, do you have an ETA, and would you like any help? If not, would you be willing to give me guidance as to how I might develop this feature? If I'm successful, the code would of course be released back to the project.

-Jake

http://www.starflower-studios.com

 
alecmyers

Joined: 2006-08-01
Posts: 4342
Posted: Sun, 2008-11-09 01:02

My first thought was "no way, vastly too complicated for most users". Then thinking a bit further, I realise it would be quite straightforward to do with an add-on module. Elegant, even. So you could install the feature if you want it, and not if you don't.

Checkout stores the cart contents within the Gallery session data. What an additional module can do is swap the current Checkout data in the session in and out, for different carts. So you would have an addition block to display on album & photo pages, alongside the cart contents, that would say something like: "You are now using your blue cart. You can change which cart you're using here:" and give you a row of links for the red cart, the yellow cart, the green cart etc. Or you could rename them. Whatever. But when you click, the current cart contents are saved (we'll come back to that in a second) and replaced with what was previously stored as the 'red' cart etc.

Where to save the cart contents? You could just move them to another part of the session; but the user's connection with the session contents are somewhat ephemeral - wipe your cookies and that's it, all access to your carts are lost. Not so bad if you only have one, but lose six and you probably won't remember what was in them. So you could store them to another table keyed by user id, but that would depend on having the user logged-in. So swings and roundabouts there.

But I do like the idea of swapping cart contents in and out, and displaying the current cart, and being able to switch to others. And the good news is that it doesn't need any modifications to the checkout module at all, it can all be done in an add-on.

 
starflower

Joined: 2006-03-29
Posts: 53
Posted: Sun, 2008-11-09 01:22

Sounds like a good approach, and something I think I can build with a little help - the first thing I need is a brief explanation of how and where you are storing the relevant data. Places to look at in the current module would also be appreciated. As there is no issue with requiring login for my application (nor, I would think, most others that will need this), I will be storing carts in the database - session data is far too ephemeral.

Thanks,

Jake

http://www.starflower-studios.com

 
alecmyers

Joined: 2006-08-01
Posts: 4342
Posted: Sun, 2008-11-09 14:09

The relevant data is a single array, which gets stored in the session under the key 'checkout.items'. The structure of the array isn't important, as long as you record it faithfully, and restore it, that will suffice. Just serialize it to a string, record it, and recover it by unserializing it, like the Gallery core session code does. (The structure may change in the future - there's already an extra element in the forthcoming version 4.2, and it may change again in the future.) It's also open, in that other modules can alter its structure, add and remove keys etc. So don't rely on anything in particular being in the array.

There is also a checkout.returnURL key that you don't need to store. Also be open to the possibilty that in future there might be a checkout.somethingElse that *does* need to accompany the cart contents. There isn't at the moment, but I might want to move things like the discount code, postage etc, out of the checkout.items key as it's a bit awkward at the moment. Just so you know.

The code to look at is in checkout/classes/CheckoutHelper.class, particularly functions storeItemListInSession($checkoutItems) and fetchCheckoutItems($items = null)

One problem you'll need to solve, if you're tying the whole thing to userId in a new table (suggest Map, not Entity btw) is that whichever cart the user is currently editing *will* be ephemeral, so consider having a "save this cart" function.

Gallery coding guidelines are here: http://codex.gallery2.org/Gallery2:Developer_Guidelines - the coding standards and guidelines are particularly well worth a read.

Good luck - let me know if you want any more help.

 
davidwwatts

Joined: 2007-12-06
Posts: 35
Posted: Tue, 2009-05-05 19:46

Hi Jake, did you make any progress on this? This would be a great addition to the module.
David.

 
alecmyers

Joined: 2006-08-01
Posts: 4342
Posted: Wed, 2009-05-06 07:18

I don't think Jake ever followed up.

 
starflower

Joined: 2006-03-29
Posts: 53
Posted: Wed, 2009-05-06 15:22

Project has been placed on hold by the client.

http://www.starflower-studios.com

 
davidwwatts

Joined: 2007-12-06
Posts: 35
Posted: Sun, 2009-05-10 05:14

So does the capability exist to even save the current cart for later retrieval? My observations are that the cart does get maintained even after the user leaves my web site, but it's not clear how long it stays in the system (browser / web application) or what causes it to be cleared.

David.

 
starflower

Joined: 2006-03-29
Posts: 53
Posted: Sun, 2009-05-10 05:19

It's currently stored in the session data. You can control session lifetime in the site admin.

http://www.starflower-studios.com

 
alecmyers

Joined: 2006-08-01
Posts: 4342
Posted: Sun, 2009-05-10 05:38
Quote:
It's currently stored in the session data

...which is keyed by the cookie. Clear your cookies and it goes. If you use a different browser, too, obviously, you have a different cart contents there.