When a user adds a product to the cart, the Drupal e-commerce project uses a database table (ec_cart) for this, but looking at the sessions table, I see the following serialized data in the session-column:

form|a:6:{s:32:"6dc59b09841cbf352fcb5669e74d3e88";a:2:{s:9:"timestamp";i:1224167714;s:4:"args";a:1:{i:0;s:14:
"system_modules";}}s:32:"176eb31a60a35c8d9a87f333de3c1775";a:2:{s:9:"timestamp";i:1224168124;s:4:"args";a:1
:{i:0;s:14:"system_modules";}}s:32:"2ae6390e331141ad4ca1aa2ef86b6977";a:2:{s:9:"timestamp";i:1224168181;s:4
:"args";a:1:{i:0;s:14:"system_modules";}}s:32:"ee2b99e2873fa5d91c2b32430b8129c5";a:2:{s:9:"timestamp";i:1224
168271;s:4:"args";a:1:{i:0;s:14:"system_modules";}}s:32:"825fef6cafc93f08b85b6953e6ed9c77";a:2:{s:9:"timestam
p";i:1224168831;s:4:"args";a:3:{i:0;s:14:"tax_admin_form";i:1;i:0;i:2;a:5:{s:5:"realm";s:7:"country";s:2:"op";s:4:"N
ext";s:13:"form_build_id";s:32:"cec0efe486aa3ea46facda1753c4d843";s:10:"form_token";s:32:"5c9909272a072ad443
cdf38841fa4431";s:7:"form_id";s:14:"tax_admin_form";}}}s:32:"ca63e4cd715e895bef761fff1b2e308e";a:2:{s:9:"time
stamp";i:1224168900;s:4:"args";a:2:{i:0;s:30:"store_transactions_search_form";i:1;a:2:{s:6:"status";s:3:"1,7";s:8:"
workflow";s:7:"1,2,3,4";}}}}node_overview_filter|a:0:{}

I've just started to look at the inner workings of Drupal, and noticed that session data is stored serialized in the sessions.session table. Why does the e-commerce module store cart-data (which is also session-related) in a seperate table?

Comments

gordon’s picture

Status: Active » Fixed

This is actually form data which is placed there by the form api. It really don't have much to do with ecommerce.

mfb’s picture

Cart data should outlive the session so it can be accessible to a user next time they login.

Fluffy Convict’s picture

Ok, thanks for explaining where the data comes from. I think that if I take a good look at the forms API, I could figure out exactly what this data represents and why it is stored in the session table.

But again, why does the e-commerce module store cart-data in a seperate table instead of using the sessions.session-datafield that's already in the database? If the forms API uses it to store info, then any module could, but no other module actually does. Why not?

gordon’s picture

Actually there are a couple of historical reasons.

1. is that the cart can last longer than the session.
2. session didn't use to be saved for anonymous users. They are now.
3. There is less over head in storing the cart in it's own tables compared to storing in session which is selected and updated everytime the page is loaded.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.