private void RenderPrices(ProductPageViewModel model) { string userId = MTApp.CurrentCustomerId; StringBuilder sb = new StringBuilder(); sb.Append("<div class=\"prices\">"); UserSpecificPrice productDisplay = MTApp.PriceProduct(model.LocalProduct, MTApp.CurrentCustomer, null, MTApp.CurrentlyActiveSales); if (productDisplay.ListPriceGreaterThanCurrentPrice) { sb.Append("<label>" + SiteTerms.GetTerm(SiteTermIds.ListPrice) + "</label>"); sb.Append("<span class=\"choice\"><strike>"); sb.Append(model.LocalProduct.ListPrice.ToString("C")); sb.Append("</strike></span>"); } sb.Append("<label>" + SiteTerms.GetTerm(SiteTermIds.SitePrice) + "</label>"); sb.Append("<span class=\"choice\">"); sb.Append(productDisplay.DisplayPrice()); sb.Append("</span>"); if ((productDisplay.BasePrice < productDisplay.ListPrice) && (productDisplay.OverrideText.Trim().Length < 1)) { sb.Append("<label>" + SiteTerms.GetTerm(SiteTermIds.YouSave) + "</label>"); sb.Append("<span class=\"choice\">"); sb.Append(productDisplay.Savings.ToString("c") + " - " + productDisplay.SavingsPercent + System.Threading.Thread.CurrentThread.CurrentUICulture.NumberFormat.PercentSymbol); sb.Append("</span>"); } sb.Append("<div class=\"clear\"></div></div>"); model.PreRenderedPrices = sb.ToString(); }
public void Promotion_CanPutAProductOnSale() { //InitBasicStubs(); var app = CreateHccAppInMemory(); var p = new Promotion(); p.IsEnabled = true; p.Name = "Product Sale Test"; p.CustomerDescription = "A Customer Discount"; p.StartDateUtc = DateTime.UtcNow.AddDays(-1); p.EndDateUtc = DateTime.UtcNow.AddDays(1); p.StoreId = 1; p.Id = 1; var prod = new Product(); prod.Bvin = "553690e2-6372-431f-97c0-83e11a05f298"; prod.SitePrice = 59.99m; app.CatalogServices.Products.Create(prod); Assert.IsTrue(p.AddQualification(new ProductBvin(prod.Bvin)), "Add Qualification Failed"); Assert.IsTrue(p.AddAction(new ProductPriceAdjustment(AmountTypes.MonetaryAmount, -20m)), "Add Action Failed"); var userPrice = new UserSpecificPrice(prod, null, app.CurrentStore.Settings); var actual = p.ApplyToProduct(app.CurrentRequestContext, prod, userPrice, null); Assert.IsTrue(actual, "Promotion should have applied with return value of true"); Assert.AreEqual(39.99m, userPrice.PriceWithAdjustments(), "Price should have been reduced by $20.00"); Assert.AreEqual(p.CustomerDescription, userPrice.DiscountDetails[0].Description, "Description should match promotion"); }
/// <summary> /// Applies to product. /// </summary> /// <param name="requestContext">The request context.</param> /// <param name="p">The p.</param> /// <param name="price">The price.</param> /// <param name="account">The account.</param> /// <returns></returns> public bool ApplyToProduct(HccRequestContext requestContext, Product p, UserSpecificPrice price, CustomerAccount account) { if (requestContext == null) { return(false); } if (p == null) { return(false); } if (price == null) { return(false); } var context = new PromotionContext(requestContext, Mode, Id) { Product = p, UserPrice = price, CurrentCustomer = account, CustomerDescription = CustomerDescription }; return(ApplyPromotion(context, PromotionQualificationMode.Products)); }
/// <summary> /// Generate the different type of price information for the product /// </summary> /// <param name="price"> /// User specific price information based on the chosen option for the product on the product detail /// page /// </param> public ProductPrices(UserSpecificPrice price) { if (price.ListPriceGreaterThanCurrentPrice) { ListPrice = new PriceData { Label = GlobalLocalization.GetString("ListPrice"), Text = price.ListPrice.ToString("C"), RawValue = price.ListPrice.ToString("F") }; } SitePrice = new PriceData { Label = GlobalLocalization.GetString("SitePrice"), Text = price.DisplayPrice(true, false), RawValue = price.DisplayPrice(true, false) }; if (price.BasePrice < price.ListPrice && price.OverrideText.Trim().Length < 1) { YouSave = new PriceData { Label = GlobalLocalization.GetString("YouSave"), Text = string.Format("{0} - {1}{2}", price.Savings.ToString("c"), price.SavingsPercent, Thread.CurrentThread.CurrentUICulture.NumberFormat.PercentSymbol), RawValue = price.SavingsPercent.ToString("N") }; } }
private void SetProducts(ContentBlockSettingListItem data) { string bvin = data.Setting1; Product p = MyPage.MTApp.CatalogServices.Products.Find(bvin); StringBuilder sb = new StringBuilder(); UserSpecificPrice price = MyPage.MTApp.PriceProduct(p, MyPage.MTApp.CurrentCustomer, null); HtmlRendering.RenderSingleProduct(ref sb, p, false, false, this.Page, price); this.litMain.Text = sb.ToString(); }
private void CheckForPricesBelowZero(UserSpecificPrice price) { var final = price.PriceWithAdjustments(); if (final < 0) { var tweak = -1 * final; price.AddAdjustment(tweak, "Price can not be below zero"); } }
public ActionResult Validate() { ProductValidateResponse result = new ProductValidateResponse(); string bvin = Request.Form["productbvin"]; Product p = MTApp.CatalogServices.Products.Find(bvin); if ((p != null)) { OptionSelectionList selections = ParseSelections(p); UserSpecificPrice price = MTApp.PriceProduct(p, MTApp.CurrentCustomer, selections); result.Price = MerchantTribe.Commerce.Utilities.HtmlRendering.UserSpecificPriceForDisplay(price); result.Sku = price.Sku; result.ImageUrl = MerchantTribe.Commerce.Storage.DiskStorage.ProductImageUrlMedium(MTApp, p.Bvin, p.ImageFileSmall, false); result.IsValid = price.IsValid; if (result.IsValid) { result.Message = string.Empty; } else { result.Message = "<div class=\"flash-message-warning\">The combination of options you've selected isn't available at the moment. Please select different options.</div>"; } if (price.VariantId.Length > 0) { result.ImageUrl = MerchantTribe.Commerce.Storage.DiskStorage.ProductVariantImageUrlMedium(MTApp, p.Bvin, p.ImageFileSmall, price.VariantId, false); } // Make sure we have stock on the product or variant InventoryCheckData data = MTApp.CatalogServices.InventoryCheck(p, price.VariantId); result.StockMessage = data.InventoryMessage; if (result.IsValid) { if (!data.IsAvailableForSale) { result.IsValid = false; // Should this be here? //result.Message = "Out of stock?"; } } // Make sure no "labels" are selected if (selections.HasLabelsSelected()) { result.IsValid = false; result.Message = "<div class=\"flash-message-warning\">Please make all selections before adding to cart.</div>"; } } return(new PreJsonResult(MerchantTribe.Web.Json.ObjectToJson(result))); }
private void ApplySales(UserSpecificPrice price, Product p, CustomerAccount currentUser, List <Promotion> sales) { if (sales == null) { return; } foreach (var promo in sales) { promo.ApplyToProduct(CurrentRequestContext, p, price, currentUser); } }
public UserSpecificPrice PriceProduct(Product p, CustomerAccount currentUser, OptionSelections selections, List <Promotion> currentSales) { if (p == null) { return(null); } var result = new UserSpecificPrice(p, selections, CurrentStore.Settings); AdjustProductPriceForUser(result, p, currentUser); ApplySales(result, p, currentUser, currentSales); CheckForPricesBelowZero(result); return(result); }
private void AdjustProductPriceForUser(UserSpecificPrice price, Product p, CustomerAccount currentUser) { if (currentUser == null) { return; } if (currentUser.Bvin == string.Empty) { return; } if (currentUser.PricingGroupId == string.Empty) { return; } if (p == null) { return; } if (price == null) { return; } var startingPrice = price.PriceWithAdjustments(); var pricingGroup = ContactServices.PriceGroups.Find(currentUser.PricingGroupId); if (pricingGroup == null) { return; } var nonGroupPrice = price.BasePrice; var groupPrice = nonGroupPrice; //groupPrice = pricingGroup.GetAdjustedPriceForThisGroup(p.SitePrice, p.ListPrice, p.SiteCost); groupPrice = pricingGroup.GetAdjustedPriceForThisGroup(startingPrice, p.ListPrice, p.SiteCost); var amountOfDiscount = groupPrice - nonGroupPrice; price.AddAdjustment(amountOfDiscount, "Price Group"); }
private void UpdateVariantImage(ProductValidateResponse validateResult, Product product, UserSpecificPrice price) { if (!string.IsNullOrEmpty(price.VariantId)) { validateResult.MediumImageUrl = DiskStorage.ProductVariantImageUrlMedium(HccApp, product.Bvin, product.ImageFileMedium, price.VariantId, false); validateResult.OriginalImageUrl = DiskStorage.ProductVariantImageUrlOriginal(HccApp, product.Bvin, product.ImageFileMedium, price.VariantId, false); } else { validateResult.MediumImageUrl = DiskStorage.ProductImageUrlMedium(HccApp, product.Bvin, product.ImageFileMedium, false); validateResult.OriginalImageUrl = DiskStorage.ProductImageUrlOriginal(HccApp, product.Bvin, product.ImageFileMedium, false); } }
private void ValidatePrice(ProductValidateResponse validateResult, UserSpecificPrice price) { validateResult.Prices = new ProductPrices(price); validateResult.Sku = price.Sku; validateResult.IsValid &= price.IsValid; }
public bool ApplyToProduct(HotcakesApplication app, Product p, UserSpecificPrice price, CustomerAccount account) { return(ApplyToProduct(app.CurrentRequestContext, p, price, account)); }