/// <summary> /// Creates a <see cref="IProductDataTableRow"/> from <see cref="IProductContentBase"/>. /// </summary> /// <param name="baseContent"> /// The <see cref="IProductContentBase"/>. /// </param> /// <param name="isVariant"> /// A value indicating whether or not the row represents a variant. /// </param> /// <returns> /// The <see cref="TRow"/>. /// </returns> public TRow Create(IProductContentBase baseContent, bool isVariant = true) { Guid productKey; Guid productVariantKey; bool isAvaliable; Guid[] matchKeys; var type = baseContent.GetType(); if (baseContent is IProductVariantContent) { var variant = (IProductVariantContent)baseContent; productKey = variant.ProductKey; productVariantKey = variant.Key; isAvaliable = variant.Available; matchKeys = variant.Attributes.Select(x => x.Key).ToArray(); } else { var product = baseContent as IProductContent; if (product == null) { throw new InvalidCastException("baseContent could not cast to IProductContent"); } productKey = product.Key; productVariantKey = product.ProductVariantKey; isAvaliable = product.Available; matchKeys = Enumerable.Empty <Guid>().ToArray(); } var row = new TRow { ProductKey = productKey, ProductVariantKey = productVariantKey, Sku = baseContent.Sku, MatchKeys = matchKeys, OnSale = baseContent.OnSale, FormattedPrice = baseContent.Price.AsFormattedCurrency(), Price = baseContent.Price, SalePrice = baseContent.SalePrice, FormattedSalePrice = baseContent.SalePrice.AsFormattedCurrency(), IsAvailable = isAvaliable, InventoryCount = baseContent.TotalInventoryCount, OutOfStockPurchase = baseContent.OutOfStockPurchase, IsForVariant = isVariant }; return(this.OnCreate(row, baseContent)); }
/// <summary> /// The current effective price. /// </summary> /// <param name="content"> /// The content. /// </param> /// <returns> /// The sale price if on sale, otherwise returns the price. /// </returns> public static decimal PriceOrSalePrice(this IProductContentBase content) { return(content.OnSale ? content.SalePrice : content.Price); }
/// <summary> /// Allows for overriding the creation of <see cref="TRow"/> from <see cref="IProductContentBase"/>. /// </summary> /// <param name="row"> /// The <see cref="TRow"/>. /// </param> /// <param name="baseContent"> /// The <see cref="IProductContentBase"/>. /// </param> /// <returns> /// The modified <see cref="TRow"/>. /// </returns> public TRow OnCreate(TRow row, IProductContentBase baseContent) { return(row); }