unimitysolutionspvtltd / basiccart

1 stars 0 forks source link

duplicate storage method for cart items #4

Open alexdicianu opened 8 years ago

alexdicianu commented 8 years ago

On install you create the basiccart_cart table and a CartStorage class for handling it.

You also have public static function add_to_cart which seems to keep the cart items in the user's session.

I would say you're either keeping the data in the database (based on a user session id) or in the user's session cookie ($_SESSION['basiccart']). I suggest the latter for simplicity.

karthikeyan-manivasagam commented 8 years ago

We have option to enable store cart in database when users enable to store cart in table, We will use to retrieve from cart table when users logged in, other wise it will collect data from session.Made it to reduce the number request to database select

alexdicianu commented 8 years ago

So what advantages does it bring to store the cart in the database? In my opinion, it just adds complexity without any obvious advantages (that I can see anyway). You could do it like commerce and make each cart item an entity. This would allow you to use views to build the cart, but would definitely pass the scope of this module which is simplicity.

My suggestion would be to use one or the other; for simplicity I would use sessions.

karthikeyan-manivasagam commented 8 years ago

Its just to persist users cart data even when they logged out and logging in after somedays. Some commerce owner would like to show up the old cart data, thats why we added this feature. We have option in cart settings to enable to data persist after logged out. when they enable it. It will store data in table but it use session data to select and showup through out the site usage. database queries will trigger/work only when they add to cart and remove from cart, when selecting data it will retrieve from session. For anonymous users it will use session at the moment when users logged in it will add session to table and then again it will start use the session as usual. now when the users logs out and logged in again. he will able to see the cart data from table. then we will use session again. These feature will work only if they enable carts persists option in admin settings. We can remove this feature as well.

alexdicianu commented 8 years ago

If you're using it for when the user is authenticated and tries to logout, I see 2 problems:

1) Drupal destroys the user cookie upon logout. Thus any information that identifies user X to cart Y is destroyed. So even if you keep the cart in the database, there's no way to identify the next user that visits your site as user X. 2) Keeping that connection (user X - cart Y) implies overwriting Drupal's behavior of destroying the cookie which can cause different problems (say the logout never happens, third party caching systems like Varnish or Cloudflare that rely on the absence of cookies might fail, etc).

karthikeyan-manivasagam commented 8 years ago

Okay lets make it either or option. when this option enabled in admin/config, we will use database to persist cart data (only for authenticated user). when user added the product to cart (as anonymous) and logging in to the site, it will convert session cart data to database table(old cart data will also persists if they added and not processed early). Is that okay ? or will hold this feature.

karthikeyan-manivasagam commented 8 years ago

Currently we storing cart data in table mapped with user id. each product in a cart would be stored with added user's id.

alexdicianu commented 8 years ago

I still don't see the advantage of having both. You can use one or the other, but 2 systems doing the same thing seems like an overkill. If you like the database approach - use that, but make sure to start a session so that you can identify the user. You can use his $uid if he's logged in.

From a code perspective it's just easier to maintain.