Post by cgcaudle » Wed Feb 25, 2009 12:53 pm

Well, I was using the older version and I had the same issue. I tried to upgrade to v1.1.8 to see if the problem was solved and it is not. :'(

Example:
You have 1 item left of product 'A'. Two new customers find your product at the same time. Both are going through the registration process at the same time. One checks out first and gets a confirmation of sale notice. The second checks out (when stock should be 0) and also gets a confirmation of sale notice.

This is not a problem when you have 1 item of product 'A' left, one person checks out completely and the order is processed, then a second customer tries to purchase the product. The second customer always gets denied and is told the item is out of stock. The problem is when more than one person is checking out at once.

I WILL be having this problem because I will be selling a specific amount of product for a specific period of time. So, I WILL have more than one person checking out at once. The problem is when I have 4 items left and 20 people just got off work and heard my radio add for my products and opencart will sell 20 products when only 4 are available. Granted, this is an extreme hypothetical, but I have tested it with 3 people and one item left and we all get confirmation notices. When we do it separately, only one gets the confirmation and the other two are denied access.

Possible solution:
Is there any way to have opencart confirm the stock levels available on the last checkout page of the shopping cart, when it asks you to confirm your order? Even if I have 10 customers that get denied the product after filling out their personal info, it's better than 10 customers getting phone calls from me (if they provided their real number) telling them I will be giving their money back and my website lied to them. I know basic html (been away from computers for years) but do not know enough to program the final checkout button to confirm stock levels before final confirmation of a sale. This would save me a lot of trouble, and I actually have yet to find a piece of software that does this. I have been testing software constantly to see if it provides this feature.

PLEASE HELP! It seems like an easy solution. Is there anyone out there who can attempt this? Any help would be much appreciated!

Thanks

Newbie

Posts

Joined
Tue Feb 24, 2009 6:03 am

Post by Daniel » Wed Feb 25, 2009 6:31 pm

This is very hard to do.

Some one could fill their basket up with all your products to their max quanitiy and goto the checkout page.

This means you would not be able to sell anything.

User avatar
Administrator

Posts

Joined
Fri Nov 03, 2006 6:57 pm

Post by liquidpele » Wed Feb 25, 2009 9:38 pm

This is actually a pretty big problem - a busy site might have 3 people trying to buy the same thing at the same time! The answer is: Just have the database handle it for you.

Make the table you track the carts/stock with InnoDB instead of myISAM. Then track the cart/stock in that table and use table locks to verify things if you're verifying and then updating the table. The performance doesn't matter if the only thing using the locking table are people with carts because you're not going to have 200 people checking out and refreshing at the same time and having good concurrency is more important.

New member

Posts

Joined
Mon Feb 23, 2009 11:58 pm

Post by cgcaudle » Wed Feb 25, 2009 10:56 pm

Daniel wrote:This is very hard to do.

Some one could fill their basket up with all your products to their max quanitiy and goto the checkout page.

This means you would not be able to sell anything.
I'm not familiar with the DB functions that liquidpele told me about (I sent you a PM on that matter), but couldn't a simple code be created that says> When clicking confirm checkout button, put products in cart IF-products selected are available, IF some products not available send message to not confirm order.

With my product it really won't be an issue of one person buying out my store, it would be an issue of multiple people buying out my stock and going into negative stock when it is not available. I will be selling only a specific amount of items that my clients will allow me to sell, no more.

A prefect example is from a post I read on another forum. He said he sells concert tickets. When he buys 50 at face value and charges his after market price he sells 75 when only 50 are available. Then he has to refund 25 customers who thought they had tickets to their favorite artist....who will never return to his store to buy tickets.

I will not be selling concert tickets, but the idea is similar. Even if the code was update so you have the OPTION to decide whether or not you can limit your customers to buy negative stock it would be a HUGE HELP!

Newbie

Posts

Joined
Tue Feb 24, 2009 6:03 am

Post by CChris » Fri Feb 27, 2009 2:10 pm

Hi!

Go to your Admin-Panel and then just set this Option to No:

Stock Checkout:
Allow customers to still checkout if the products they are ordering is not in stock.

You can find it under "admin/index.php?route=setting/setting"

New member

Posts

Joined
Tue Feb 10, 2009 8:36 am

Post by liquidpele » Fri Feb 27, 2009 9:44 pm

CChris wrote: Stock Checkout:
Allow customers to still checkout if the products they are ordering is not in stock.

You can find it under "admin/index.php?route=setting/setting"
I think that is the opposite of what he wanted. From what I read, it sounds like his example was concert tickets. Lets say you have 30 tickets and you can *not* get any more. The stock going negative for any reason would be very bad.

New member

Posts

Joined
Mon Feb 23, 2009 11:58 pm

Post by Qphoria » Sat Feb 28, 2009 1:26 am

liquidpele wrote:
CChris wrote: Stock Checkout:
Allow customers to still checkout if the products they are ordering is not in stock.

You can find it under "admin/index.php?route=setting/setting"
I think that is the opposite of what he wanted. From what I read, it sounds like his example was concert tickets. Lets say you have 30 tickets and you can *not* get any more. The stock going negative for any reason would be very bad.
Well concert ticket sites usually "hold" tickets for you after selection for a finite period of time. So essentially it removes them from the stock while they are in your cart during the "working time period". After which, if you don't check out, they return to stock.

So you could do it where the stock is removed when its added to a cart, and then have the session timer to clear the cart and return the stock after some amount of time

User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by liquidpele » Sat Feb 28, 2009 1:48 am

Well, you can track stock one of two ways:

1) Like you said, subtract it from stock when you put it into, or update, the cart. This would work

2) Allow them to put it into the cart, but do not subtract it out of the stock until they purchase the item. This is ideal in my opinion as you don't have items stuck in carts until a timeout which is probably 30 minutes or longer depending on the php settings.

Either way though, to enforce items that have a set amount of stock, you have to add in a mutex somewhere so that two shoppers can't effectively take away from the cart at the same time**. To do that, you can use a mysql table lock, or use tricks like "update products set stock=stock-$num where stock>=$num and productid=$id" and then check affected rows to ensure it updated it (updates automatically do row-lock minimum).

** If you've never worked with a mutex and threads, basically imagine 2 people that click "buy" at the same time, so both apache forks then run the update statement "update products set stock=stock-1 where productid=1" on the database at the same time. If there was only 1 left in stock, they both think they got that one and you end up with a -1 stock.

New member

Posts

Joined
Mon Feb 23, 2009 11:58 pm

Post by nde » Sat Feb 28, 2009 10:23 am

I agree, I think it's highly unlikely that two customers click the final checkout button at the same millisecond. So I'd suggest to check the stock on the last step, then just in case display that a given product has been sold out meanwhile.

nde
New member

Posts

Joined
Sat Jun 30, 2007 7:32 am

Post by cgcaudle » Sat Feb 28, 2009 12:52 pm

CChris wrote:Hi!

Go to your Admin-Panel and then just set this Option to No:

Stock Checkout:
Allow customers to still checkout if the products they are ordering is not in stock.

You can find it under "admin/index.php?route=setting/setting"
Thanks, but this option is already selected. The problem is when 2 people checkout at the same time.

nde-It's not that 2 people click on the same checkout button at the same exact time. The example (which I have done with three people to confirm the bug) is when 2 new customers find the same product at relatively the same time. So, at 8:01 John Doe clicks on buy product. He now has to enter registration information to create his account. By this time it's 8:03 and Sam Smith clicks on on the same product John Doe did 2 minutes prior. As Sam Smith begins entering his information, John Doe is doing to final checkout process and gets an order confirmation at 8:04. Sam smith finishes his data entry and gets a final sale confirmation at 8:06. The whole process was started by 2 people minutes apart from each other, but because they were going through a several minute process (which could be narrowed down to 30 seconds, I'm just using minutes as an example) they both received a confirmation letter for their purchases. The problem? Only 1 product was in stock. When I go to look at the product status it shows -1 in my inventory....and yes, even after checking the "NO, do not allow customers to check out when no stock is available." The system works just fine if Sam Smith began his checkout 'process' after John Doe received his order confirmation.

Why is this a big deal? Because I will be selling a product of a limited quantity (50 for example) for a specific period of time (3 days for example). I will be advertising on prime radio time and will be waiting for the masses to hit my site to check out my catalog of 25 products, which all have varying times they will be sold. So product 'A' will have 50 in stock and will be on sale from Mon thru Wed. My customers hear the radio ad during the course of the previous week and all wait for my items to be sold on Mon-Wed. Well, if/when Product 'A' sells out and 100 customers attack my site...there's a good chance that OpenCart will over sell my product since it allows negative stock. BAD!!! Now I have to return customer money as I only accept credit cards/paypal. I am selling products that are specific to my region and will be in high demand. So, creating a limited number and limited time....I can set my price where I want and people will pay.

If OpenCart does not remedy this I will be moving on to test the next piece of software. It's getting old and I'm getting to the point where I will probably pay someone to do this because I have yet to find a shopping cart program that actually does this function.....which I would have figured would be a foundation block of shopping carts in general. </rant>

Newbie

Posts

Joined
Tue Feb 24, 2009 6:03 am

Post by Qphoria » Sat Feb 28, 2009 3:59 pm

There is nothing to remedy. This is not an opencart issue.. This is an uncommon feature that you'd need to code for. Just like ticket sites use a custom type of cart for their "timed" sales, you'd need to do the same. You won't find this on any cart out of the box.

It seems quite a few people have given ideas on how you can code it. But if you are not code savvy then you will need to get someone to do it.

Perhaps follow the other "deal-of-the-day" sites like woot and the others at dodtracker.com and see what advice they can give you on how they did it.

User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by nde » Sun Mar 01, 2009 6:15 am

@cgcaudle - it was just a general thought.


Right now, I can't start with the checkout when any given product is out of stock and marked ***

Now I think it's really a good idea to implement a final check on the stock too (while the customer is doing the last checkout click). If any product sold out meanwhile, just display a message then.

nde
New member

Posts

Joined
Sat Jun 30, 2007 7:32 am

Post by Daniel » Sun Mar 01, 2009 6:36 am

This line of code stops customers from purchasing stock that is out of stock:

Code: Select all

<?php
        if ((!$this->cart->hasProducts()) || ((!$this->cart->hasStock()) && (!$this->config->get('config_stock_checkout')))) {
              $this->redirect($this->url->https('checkout/cart'));
?>        }
After they leave the checkout/confirm page to the payment gateway we can no longer control the customer.

Only when the customer gets to the checkout success page can we subtrack the stock.

Its like Qphoria says no other shopping cart offers this service. The only way you could do it is if payments where taken without the customer leaving the web site.

User avatar
Administrator

Posts

Joined
Fri Nov 03, 2006 6:57 pm

Post by liquidpele » Sun Mar 01, 2009 7:00 am

Actually, many shops do support this (not sure how well it's supported with GPL carts though), but you have to use the gateway's API instead of just redirecting to their site. For instance, authorize.net allows you to do advanced integration so that you never leave the shopping site. For more info on that, see here:

http://developer.authorize.net/guides/AIM/

It appears that the authorize.net AIM module for opencart zero was already done by Qphoria according to him:

http://forum.opencart.com/viewtopic.php?f=22&t=3248
Last edited by liquidpele on Sun Mar 01, 2009 7:07 am, edited 2 times in total.

New member

Posts

Joined
Mon Feb 23, 2009 11:58 pm

Post by Qphoria » Sun Mar 01, 2009 7:06 am

Sure, Authorize.net AIM exists for OpenCart 0.x

That isn't the point. That has nothing to really do with this. That is just another checkpoint. The fact is, whether they go offsite to pay, or they stay on site, the payment is still processed when that final message is sent. Granted on an integrated site, there is less time during the checkout process. But even with authorize.net AIM, you could have 2 people paying for the same item and it could still have a conflict.

Your only options would be the mutex method, which is a bit more advanced. Or, remove the item from stock as soon as its added to the cart and after a timer expires, it is removed from the user's cart and put back into stock.

This way 2 people could hit add to cart at the same time, but only one of them is gonna get it.

User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by liquidpele » Sun Mar 01, 2009 7:09 am

Oh yea, that's right.... not thinking clearly today :(

Edit: Thinking about this though, I think removing it from stock when starting the payment process, and putting it back if they cancel or get an error or it times out would be ideal. Then the only last thing you'd have to do is ensure two stock updates don't hit the DB at the same exact time, and that's not hard to prevent.

New member

Posts

Joined
Mon Feb 23, 2009 11:58 pm

Post by Qphoria » Sun Mar 01, 2009 2:04 pm

Yea that might work. just remember if there is 1 item left and 2 people add it to cart, then person 1 starts checkout, you will have to recheck the stock on cart checkout for person 2 and error that the item is out of stock. But yea it could be done

User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by cgcaudle » Mon Mar 02, 2009 5:57 am

Qphoria wrote:Yea that might work. just remember if there is 1 item left and 2 people add it to cart, then person 1 starts checkout, you will have to recheck the stock on cart checkout for person 2 and error that the item is out of stock. But yea it could be done
YES! That would be awesome! I would much rather the item return to stock if customer A did not want it/had errors so customer B, C, or D would have the opportunity to get the item....without going into negative stock.

Is there anything I can do on my end to edit anything to get this going? O0

Newbie

Posts

Joined
Tue Feb 24, 2009 6:03 am

Post by liquidpele » Mon Mar 02, 2009 10:04 am

Is there anything I can do on my end to edit anything to get this going?
You could offer me a million dollars to code it for you :D

Really though, it's up to Daniel I suppose (I think he's the only one working on 1.x??) so you'll have to convince him if you don't modify your cart yourself.

New member

Posts

Joined
Mon Feb 23, 2009 11:58 pm

Post by Qphoria » Mon Mar 02, 2009 1:13 pm

erm.. no. If you want custom code there are many forum members that could trade code for money. This is still a custom feature that most stores won't need, so its out of the core code's scope.

User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am
Who is online

Users browsing this forum: No registered users and 224 guests