Developer forum

Forum » Development » Custom generated field

Custom generated field

Martin Grønbekk Moen
Martin Grønbekk Moen
Reply

What is the best way to create a custom generated field.
We need to accumulate the stock level of all variants in the same color.

So we have two variant groups (Color and Size). One product has multiple colors, and multiple sizes.
Each variant option of course have their own stock level, but we need to know the total stock level across all sizes on a particular color.

Thinking of creating a custom product field which hold this info, but what is the best way to populate this field?
Is it possible to populate this field during the index build, or what would be the best practice?


Replies

 
Nicolai Pedersen
Reply

Hi Martin

Good question. I think your approach is the best bet. Maybe use a scheduled SQL in the scehduler to update the field - you can probably do it using a single relatively simple SQL expression.

BR Nicolai

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

If you have a limited number of products, you could also consider a computed column where you count the current stock dynamically and in real-time: https://www.mssqltips.com/sqlservertip/5464/computed-columns-with-scalar-functions-sql-server-performance-issue/

Not sure how Dynamicweb handles such a field though. 

Be aware of performance though; if you have a large product set this could lead to issues quickly.

Imar

 

 
Martin Grønbekk Moen
Martin Grønbekk Moen
Reply

Thanks both of you. Because of the performance I would very much like to do it through some kind of job or batch.
Thats why I was wondering if it even was possible through the index.

But I guess i will have to dig into some SQL in order to get it to work...

 

You must be logged in to post in the forum