Posted on 12/10/2020 19:09:31
Well it would be neat and cool to have this built into DW someday :)
And you're right, the stock management will always be likely to cause headaches no matter how you spin this :) You would have to re-calculate the stock value for the other stock units after each sale.
As you said, the simple thing is to add the relation and calculation between the units, f.e. by adding StockUnitParentUnitId, StockUnitUnitSize, and StockUnitName (instead of using the VariantOptions table) fields to the EcomStockUnit table:
StockUnitProductId |
StockUnitId |
StockUnitName |
StockUnitQuantity |
StockUnitParentUnitId |
StockUnitUnitSize |
ProductA |
SU1 |
Piece |
492 |
|
1 |
ProductA |
SU2 |
Box |
4 |
SU1 |
100 |
ProductA |
SU3 |
Pallet |
0 |
SU1 |
1000 |
Then inside SetOrderComplete / CheckoutDone or wherever you do the stock calculations after orders are completed today, you'd have to trigger recalculations of all stock values for all stock units for that product with a StockUnitParentUnitId on them, based on the StockUnitUnitSize value. So if someone bought 93 single units of ProductA, the table rows would look something like this afterwards:
StockUnitProductId |
StockUnitId |
StockUnitName |
StockUnitQuantity |
StockUnitParentUnitId |
StockUnitUnitSize |
ProductA |
SU1 |
Piece |
399 |
|
1 |
ProductA |
SU2 |
Box |
3 |
SU1 |
100 |
ProductA |
SU3 |
Pallet |
0 |
SU1 |
1000
|
This is at least how I would approach the issue without having spent any time yet on researching how DW manages the stock under the hood, maybe after that I'll realise that I'm an idiot, shut up and leave you alone :)
In the case of me being Simple Jack, I could probably just skimp on the stock calculations since I'm always working with ERP integrated webshops. All Stock is synced / fetched from the ERP systems on the fly and no orders are allowed to be finished unless the LiveIntegration is running. I'd just need to add the fields so that I could show the units in the frontend, then convert them to single units during checkout and have the ERP do the rest. But that wouldn't be much of a solution for anyone else now would it :)
BR,
Nóri