SilverShop/Stock won't decrement ProductWarehouseStock

Silverstripe Version: 4.3.3
SilvershopVersion: 3.0.0
silvershop/stock: dev-master

I have trouble to get silvershop/stock to work.

I was able to install the module. I was able te create a ware house. I did add quantity for products. The problem that I am facing is that the stock won´t get decremented. I found out that ProductSockExtension has a methode decrementStock() that should handle that. If i set a breackpoint to there everything looks good to me. This is what warehouse looks before it gets reduced: 01
This is how it looks afterwards: 35
The only difference i can spot is that quantity is a string before it gets decremented. Afterwards it is an int. Quantity is defined as Varchar. But i think it schould be possible to store an Int into a DBVarchar field.

So to me it looks as if it just wouldn´t write to the database. I even looked at the write methode if i can find out if I have an error there that won´t be showen.

Does this module work for others? Is there a config that has to be set to make that work? As I understand the docks i´d say no. Any ideas why this won’t write to the db?

Given that the LastEdited value is the same in both, I’d agree that the DB write hasn’t happened. Have you got xdebug installed? You might need to step through everything to see what’s going on. Might be worth enabling the MySQL query log as well, to see if the queries are being sent and that they are actually making sense.

I’d have thought the quantity field should be defined as a numeric of some sort, else you’re relying on all kinds of type-juggling during the increments / decreases. It may not be the cause of this issue, but it seems like a curious choice.

1 Like

I have xdebug installed. I couldn’t work without it. I have no clue what there is going on. I stepped into the write methode. From there everything looks good. No errors there i even tried to turn on debug on write. But no errors.

The quantityfield is a varchar because they creators needed to support -1 for infinity amount of items.

I just created an mysql query log file lets see if i can find the error in there .

I found the query in the query log file Execute UPDATE "SilverShop_ProductWarehouseStock" SET "ClassName" = 'SilverShop\\Stock\\Model\\ProductWarehouseStock', "LastEdited" = '2019-08-27 13:28:10', "Created" = '2019-08-26 09:44:09', "Quantity" = '98', "ProductID" = 24, "ProductClass" = 'SilverShop\\Page\\Product', "WarehouseID" = 1 WHERE ("ID" = 2) Close stmt Even that looks good to me. I can’t spot an error.

If i execute the query in phpmyadmin it works so it is also not the query.

I’m not sure if this is just a result of the testing, but the query you posted is updating a different ID than the snippets you posted earlier.

Still seems odd. Signed integer fields can accept negative numbers. Ah well.

As i had to turn on the mysql query log. It is another query.

This is the db table i am talking about.

53

I raised a ticket here does not decrease · Issue #27 · silvershop/silvershop-stock · GitHub. thank you Dorset

1 Like