Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Clearing Shopping Cart on Log Out


Cyz

Recommended Posts

By default oscommerce stores a customers shopping cart on log out... because the items I am trying to sell are one of a kind this option would cause alot of problems for me... Is there a way which I can clear a shopping cart on log out and also Is there a way that I can setup the catalog so that It wont show out of stock Items?

 

Thank you in advance

Link to comment
Share on other sites

  • 1 month later...

It's easy to not show out of stock items - if you mark the item as out of stock in admin - for example, by clicking on the red ball next to its listiing - it won't be shown.

 

Code to clear the customer's cart is as follows:

 

   $reset_query_raw = "delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id=" . $customer_id; 
  tep_db_query($reset_query_raw); 
  $reset_query_raw2 = "delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id=" . $customer_id; 
  tep_db_query($reset_query_raw2);

Insert this in checkout_success.php just before the line:

    tep_redirect(tep_href_link(FILENAME_DEFAULT, $notify_string));

 

Note - I have not tested this, but it should work.

Link to comment
Share on other sites

Yea I'd also like to know how to do this. When they close their browser, the cart empties. Cause I have people coming back and purchasing one thing, not noticing that they have the other products in their cart. Id also love to know how to have it so when people click on new products or specials or whats new products, it goes to that category and not to the products themselves, with that product being first.

 

S

Link to comment
Share on other sites

It's easy to not show out of stock items - if you mark the item as out of stock in admin - for example, by clicking on the red ball next to its listiing - it won't be shown.

 

Code to clear the customer's cart is as follows:

 

   $reset_query_raw = "delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id=" . $customer_id; 
  tep_db_query($reset_query_raw); 
  $reset_query_raw2 = "delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id=" . $customer_id; 
  tep_db_query($reset_query_raw2);

Insert this in checkout_success.php just before the line:

    tep_redirect(tep_href_link(FILENAME_DEFAULT, $notify_string));

 

Note - I have not tested this, but it should work.

 

 

I don't understand this, if you are on checkout success, the cart items are ordered for that customer and emptied. So what is the point of emptying them again.

Treasurer MFC

Link to comment
Share on other sites

I don't understand this, if you are on checkout success, the cart items are ordered for that customer and emptied. So what is the point of emptying them again.

 

 

I would combine it with the who's online code.

If you delete customers from those tables, also delete their shopping cart and attribute entries.

Treasurer MFC

Link to comment
Share on other sites

I would combine it with the who's online code.

If you delete customers from those tables, also delete their shopping cart and attribute entries.

 

Then again, the problem will not go away because 2 customers can add it to their cart and go to checkout.

 

So the only solid solution would be to check the product status of all products in their cart when going to checkout and again when the customers presses confirm order.

Treasurer MFC

Link to comment
Share on other sites

???

Products clear once you have ordered.

 

I think he wants, and so do I, the shopping cart to empty when they leave. To get more crazy, maybe have it setup to clear if they return after 1 day or something instead of as soon as they close their browser. But I'd settle with it just clearing when they close their browser, purchased or not.

 

S

Link to comment
Share on other sites

???

Products clear once you have ordered.

 

I think he wants, and so do I, the shopping cart to empty when they leave.  To get more crazy, maybe have it setup to clear if they return after 1 day or something instead of as soon as they close their browser.  But I'd settle with it just clearing when they close their browser, purchased or not.

 

S

 

 

that does not solve the problem of unique items being ordered by 2 different customers.

Treasurer MFC

Link to comment
Share on other sites

I apologize - I should take care when reading posts early in the morning that I understand what is written. The code I presented, while it does empty the cart, is rather useless where i suggested to put it.

 

I guess what you really want here is for the cart to not be associated with the user's login and to remain active only for the current session. An alternative, which I suppose is easier, is on subsequent login to NOT merge the saved cart, if any, but to delete it then. I don't know of an easy way to get rid of the cart when the user simply leaves the site for somewhere else.

Link to comment
Share on other sites

here's how I did it...seems to work okay...this deletes all carts that were created before the current day...cleans out both the customers_basket and customers_basket_attributes tables...runs the process everytime someone logs in....

 

 

in catalog/login.php add the following just below line 56 (which is the comment "// restore cart contents"):

 

$cart_customers_query = tep_db_query("select customers_id from " . TABLE_CUSTOMERS_BASKET . " where customers_basket_date_added != " . date('Ymd'));

 

while ($cart_customers_ids = tep_db_fetch_array($cart_customers_query)) {

tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where

customers_id = " . $cart_customers_ids['customers_id']);

}

 

tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where

customers_basket_date_added < " . date('Ymd'));

Link to comment
Share on other sites

By default oscommerce stores a customers shopping cart on log out... because the items I am trying to sell are one of a kind this option would cause alot of problems for me...  Is there a way which I can clear a shopping cart on log out and also Is there a way that I can setup the catalog so that It wont show out of stock Items?

 

Thank you in advance

 

I sell one of a kind stock also and I don't see the problem (might be the New Years lag :D ). If a registered customer leaves without ordering and with items in his basket they are indeed saved but the next customer can just order them like the previous one. The only caveat I see is that if the first customer returns he might find one or more of his selected items already sold. Why should I go through the fuzz of deleting carts for this ?

Next time the first customer should be wiser and order immediately so he/she won't have the risk of something sold while thinking about a purchase. If they explicitly ask me for a short period to think about it I will reserve the item and put stock to zero for the time being.

 

Happy New Year !

Link to comment
Share on other sites

I sell one of a kind stock also and I don't see the problem (might be the New Years lag  :D ). If a registered customer leaves without ordering and with items in his basket  they are indeed saved but the next customer can just order them like the previous one. The only caveat I see is that if the first customer returns he might find one or more of his selected items already sold. Why should I go through the fuzz of deleting carts for this ?

Next time the first customer should be wiser and order immediately so he/she won't have the risk of something sold while thinking about a purchase. If they explicitly ask me for a short period to think about it I will reserve the item and put stock to zero for the time being.

 

Happy New Year !

 

 

even more, if two customers are logged in and put the same unique item in their cart and proceed to checkout, the problem remains, deleting carts or not. As said, it can only be automated if you check remaining stock when the customer confirms the order.

Treasurer MFC

Link to comment
Share on other sites

  • 10 months later...
even more, if two customers are logged in and put the same unique item in their cart and proceed to checkout, the problem remains, deleting carts or not. As said, it can only be automated if you check remaining stock when the customer confirms the order.

 

The problem as Boxtel explains it is exactly what I want to avoid.

I understand what Boxtel is saying. Problem is that I have no idea how to do it. So any help would be appreciated.

 

I?m a cut and paste guy so I would appreciate if someone could explain with code.

 

Thanks in advance

 

/Per

Link to comment
Share on other sites

The problem as Boxtel explains it is exactly what I want to avoid.

I understand what Boxtel is saying. Problem is that I have no idea how to do it. So any help would be appreciated.

 

I?m a cut and paste guy so I would appreciate if someone could explain with code.

 

Thanks in advance

 

/Per

 

well,

 

the problem would not happen often as it only occurs when 2 people add the same unique item to their cart before checking out. At that time they both see the same stock level as being 1.

Then they can both order that item leaving you the choice who gets it and clean up the mess.

One solution would be to make the carts table based so you could check if the item is already in someone elses cart before adding it but that would create the problem that as long as someone has it in its cart, noone can order it.

 

so I guess the best way is to introduce a last minute check during checkout confirmation whether the items in their cart are still in stock at that time. If not, give a message that someone has beaten them to the finish line for these unique products and remove the items from their cart with your sincerest apology.

Treasurer MFC

Link to comment
Share on other sites

well,

 

the problem would not happen often as it only occurs when 2 people add the same unique item to their cart before checking out. At that time they both see the same stock level as being 1.

Then they can both order that item leaving you the choice who gets it and clean up the mess.

One solution would be to make the carts table based so you could check if the item is already in someone elses cart before adding it but that would create the problem that as long as someone has it in its cart, noone can order it.

 

so I guess the best way is to introduce a last minute check during checkout confirmation whether the items in their cart are still in stock at that time. If not, give a message that someone has beaten them to the finish line for these unique products and remove the items from their cart with your sincerest apology.

 

Thanks for your reply Amanda!

It?s the later part of your answear I wanna achieve. I would like to check the stock when the customer clicks the confirm button. If the item is out of stock the customer gets redirected back to the shopping cart with the regular *** to show that an item is out of stock. I can just change the message text to something like you suggested.

 

But... how do I code this and where do I put the code?

 

I tried adding something like this to the checkout_confirmation.php

if ( ($stock_left < 1) && (STOCK_ALLOW_CHECKOUT == 'false') ) {

 

but it didn?t seam to work. I?m like I said before just a cut and paste guy. :blush:

 

Hoping for your help with this since it?s one of the last things left for me to fix before I can go live.

 

Thanks in advance

 

Per

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...