Developer forum

Forum » Ecommerce - Standard features » Stock update does not take unit into account.

Stock update does not take unit into account.

Simon Nordahl
Simon Nordahl
Reply

Hi,

We have an upcomming site with 2 stocklocations and 2 units, when the customer adds a product to the cart he selects what unit he want to buy.

What stocklocation to use is defined on the customer (standard).

It all works until you make a few orders and notice that stocks are not correctly updated, its the correct stocklocation but not the correct unit that has been updated.

Upon inspecteing the code, the issue seems to lie in the StockLocationManager, line 54 (marked with red):

	Dim productUnits As IEnumerable(Of StockUnit) = StockUnit.GetProductStockUnits(orderLine.ProductId, orderLine.ProductVariantId)
	If Not productUnits.Any() AndAlso Not String.IsNullOrEmpty(orderLine.ProductVariantId) AndAlso String.IsNullOrEmpty(orderLine.Product.VariantId) Then
		' if there are no stock units for simple variant, take them from main product
		productUnits = StockUnit.GetProductStockUnits(orderLine.Product)
	End If
	Dim productUnitsByLocation As IEnumerable(Of StockUnit) = productUnits.
		Where(Function(stockUnit)
					Return (IsNothing(Common.Context.StockLocation) OrElse stockUnit.StockLocationId = Common.Context.StockLocation.ID)
				End Function).
		OrderBy(Function(stockUnit)
					Dim location As StockLocation = Nothing
					If stockUnit.StockLocationId <> 0 Then
						location = StockLocation.GetStockLocationByIdAndLanguage(stockUnit.StockLocationId, orderLine.Product.LanguageId)
					End If
	
					If IsNothing(location) Then
						Return 999
					Else
						stockUnit.StockLocationId = location.ID
						Return location.SortOrder
					End If
				End Function)
	If Not IsNothing(Common.Context.StockLocation) AndAlso productUnitsByLocation.Any() Then
		unitId = productUnitsByLocation.First().UnitId
	Else
		unitId = If(String.IsNullOrEmpty(orderLine.UnitID), orderLine.Product.DefaultUnitID, orderLine.UnitID)
	End If

Are there ever any reason not to attempt to find the correct unit instead of just taking the first? Something like this (Disclaimer, I'm not a VB export):

    Dim stockUnitLocation = productUnitsByLocation.FirstOrDefault(Function(loc) String.Equals(loc.UnitId, orderLine.UnitId))
    If IsNothing(stockUnitLocation)
        stockUnitLocation = productUnitsByLocation.First()
    End If
    unitId = stockUnitLocation.UnitId

 

Regards Simon Nordahl

 

 


Replies

 
Nicolai Pedersen
Reply

Hi Simon

Good question - I've send this to a dev team to check out. It might be a simple change - it might have a reason...

 
Nicolai Pedersen
Reply
This post has been marked as an answer

Hi Simon

We looked into this and propose this change instead:

unitId = If(String.IsNullOrEmpty(orderLine.UnitID), orderLine.Product.DefaultUnitID, orderLine.UnitID)
If Not IsNothing(Common.Context.StockLocation) AndAlso productUnitsByLocation.Any() Then
    If Not productUnitsByLocation.Any(Function(loc) String.Equals(loc.UnitId, unitId)) Then
        unitId = productUnitsByLocation.First()
    End If
End If

Any comments before we test this out?

Thanks, Nicolai

Votes for this answer: 1
 
Simon Nordahl
Simon Nordahl
Reply

Hi Nicolai,

Seems just as good (if not better), do you have any idea of when we can expect said change to be deployed?

 

Thanks for the quick and helpfull reponse.

Simon

 
Kristian Kirkholt Dynamicweb Employee
Kristian Kirkholt
Reply

Hi Simon

You can now fix the Stock Unit Update problem with Package "Dynamicweb.Ecommerce" version 1.5.33

You are able to find this update in the backend Package update section.

Also the correction are part of the 9.5.7 release 

You are able to find this build in the download section:

http://doc.dynamicweb.com/releases-and-downloads/releases

Please contact Dynamicweb Support if you need any additional help regarding this.

Kind Regards
Dynamicweb Support
Kristian Kirkholt

 
Simon Nordahl
Simon Nordahl
Reply

Hi Kristian

Thank you, I'll test it out.

Regards 

Simon 

 

You must be logged in to post in the forum