WBCE CMS Forum

WBCE CMS – Way Better Content Editing.

Du bist nicht angemeldet.

#1 18.03.2019 03:47:27

losttrip
Mitglied

Stock handling in case of non-completed orders

I am sorry I am not able to help with your specific issue.  I do have what seems to be a related issue, so I thought I would join this thread, but if you would rather I start a new one, feel free to instruct me to do so, or move my post.  I thought, since you have the associated view.php code listed, it would be suitable to ask here.

I am testing bakery functionality locally:
WBCE Version: 1.3.3
PHP Version: 7.1.0
Bakery 1.8.4

I have a client who sells unique items, so there is only one (1) stock of each item.  So, it is very important to keep stock levels showing correctly and in a timely manner.  They can not afford duplicate orders, but they also can't afford to have non completed orders keeping stock from being available for purchase.

That said, here are the scenarios I have been testing.
[list=2]
[*]I put an item in my cart.  That item on the store page immediately shows N/A, which is expected.  If I then click on the red X or Cancel the order, the stock level immediately returns to 1.  Great![/*]
[*]I put an item in my cart.  I leave the page and come back after an hour.  The item store page still shows stock "N/A".  The only way I can get the item to restock is to click the "View Cart" button, which shows me a message that my cart is empty [Continue shopping] (so my cart is being emptied, which is expected, but the stock level is not being updated automatically), and then only when I return to the item store page the stock is returned to 1. [/*]
[/list]

I am trying to figure out how the restocking of not submitted orders is triggered.  Does it tack a future action from the initial buyer who put the item in their cart in order for the re-stocking to occur?

For testing purposes, Is there a way to change this time so that I do not have to wait an hour each time I want to test this?  I would prefer to have this restocking action happen sooner, like after 2 minutes.  I did a search for php time functions, but could not fully understand how to implement this.

[== PHP ==]
// Delete db records of not submitted orders older than 1 hour
		$outdate = $now - (60 * 60 * 1);

Thank you.

Offline

#2 18.03.2019 07:50:59

florian
Administrator

Re: Stock handling in case of non-completed orders

I've moved your post into a new topic (the problem I described in the other thread seemed just to be an usability issue, e.g. users misinterpreted the button "Continue Shopping" and clicked there instead of "Buy").

About your issue: I hope this is the explanation/solution (I'm not sure) -
There-stocking mechanism is only proceeded if someone visits a "real" bakery page. A "usual" page just with Minicart included is not sufficient to reset the stock counter since the re-stocking code is only executed when the modules/bakery/view.php is loaded (e.g. a bakery page is requested from the server).
So it might help you set a cronjob which calls every 5 minutes the product overview.

The code

$outdate = $now - (60 * 60 * 1);

means 3600 seconds (since the order time is saved as an Unix timestamp). So to decrease the time after a non-completed order is (hopefully) reverted just change this to

$outdate = $now - 120;

Beitrag geändert von florian (18.03.2019 07:59:05)


Code allein macht nicht glücklich. Jetzt spenden!

Offline

#3 19.03.2019 01:22:21

losttrip
Mitglied

Re: Stock handling in case of non-completed orders

[== PHP ==]
$outdate = $now - (60 * 60 * 1);

First a quick question.  What is the purpose of the * 1 in this line?

Why not use:

[== PHP ==]
$outdate = $now - (60 * 60);

or just,

[== PHP ==]
$outdate = $now - 3600;

Is it just coder preference?


Now back to my issue.  I am not using minicart, and there is only one bakery page, with only one product, and only a single unit of that product.

I've continued to test this and the only way I can (sometimes) get the stock to re-stock from 0 (zero) to 1 (one) is by waiting past the two minutes and then returning to the bakery page on the local test site and clicking "View Cart".  BUT, this only SOMETIMES updates the stock back to 1.  Is the "View Cart" the only action that runs the view.php file?

AND, If I have two different browsers open and I put the item in the cart of browser 1, I can not get the stock to re-stock using browser 2.  No matter how long I wait or what I try.  Reload, Refresh, clicking "View Cart", "add to Cart", nothing works.  The item always shows "N/A" (Not Available).

I can only get the stock level to re-stock (sometimes) by clicking the "View Cart" button in browser 1, the user who put the item in the cart originally.  This is not of much use if the person who puts the item in their cart never returns to the site.

Any suggestions?

Offline

#4 19.03.2019 10:05:37

florian
Administrator

Re: Stock handling in case of non-completed orders

Sorry, forget my first answer.
Seems to be a bigger problem. I will have a look at it lateron, but I can't promise that I find a solution.


Code allein macht nicht glücklich. Jetzt spenden!

Offline

#5 19.03.2019 15:17:57

losttrip
Mitglied

Re: Stock handling in case of non-completed orders

I appreciate your time / thought.  I will continue to chip away at testing to see if I can maybe find more results that might help.

Offline

#6 19.03.2019 20:43:34

florian
Administrator

Re: Stock handling in case of non-completed orders

Some information about that case...

1) The re-stocking is only executed if
- someone views his cart
- an item is added to somone's cart
- changes to the cart are applied
- an order is submitted
- the shipping address form is hidden or displayed.
So just viewing a usual bakery page will NOT update the stock.
I thought it might work if I just move the block of code which resets the stock outside the if condition, but doing so breaks Bakery - there are no errors displayed, but ordering products doesn't work any more, e.g. neither the order is stored, nor confimation emails are sent. So the code has to stay in place.


2) Beside of this, there are issues due to the old code of Bakery and PHP 7.x.
I'm not completely sure, but I think, the code

if (is_numeric($stock) && !empty($stock)) {

will never be true, if the item amount is 0, because the value 0 is an "empty" thing. So this has to be changed to

if (is_numeric($stock) && $stock!='') {

Changed to this, and called the cart after a period of time, the unfulfilled orders are deleted from the database, but the item stock is still not updated. So I applied some changes to the SQL query which should re-add the ordered amount:
Old:

$database->query("UPDATE ".TABLE_PREFIX."mod_bakery_items SET stock = stock + '$quantity' WHERE item_id = '$item_id'");

New:

$new_stock = intval($stock)+intval($quantity);							
$updq = 'UPDATE '.TABLE_PREFIX.'mod_bakery_items SET `stock`=\''.$new_stock.'\' WHERE `item_id` =\''.$item_id.'\'';

This way, the stock is increased - but unfortunately, it is increased too much, since - again due to "empty" the Bakery setting "Allow out of Stock Orders" = false is ignored. So line ~275

// Only use stock admin if stock is not blank
if (is_numeric($stock) && !empty($stock)) {

has to be changed to

// Only use stock admin if stock is not blank
if (is_numeric($stock)) {

to avoid that sold-out items could be put in the cart.

Beside of this, the re-stocking still is not reliable. It might be wanted behavoiur, but it seems that the code is not executed in the same browser / user, e.g. If I put sth. in the cart, do for the given amount of time (2 minutes for testing purposes) nothing and then call the cart again, my item is still inside, although I expected it should be deleted. This happens (sometimes) if I test with another browser, but sometimes this does not help either - no idea why.

So long terms short, the mechanism has to be reworked heavily. Unfortunately, my PHP knowledge does not last for this.


Code allein macht nicht glücklich. Jetzt spenden!

Offline

#7 19.03.2019 20:53:38

losttrip
Mitglied

Re: Stock handling in case of non-completed orders

I truly appreciate your effort.
This is disappointing news.

1) The re-stocking is only executed if
- someone views his cart
- an item is added to somone's cart
- changes to the cart are applied
- an order is submitted
- the shipping address form is hidden or displayed.

When there is only 1 unit of each product, and that unit is in someones cart, none of these actions will take place, as future visitors will see "N/A" for the stock and therefore there is no action they can/will take on that item... and therefore the res-stocking will never be accurate.

Beitrag geändert von losttrip (19.03.2019 20:57:01)

Offline

#8 19.03.2019 21:19:26

florian
Administrator

Re: Stock handling in case of non-completed orders

It might be a workaround if you create a cronjob which executes yourdomain.tld/yourbakerypage.php?view_cart=yes frequently. If the other fixes mentioned above are applied to the view.php, non-fulfilled orders seem to be cleared.


Code allein macht nicht glücklich. Jetzt spenden!

Offline

#9 19.03.2019 21:20:48

losttrip
Mitglied

Re: Stock handling in case of non-completed orders

I will test that and get back to you.  Thank you.  It might be a couple of days before I have a chance now.

Offline

#10 19.03.2019 23:14:53

losttrip
Mitglied

Re: Stock handling in case of non-completed orders

Just for clarification.

This code appears in four places, lines ~ 210, 275, 340, 478

[== PHP ==]
if (is_numeric($stock) && !empty($stock)) {

Should I be changing only line 275 to:

[== PHP ==]
if (is_numeric($stock)) {

and the other three lines to
Should I be changing only line 275 to:

[== PHP ==]
if (is_numeric($stock) && $stock!='') {

And the  SQL query appears in two places, lines ~ 212 and 480
Do I make the suggested change in both places, or just  212 under the section about:

[== PHP ==]
// First put not sold items back to stock...

Hope this makes sense.

I guess I will have to upload the test site to a server to test the cronjob work around, as I don't know how to run a cron job on my localhost.

Offline

#11 20.03.2019 15:09:44

florian
Administrator

Re: Stock handling in case of non-completed orders

Hm, weird.
I've changed the SQL string back to the former version - which actually does work, so changing the line is not necessary.

The change of

if (is_numeric($stock) && !empty($stock)) {

to

if (is_numeric($stock)) {

has to be applied to avoid ordering of sold out-items. About the other appearances - I confess I don't know what to do with them. Changing them to

if (is_numeric($stock) && $stock!='') {

does not change the behaviour of Bakery.

In my opinion, the second condition is redundant anyway. If $stock has no value, is_numeric is false, so there is no need for another check if $stock is not an empty field.

To be honest, I would not recommend to use Bakery in this special case. A professional online shop tool or selling the items via Etsy probably will be the better solution.


Code allein macht nicht glücklich. Jetzt spenden!

Offline

#12 20.03.2019 22:28:06

losttrip
Mitglied

Re: Stock handling in case of non-completed orders

florian schrieb:

To be honest, I would not recommend to use Bakery in this special case. A professional online shop tool or selling the items via Etsy probably will be the better solution.

I respect you opinion.  And I am heavily leaning away from Bakery for this project, but part of me doesn't want to give up on Bakery, as a selling tool like this is essential to have in the arsenal of tools of a great CMS.  Also, if it's not a good choice for this "special case", how can it be a good tool for any store... since I expect most stores, even with much stock, will want to keep their stock levels accurate in their web store.  I built an OSCommerce site from scratch (with no experience at all... just a great book) many years ago with thousands of products and I don't remember ever having a stock level issue.

From what I can decipher there is no one developing Bakery any more.  Are there no users with Bakery installs in operation?  If there are (and I presume there are) how do they handle the stock level issues?  I'm not just asking you Florian, I am asking EVERYONE.

Thank you again for your time trying to assist me.

Offline

Fußzeile des Forums

up