New issue 807 by peter.al...@gmail.com: Stock Inventory levels not reducing
upon sale
http://code.google.com/p/wp-e-commerce/issues/detail?id=807
What steps will reproduce the problem?
1. Place a limited stock item in cart and go to checkout
2. Purchase (I used bank-transfer to test)
3. Stock says "xx of them are reserved for pending or recently completed
orders"
4. Change the order to payment accepted, then shipped, then closed
5. Stock not reduced, they remain in reserved and sit there...
What is the expected output? What do you see instead?
What version of WP e-Commerce are you using? = Version 3.8.7.1
WordPress version? = 3.2.1
Which browser? Firefox
If this issue has been discussed in the forums, please link to the relevant
posts.
Please provide any additional information below.
All other features work fine, unable to convert stock from reserved to sold.
I am expecting the Inventory number to go down once an order has progressed
past the payment accepted status.
I have WP E-Commerce Extra Shipping Options and WP E-Commerce Pick-up
Shipping Modules installed as well.
Comment #1 on issue 807 by ja...@om4.com.au: Stock Inventory levels not
reducing upon sale
http://code.google.com/p/wp-e-commerce/issues/detail?id=807
(No comment was entered for this change.)
Adjust wpsc_decrement_claimed_stock($purchlog_id) to execute first instead
of wpsc_clear_stock_claims() in function wpsc_purchlog_edit_status().
The issue arises because we are clearing the stock claims first and when it
comes to updating the balance stock, the code found no claimed stock in the
database therefore balance stock didnt need to be updated.
Would this be the correct way?
Attachments:
wpsc_purchlog_edit_status.diff 1.0 KB
Version 3.8.7.2 seems to have fixed this issue for me.
The file changes between 3.8.7.1 and 3.8.7.2 are here:
http://plugins.trac.wordpress.org/changeset?old_path=%2Fwp-e-commerce%2Ftags%2F3.8.7.1&new_path=%2Fwp-e-commerce%2Ftags%2F3.8.7.2
Looking at those changes, I can't see any code changes that would have
fixed this bug as part of the 3.8.7.2 release.
I applied the above diff in wpsc_purchlog_edit_status.diff.
Worked for me.
I agree that the issue mentioned in Comment 2 is a bug, but still problems
remain when using the test_merchant, as the original poster obviously does.
First, I need to say I am not an expert at all with wordpress and
wp-e-commerce. I am also using/testing only the test_merchant module, so I
am very well aware of what is done when using the other merchants.
However, after an examination I made, the problem is due to the function
wpsc_clear_stock_claims that is periodically run via wp_cron and deletes
the claimed stock record,
while the order is received and pending (status=2). I think the problem can
be solved by changing line 21 in wpsc-includes/cron.php to:
$sql = $wpdb->prepare( "DELETE FROM " . WPSC_TABLE_CLAIMED_STOCK . " WHERE
`cart_submitted` != '1' AND last_activity < NOW() - INTERVAL %d SECOND",
$seconds );
Now when this function is run either by cron or when the purchase_status is
changed from the Dashboard, no harm is done to these claimed stock records
and this claimed stock will not be available to other users. If payment is
received and/or the items are dispatched or transaction is marked as
completed, there is code in wpsc-transaction_results_functions.php to
permanently decrement stock and delete the record.
So, I guess, the only problem left is to delete the claimed stock record
also if the admin for some reason deletes the purchase from the dashboard.
In this case, the wpsc_delete_purchlog in wp-admin/ajax-and-init.php is
called, so I think I fixed it by changing line 685 to:
if ( $purchlog_status == 5 || $purchlog_status == 1 || $purchlog_status ==
2) {
I tried the above fix and I don't see any problem until now. Can an expert
developer check and tell us if my modifications are fine or not, and also
if they create any problems to other merchants?
Thanks in advance!
PS: Probably the last line change should be changed to:
if ( $purchlog_status == 5 || $purchlog_status == 1 || $purchlog_status ==
2 || $purchlog_status == 6) {
to handle the case of "declined payment" too...