November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
IInventoryService is what you need, you can get the stocks of a variant by its code, update the data, then save it back
https://world.episerver.com/documentation/Class-library/?documentId=commerce/8/95A5598E
Hi Quan,
Thx, could you elaborate a little? ;)
Perhaps with example or reference to a concrete example.
I would much appreciate this.
Hi again,
When I'm trying to update values in the InventoryRecord, it isn't stored in the database.
What am I doing wrong?
public someClass { ... private bool UpdateVariant(VariantData vd) { if(vd == null) { return false; } try { IEnumerable<InventoryRecord> irs = Helpers.Utilities.QueryInventoriesByEntryCode(vd.Code); var editableVariant = irs.First(); if (editableVariant != null && vd.Quantity > -1) { var tmpV = editableVariant.CreateWritableClone(); tmpV.PreorderAvailableQuantity = vd.Quantity; var inventoryService = ServiceLocator.Current.GetInstance<IInventoryService>(); UpdateInventoryRecord(tmpV); return true; } } catch (Exception) { } return false; } private void UpdateInventoryRecord(InventoryRecord record) { var inventoryService = ServiceLocator.Current.GetInstance<IInventoryService>(); inventoryService.Update(new[] { record }); } ... }
Did you make sure inventoryService.Update was actually called, and not the empty catch that swallows any exception?
No there's no exceptions, it runs the update method on all the WritableClones of the InventoryRecords
Should I perhaps use inventoryservice Save method instead?
Or is it overall a wrong approach. Should I update the 'containing' Variant also or what?
I'm in the dark here...
... When I'm debugging I can see that the InventoryRecord is Readonly (InventoryRecord.IsReadOnly == True).
That might be the issue ;) ...
I'll repport back with a fix/status
OMG!
I'm sorry for wasting your time...
I tried to set the WRONG property...
the right way is to set InventoryRecord.PurchaseAvailableQuantity
... tmpV.PurchaseAvailableQuantity = (decimal)vd.Quantity; ...
And with use of update method everything works - THX anyway
Hi,
we're using the newest commerce 12.
For a customer 'Im about to make a admin tool to upload an excel-sheet with variant id's and data like stock count/quantity, so that the catalog/variants quantity should be updated to this number.
Any ideas on how to get to a variant/prodycts quantity property, hence update it?
Is it through [ContentReference] InventoryReference when I'm traversing VariantContent objects?
If yes, any hints on the best way?
thx
J