/// <summary> /// Set default values using parameterized constructor /// <remarks> /// This generally called from the products controller to set proper urls and product link for the bundled product /// </remarks> /// </summary> /// <param name="bp">Parameter passed for existing BundledProduct object</param> /// <param name="hccApp">An instance of the Hotcakes Application context.</param> public BundledProductViewModel(BundledProductAdv bp, HotcakesApplication hccApp) { BundledProductAdv = bp; Item = bp.BundledProduct; ProductLink = UrlRewriter.BuildUrlForProduct(BundledProductAdv.BundledProduct); ImageUrls = new ProductImageUrls(); ImageUrls.LoadProductImageUrls(hccApp, BundledProductAdv.BundledProduct); SwatchDisplay = ImageHelper.GenerateSwatchHtmlForProduct(BundledProductAdv.BundledProduct, hccApp); }
private int CalculateProductQuantity(PromotionContext context, BundledProductAdv prod, OptionSelectionList osl, int mainQuantity) { var quantity = mainQuantity; foreach (var item in context.Order.Items) { if (item.IsBundle) { var p = context.HccApp.CatalogServices.Products.FindWithCache(item.ProductId); var prods = p.BundledProducts.Where( pr => pr.BundledProduct != null && pr.BundledProduct.Bvin.ToLowerInvariant() == prod.ProductId.ToLowerInvariant()).ToList(); foreach (var bundledProd in prods) { var options = item.SelectionData.GetSelections(bundledProd.Id); if (osl.Equals(options)) { quantity = Math.Max(quantity, bundledProd.Quantity); } } } else { if (item.ProductId.ToLowerInvariant() == prod.BundledProduct.Bvin.ToLowerInvariant() && item.SelectionData.OptionSelectionList.Equals(osl)) { quantity += item.Quantity; } } } return(quantity); }