Class ProductViewModel
- Namespace
- Dynamicweb.Ecommerce.ProductCatalog
- Assembly
- Dynamicweb.Ecommerce.dll
The product viewmodel represents a product and its data. The model covers basic things like Name, SKU, Description and the price.
The model also contains information about related product data like product relations, units, quantity prices, stock levels, assets, attributes and much more.
Most of the data is only loaded if and when used in a template or exposed in a web-api. The more of the properties that are used, the more is loaded and that will have an impact on load performance. Each description of properties in this documentation contains information about a potential performance overhead.
When rendering a list of products, the list size (i.e. 10 vs. 30 vs. 100 products on a list) can affect the performance of a product list page since more data needs to be loaded.
WARNING: If multiple of the properties with performance overhead are used on the product list and many products are listed, a lot of data will be loaded and affect performance. Limit the use of the properties with performance overhead on lists or use the web-api to load additional information on demand when needed.
public class ProductViewModel : FillableViewModelBase
- Inheritance
-
ProductViewModel
- Inherited Members
- Extension Methods
Remarks
A number of extension methods exists for the product viewmodel giving access to additional functionality or loading data in other structures. To see these extension methods in your template, add Dynamicweb.Ecommerce.ProductCatalog in a using statement.
Properties
Active
A flag indicating that the product is active or not. It's mapped from Active. When rendering a product and this is false, it will enact a response of Default.
public bool Active { get; set; }
Property Value
- bool
Returns true if the product is active
Remarks
Lazy loaded - only filled when using it but does not come with an overhead.
AssetCategories
Returns a list of AssetCategoryViewModel representing the asset categories with assets for this product. Each category has a name and a list of assets, i.e. images and documents.
Uses GetDetailsBulk(IEnumerable<ProductKey>, string, bool) to find the list of Detail and groups them based on the GroupId.
public List<AssetCategoryViewModel> AssetCategories { get; set; }
Property Value
- List<AssetCategoryViewModel>
An instance of List<T>
Remarks
Lazy loaded - only filled when using it. Comes with a performance hit when used.
Cost
The cost of a product in default currency. Can be used to ensure that products are not sold cheaper than their cost when used with cart management and quoting of orders. It's mapped from Cost.
public double? Cost { get; set; }
Property Value
- double?
I.e. '99.95'
Remarks
Lazy loaded - only filled when using it but does not come with an overhead.
- See Also
Created
The timestamp the product was created. Once a product is created, this is set to Now. This means the DateTime is based on the solutions timezone. It's mapped from Created.
public DateTime? Created { get; set; }
Property Value
- DateTime?
I.e. '2023-10-31 12:21'
Remarks
Lazy loaded - only filled when using it but does not come with an overhead.
DefaultImage
Returns the default image of the product either from an asset category, image pattern or product image.
Gets all the Detail for all the Products with GetPrimaryDetailsBulk(IEnumerable<ProductKey>, string) with an empty detailType. Finds the Details for this Product, and then the Detail where IsDefault is true.
If the Detail is not null, it will use the path from Value, otherwise it will look at all the ProductImages found with GetProductImages(ImagePatternProductInfo) and select the DefaultImage. If no DefaultImage exists, it will use the path located in your GlobalSettings "/Globalsettings/Ecom/Picture/NoPicture/Large".
public MediaViewModel DefaultImage { get; set; }
Property Value
- MediaViewModel
An instance of MediaViewModel
Remarks
Lazy loaded - only filled when using it. Comes with a performance hit when used.
DefaultUnitId
The id of the default unit if the product comes in different units and a default unit is specified. It's mapped from DefaultUnitId.
public string DefaultUnitId { get; set; }
Property Value
- string
I.e. 'unit1'
Remarks
Lazy loaded - only filled when using it but does not come with an overhead.
DefaultVariantId
The id of the default variant if one is specified. It's mapped from DefaultVariantComboId. If this is not null, when using GetProductLink(ProductViewModel, int, bool) this is appended to the end result as $"&VariantID={DefaultVariantId}".
public string DefaultVariantId { get; set; }
Property Value
- string
I.e. 'vo1.vo2'
Remarks
Lazy loaded - only filled when using it but does not come with an overhead.
Depth
The depth of the product in the default dimension unit. It's mapped from Depth.
public double? Depth { get; set; }
Property Value
- double?
I.e. '21.35'
Remarks
Lazy loaded - only filled when using it but does not come with an overhead.
Discontinued
A flag indicating that the product has been discontinued and should not be purchasable. Can be used to show the product and disable the add to cart functionality. It's mapped from Discontinued.
public bool Discontinued { get; set; }
Property Value
- bool
Returns true if the product is discountinued
Remarks
Lazy loaded - only filled when using it but does not come with an overhead.
- See Also
DiscontinuedAction
Returns a value indicating what should happen if the product is Discontinued. It's mapped from DiscontinuedAction.
public int DiscontinuedAction { get; set; }
Property Value
- int
0 = No action, 1 = RedirectToReplacementProduct, 2 = RedirectToGroup
Remarks
Lazy loaded - only filled when using it but does not come with an overhead.
- See Also
Discount
Returns the discount of the product if any discounts are valid in the current context.
The total discount is found by creating a DiscountInfoCollection(PriceContext, Product, string, long) with PriceSettings, Product, DefaultUnitId and StockLocationId. Then it's total by using TotalPrice and this IPriceInfo is then passed on to create the PriceViewModel with the PriceSettings.
public PriceViewModel Discount { get; set; }
Property Value
- PriceViewModel
An instance of PriceViewModel
Remarks
Lazy loaded - only filled when using it. Comes with a minor performance hit when used.
- See Also
EAN
The product EAN number. European Article Number. This is a labelling system that uses numbers to identify a specific manufacturer’s retail products in the European market. It is usually 8 or 13 digits long and globally accepted. Not to be confused with the Order EAN number used in DK. It's mapped from EAN.
public string EAN { get; set; }
Property Value
- string
I.e. '12345678'
Remarks
Lazy loaded - only filled when using it but does not come with an overhead.
ExpectedDelivery
The timestamp with the expected delivery time for products that are out of stock. Should always be a date in the future.
Should only be used and displayed if the StockLevel i 0 or below and if the timestamp is in the future.
It's mapped from ExpectedDelivery. If ExpectedDelivery is MaxDate(), it's null, otherwise it's converted to a nullable DateTime. MaxDate() is set with DateTime(int, int, int, int, int, int) as new DateTime(2999, 12, 31, 23, 59, 59).
public DateTime? ExpectedDelivery { get; set; }
Property Value
- DateTime?
I.e. '2023-10-31 12:21'
Remarks
Lazy loaded - only filled when using it but does not come with an overhead.
FieldDisplayGroups
Returns a list of product field display groups.
Finds all the CategoryFieldViewModels that intersects between GetFrontendDisplayGroups() and GetDisplayGroupsFields(). If any of the GetDisplayGroupsFields() has a Section that's equals Category, it fetches all the GetCategories(Product) for that product and checks it against the Section.
public Dictionary<string, CategoryFieldViewModel> FieldDisplayGroups { get; set; }
Property Value
- Dictionary<string, CategoryFieldViewModel>
An dictionary of CategoryFieldViewModel where the key is the system name of display group
Remarks
Lazy loaded - only filled when using it. Comes with a performance hit when used.
- See Also
GroupPaths
Returns a list of lists of GroupInfoViewModel representing the group paths to this product. A product can be in several groups, so each entry in the list represents a group path to the product.
They're based on Groups and selects specifically the ones matching the GroupInfoViewModelSettingsShopId.
public List<List<GroupInfoViewModel>> GroupPaths { get; set; }
Property Value
- List<List<GroupInfoViewModel>>
A list of lists of GroupInfoViewModel
Remarks
Lazy loaded - only filled when using it. Comes with a minor performance hit when used.
Groups
Returns a list of groups that this product is direct member of.
Using the GroupInfoSettingsGroupInfoViewModelSettingsShopId to filter the GroupCollection from Groups.
public List<GroupInfoViewModel> Groups { get; set; }
Property Value
- List<GroupInfoViewModel>
A list of GroupInfoViewModel
Remarks
Lazy loaded - only filled when using it. Comes with a minor performance hit when used.
Height
The height of the product in the default dimension unit. It's mapped from Height.
public double? Height { get; set; }
Property Value
- double?
I.e. '21.35'
Remarks
Lazy loaded - only filled when using it but does not come with an overhead.
Id
The product id. It's mapped from Id.
public string Id { get; set; }
Property Value
- string
I.e. 'prod1'
Remarks
Eager loaded - always available and using it does not come with an overhead.
ImagePatternImages
Returns the images of the product found based on the shop image pattern settings.
It will look at all the ProductImages found with GetProductImages(ImagePatternProductInfo) and select all of the images where MatchesIsAlternativeImage is true.
public List<MediaViewModel> ImagePatternImages { get; set; }
Property Value
- List<MediaViewModel>
A list of MediaViewModel
Remarks
Lazy loaded - only filled when using it. Comes with a performance hit when used.
Keywords
public string Keywords { get; set; }
Property Value
- string
I.e. 'Keyword1, keyword2, keyword3'
Remarks
Lazy loaded - only filled when using it but does not come with an overhead.
- See Also
LanguageId
The product language id. It's mapped from LanguageId.
public string LanguageId { get; set; }
Property Value
- string
I.e. 'lang1'
Remarks
Eager loaded - always available and using it does not come with an overhead.
LongDescription
The long description of the product. Usually contains markup and multiple lines. It's mapped from LongDescription.
public string LongDescription { get; set; }
Property Value
- string
I.e. '<h2>Long description of the product</h2>'
Remarks
Lazy loaded - only filled when using it but does not come with an overhead.
Manufacturer
Returns the manufacturer of the product if specified.
Uses GetManufacturerById(string) with the ManufacturerId to fill in the ManufacturerViewModel.
public ManufacturerViewModel Manufacturer { get; set; }
Property Value
- ManufacturerViewModel
An instance of ManufacturerViewModel
Remarks
Lazy loaded - only filled when using it. Comes with a performance hit when used.
MetaDescription
The meta description of the product. Can contain multiple lines. It's mapped from MetaDescription.
If it's not null, it's added with MetaAddTag(string, string) with the name "Description".
public string MetaDescription { get; set; }
Property Value
- string
I.e. 'Some product description'
Remarks
Lazy loaded - only filled when using it but does not come with an overhead.
MetaKeywords
The meta keywords of the product. Can contain multiple lines. It's mapped from MetaKeywords.
If it's not null, it's added with MetaAddTag(string, string) with the name "Keywords".
public string MetaKeywords { get; set; }
Property Value
- string
I.e. 'Keyword1, keyword2, keyword3'
Remarks
Lazy loaded - only filled when using it but does not come with an overhead.
MetaTitle
The product meta title. Often the same value as Name but can be overwritten in the meta title field. It's mapped from MetaTitle.
public string MetaTitle { get; set; }
Property Value
- string
I.e. 'T-shirt'
Remarks
Lazy loaded - only filled when using it but does not come with an overhead.
- See Also
Name
The product name. It's mapped from Name.
public string Name { get; set; }
Property Value
- string
I.e. 'T-shirt'
Remarks
Lazy loaded - only filled when using it but does not come with an overhead.
NeverOutOfstock
A flag indicating that the product is marked as NOS or Never out of stock. If true, the product can be ordered eventhough it is a stock product and no items are in stock. Can be used to allow ordering of a product in the UI even if stocklevels are below 0.
It's mapped from NeverOutOfStock.
public bool NeverOutOfstock { get; set; }
Property Value
- bool
Returns true if the product is a NOS product
Remarks
Lazy loaded - only filled when using it but does not come with an overhead.
- See Also
Number
The product number or SKU of the product. It's mapped from Number. When exporting with ProductViewModelsExporter, it will set ProductNumber to this.
public string Number { get; set; }
Property Value
- string
I.e. 'sku123456'
Remarks
Lazy loaded - only filled when using it but does not come with an overhead.
PointPrice
The price of the product in points if the current user can buy the product with points. It's mapped from DefaultPoints.
public double? PointPrice { get; set; }
Property Value
- double?
I.e. '100'
Remarks
Lazy loaded - only filled when using it but does not come with an overhead.
Price
Returns the final price of the product with discounts subtracted.
It's mapped by creating a new PriceViewModel with PriceSettings and a PriceInfo.
This PriceInfo based on GetPrice(PriceContext, Product, string, long) with PriceSettings, Product, DefaultUnitId and StockLocationId.
The PriceInfo is then subtracted by the total amount of discounts found for the product.
PreparePrices(PriceContext, IEnumerable<Product>) is run if they have not yet been prepared.
public PriceViewModel Price { get; set; }
Property Value
- PriceViewModel
An instance of PriceViewModel
Remarks
Lazy loaded - only filled when using it. Comes with a minor performance hit when used.
- See Also
PriceBeforeDiscount
Returns the price of the product before discounts are subtracted.
It's mapped by creating a new PriceViewModel with PriceSettings and a PriceInfo.
This PriceInfo based on GetPrice(PriceContext, Product, string, long) with PriceSettings, Product, DefaultUnitId and StockLocationId.
PreparePrices(PriceContext, IEnumerable<Product>) is run if they have not yet been prepared.
public PriceViewModel PriceBeforeDiscount { get; set; }
Property Value
- PriceViewModel
An instance of PriceViewModel
Remarks
Lazy loaded - only filled when using it. Comes with a minor performance hit when used.
- See Also
PriceInformative
Returns an informative price of the product if one is specified. An informative price can be a RRP, before price or other. The price is informational only and does not affect the price calculations.
This PriceViewModel is created with PriceSettings and GetInformativePrice(PriceContext, Product, string, long) with the Product, DefaultUnitId and StockLocationId.
PreparePrices(PriceContext, IEnumerable<Product>) is run if they have not yet been prepared.
public PriceViewModel PriceInformative { get; set; }
Property Value
- PriceViewModel
An instance of PriceViewModel
Remarks
Lazy loaded - only filled when using it. Comes with a minor performance hit when used.
- See Also
Prices
Returns a list of quantity prices. It will contain the prices that will be applicable if 2 or more products are added to the cart if quantity prices have been specified.
public List<PriceListViewModel> Prices { get; set; }
Property Value
- List<PriceListViewModel>
A list of PriceListViewModel
Remarks
Lazy loaded - only filled when using it. Comes with a minor performance hit when used.
- See Also
PrimaryOrDefaultGroup
Returns the default or primary group given the current shop context. If a product is member of several groups in a shop, the one marked as primary is returned - otherwise the first group found.
Uses GetDefaultGroupByShopId(Product, string) with the ProductViewModelSettingsShopId.
public GroupInfoViewModel PrimaryOrDefaultGroup { get; set; }
Property Value
- GroupInfoViewModel
An instance of GroupInfoViewModel
Remarks
Lazy loaded - only filled when using it. Comes with a minor performance hit when used.
ProductCategories
Returns a list of product categories.
Fetches all Category with GetCategories(Product, bool) for the Product. Then uses GetFieldsByCategoryId(string) for each of those categories to get all the fields, which will be converted to CategoryFieldViewModel.
If the DoNotRender is true for the Field, it will not be returned.
public Dictionary<string, CategoryFieldViewModel> ProductCategories { get; set; }
Property Value
- Dictionary<string, CategoryFieldViewModel>
An dictionary of CategoryFieldViewModel where the key is the system name of category
Remarks
Lazy loaded - only filled when using it. Comes with a performance hit when used.
- See Also
ProductDiscounts
Returns a list of discounts that are applicable for the current context.
The discounts is found by creating a DiscountInfoCollection(PriceContext, Product, string, long) with PriceSettings, Product, DefaultUnitId and StockLocationId. All of these DiscountInfo are then mapped to DiscountViewModel.
public IEnumerable<DiscountViewModel> ProductDiscounts { get; set; }
Property Value
- IEnumerable<DiscountViewModel>
A list of DiscountViewModel
Remarks
Lazy loaded - only filled when using it. Comes with a minor performance hit when used.
- See Also
ProductFields
Returns a list of product field values. Product fields are the fields that are specified to be on all products, known as Custom fields (EcomProducts table).
Maps by looping through all the ProductFieldValue in ProductFieldValues and creating a FieldValueViewModel based on them. The key of this dictionary is SystemName.
If the DoNotRender is true for the ProductField that the ProductFieldValue belongs to, it will not be returned.
public Dictionary<string, FieldValueViewModel> ProductFields { get; set; }
Property Value
- Dictionary<string, FieldValueViewModel>
An dictionary of FieldValueViewModel where the key is the system name of the field
Remarks
Lazy loaded - only filled when using it. Comes with a minor performance hit when used.
- See Also
ProductType
The type of the product. Possible values are; Stock, Service, Bom, GiftCard. It's used to check if this is Bom when using GetBomConfiguration(ProductViewModel). It's mapped from Type.
public ProductType ProductType { get; set; }
Property Value
- ProductType
I.e. 'bom'
Remarks
Lazy loaded - only filled when using it but does not come with an overhead.
PurchaseMinimumQuantity
The minimum purchase quantity of a product. The minimum purchase quantity is handled by the cart, but this property can be used to create the UI to help the user order and understand the right quantity. Used to ensure that i.e. minimum 4 of a product is purchased. It's mapped from PurchaseMinimumQuantity.
public double? PurchaseMinimumQuantity { get; set; }
Property Value
- double?
I.e. '4'
Remarks
Lazy loaded - only filled when using it but does not come with an overhead.
- See Also
PurchaseQuantityStep
The purchase quantity step of a product. The purchase quantity step is handled by the cart, but this property can be used to create the UI to help the user order and understand the right quantity. Can be used to ensure that i.e. either 4, 6, 8 etc. are ordered. It's mapped from PurchaseQuantityStep.
public double? PurchaseQuantityStep { get; set; }
Property Value
- double?
I.e. '2'
Remarks
Lazy loaded - only filled when using it but does not come with an overhead.
- See Also
Rating
The rating of the product as an average of all ratings. It's mapped from Rating.
public double? Rating { get; set; }
Property Value
- double?
I.e. '3.2'
RelatedGroups
Returns a list of RelatedGroupViewModel representing the relation groups like 'Accesories', 'Also works with', 'Others also bought' etc. Each product can have various groups attached to them and each group contains a list of products that are related to this product in the given group.
Uses GetRelations(string, string, string, bool, string, string) with Id, VariantId, ProductViewModelSettingsLanguageId, true, ProductViewModelSettingsShopId and ProductViewModelSettingsCountryCode, then groups them based on RelatedGroupId.
public List<RelatedGroupViewModel> RelatedGroups { get; set; }
Property Value
- List<RelatedGroupViewModel>
A list of RelatedGroupViewModel
Remarks
Lazy loaded - only filled when using it. Comes with a performance hit when used.
ReplacementProduct
Returns the replacement product if this product is discountinued and a replacement is specified. It's mapped by creating a new ProductInfoViewModel based on ReplacementProductId and ReplacementVariantId.
public ProductInfoViewModel ReplacementProduct { get; set; }
Property Value
- ProductInfoViewModel
An instance of ProductInfoViewModel
Remarks
Lazy loaded - only filled when using it. Comes with a performance hit when used.
- See Also
ShortDescription
The short description of the product. Usually contains markup and multiple lines. It's mapped from ShortDescription.
public string ShortDescription { get; set; }
Property Value
- string
I.e. '<h2>Short description of the product</h2>'
Remarks
Lazy loaded - only filled when using it but does not come with an overhead.
StockDeliveryText
The stock delivery text of the default unit id in the current stock location.
Used with StockDeliveryValue to show an expected delivery time for products that are either low or out of stock.
It's mapped from GetStockStatus(Product, double), using the StockLevel as the double to get the StockStatus.
Then using GetExpectedDeliveryText(string) with the ProductViewModelSettingsLanguageId to get this.
public string StockDeliveryText { get; set; }
Property Value
- string
I.e. 'days'
Remarks
Lazy loaded - only filled when using it. Comes with a performance hit when used.
- See Also
StockDeliveryValue
The stock delivery value of the default unit id in the current stock location.
Used with StockDeliveryText to show an expected delivery time for products that are either low or out of stock.
It's mapped from GetStockStatus(Product, double), using the StockLevel as the double to get the StockStatus.
Then using GetExpectedDeliveryValue(string) with the ProductViewModelSettingsLanguageId to get this.
public string StockDeliveryValue { get; set; }
Property Value
- string
I.e. '5-7'
Remarks
Lazy loaded - only filled when using it. Comes with a performance hit when used.
- See Also
StockLevel
The stock level of the default unit id in the current stock location. Consider using the StockUnits.
It's mapped from GetUnitStock(Product, StockLocation, string) where the StockLocation is found by GetStockLocation(long) with the ProductViewModelSettingsStockLocationId and DefaultUnitId.
public double? StockLevel { get; set; }
Property Value
- double?
I.e. '123'
Remarks
Lazy loaded - only filled when using it. Comes with a performance hit when used.
- See Also
StockStatus
The stock status of the default unit id in the current stock location. Consider using the StockUnits.
It's mapped from GetStockStatus(Product, double), using the StockLevel as the double to get the StockStatus.
Then using GetText(string) with the ProductViewModelSettingsLanguageId to get this.
public string StockStatus { get; set; }
Property Value
- string
I.e. 'Few in stock'
Remarks
Lazy loaded - only filled when using it. Comes with a performance hit when used.
- See Also
StockUnits
Returns a list of StockUnitViewModel representing the inventory levels for this product in various units, locations and variants. Some products does not exist in units or in different stock locations and then StockLevel can be used. If a product comes in different units and/or is in stock in various stock locations, the stock level can vary based on these settings. This list contains information about the StockLevels in the various units for the various locations.
Uses GetStockUnits(string, string) with Id and VirtualVariantId.
public List<StockUnitViewModel> StockUnits { get; set; }
Property Value
- List<StockUnitViewModel>
A list of StockUnitViewModel
Remarks
Lazy loaded - only filled when using it. Comes with a performance hit when used.
- See Also
Title
The product meta title. Often the same value as Name but can be overwritten in the meta title field.
It's mapped from MetaTitle, if that property is not null, otherwise it maps Name.
public string Title { get; set; }
Property Value
- string
I.e. 'T-shirt'
Remarks
Lazy loaded - only filled when using it but does not come with an overhead.
- See Also
UnitOptions
Returns a list of UnitOptionViewModel representing the available units for this product if any are specified. This list also contains the available stocklevels for the given unit. If a product comes in different units, use this list to create a unit selector.
Uses GetStockUnits(string, string) with Id and VariantId. To fill NeverOutOfStock, it will find the StockUnit with a matching UnitId matching the Id and NeverOutOfStock.
public List<UnitOptionViewModel> UnitOptions { get; set; }
Property Value
- List<UnitOptionViewModel>
A list of UnitOptionViewModel
Remarks
Lazy loaded - only filled when using it. Comes with a performance hit when used.
- See Also
Updated
The timestamp the product was last updated, this doesn't necessarily mean changed. If you save the product with the same information, this will change to Now. This means the DateTime is based on the solutions timezone. It's mapped from Updated.
public DateTime? Updated { get; set; }
Property Value
- DateTime?
I.e. '2023-10-31 12:21'
Remarks
Lazy loaded - only filled when using it but does not come with an overhead.
VariantId
The product variant id. The variant id is a combination of ids of variant options. I.e. if a product comes in different colors and sizes, the variant id will be a combination of 2 variant option ids (a color and a Size). It's mapped from VariantId.
public string VariantId { get; set; }
Property Value
- string
I.e. 'vo1.vo2'
Remarks
Eager loaded - always available and using it does not come with an overhead.
VariantInfo
Returns a structure that describes the variants of the product and possible combinations with min and max prices and other relevant information.
Set if LoadVariantInfoOnVariants or GetIsVariantMaster(Product) is true.
public VariantInfoViewModel VariantInfo { get; set; }
Property Value
- VariantInfoViewModel
An instance of VariantInfoViewModel
Remarks
Lazy loaded - only filled when using it. Comes with a performance hit when used.
VariantName
The name of the variant if the product is a variant (VariantId has a value). It's mapped by getting the name through GetVariantName(string, string) with VariantId and LanguageId.
public string VariantName { get; set; }
Property Value
- string
I.e. 'Red - Small'
Remarks
Lazy loaded - only filled when using it. Comes with a potential minor overhead.
- See Also
Weight
The weight of the product in the default weight unit. It's mapped from Weight.
public double? Weight { get; set; }
Property Value
- double?
I.e. '1.35'
Remarks
Lazy loaded - only filled when using it but does not come with an overhead.
Width
The width of the product in the default dimension unit. It's mapped from Width.
public double? Width { get; set; }
Property Value
- double?
I.e. '21.35'
Remarks
Lazy loaded - only filled when using it but does not come with an overhead.