예제 #1
0
        public static string UserSpecificPriceForDisplay(Catalog.UserSpecificPrice price)
        {
            StringBuilder sb = new StringBuilder();

            if (price.ListPriceGreaterThanCurrentPrice)
            {
                sb.Append("<label>" + Content.SiteTerms.GetTerm(Content.SiteTermIds.ListPrice) + "</label>");
                sb.Append("<span class=\"choice\"><strike>");
                sb.Append(price.ListPrice.ToString("C"));
                sb.Append("</strike></span>");
            }

            sb.Append("<label>" + Content.SiteTerms.GetTerm(Content.SiteTermIds.SitePrice) + "</label>");
            sb.Append("<span class=\"choice\">");
            sb.Append(price.DisplayPrice());
            sb.Append("</span>");

            if ((price.BasePrice < price.ListPrice) && (price.OverrideText.Trim().Length < 1))
            {
                sb.Append("<label>" + Content.SiteTerms.GetTerm(Content.SiteTermIds.YouSave) + "</label>");
                sb.Append("<span class=\"choice\">");
                sb.Append(price.Savings.ToString("c")
                          + " - "
                          + price.SavingsPercent
                          + System.Threading.Thread.CurrentThread.CurrentUICulture.NumberFormat.PercentSymbol);
                sb.Append("</span>");
            }

            sb.Append("<div class=\"clear\"></div>");

            return(sb.ToString());
        }
예제 #2
0
        public void CanPutAProductOnSale()
        {
            Promotion p = new Promotion();

            p.IsEnabled           = true;
            p.Name                = "Product Sale Test";
            p.CustomerDescription = "A Customer Discount";
            p.StartDateUtc        = DateTime.Now.AddDays(-1);
            p.EndDateUtc          = DateTime.Now.AddDays(1);
            p.StoreId             = 1;
            p.Id = 1;
            Assert.IsTrue(p.AddQualification(new ProductBvin("bvin1234")), "Add Qualification Failed");
            Assert.IsTrue(p.AddAction(new ProductPriceAdjustment(AmountTypes.MonetaryAmount, -20m)), "Add Action Failed");

            Catalog.Product prod = new Catalog.Product();
            prod.Bvin      = "bvin1234";
            prod.SitePrice = 59.99m;
            prod.StoreId   = 1;

            Catalog.UserSpecificPrice userPrice = new Catalog.UserSpecificPrice(prod, null);

            RequestContext           c   = new RequestContext();
            MerchantTribeApplication app = MerchantTribeApplication.InstantiateForMemory(c);

            bool actual = p.ApplyToProduct(app, prod, userPrice, null, DateTime.UtcNow);

            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");
        }
예제 #3
0
 private void RepriceItemsForUser(Order o)
 {
     foreach (LineItem li in o.Items)
     {
         Catalog.UserSpecificPrice price = _app.PriceProduct(li.ProductId, o.UserID, li.SelectionData);
         // Null check because if the item isn't in the catalog
         // we will get back a null user specific price.
         //
         // In the future it may be a good idea to add an option
         // allowing merchant to select if they would like to allow
         // items not in the catalog to exist in carts or if we should
         // just remove items from the cart with a warning here.
         if (price != null)
         {
             li.BasePricePerItem = price.BasePrice;
             foreach (Marketing.DiscountDetail discount in price.DiscountDetails)
             {
                 li.DiscountDetails.Add(new Marketing.DiscountDetail()
                 {
                     Amount = discount.Amount * li.Quantity, Description = discount.Description
                 });
             }
         }
     }
 }
예제 #4
0
        public bool ApplyToProduct(MerchantTribeApplication app,
                                   Catalog.Product p,
                                   Catalog.UserSpecificPrice price,
                                   Membership.CustomerAccount currentCustomer,
                                   DateTime currentDateTimeUtc)
        {
            if (app == null)
            {
                return(false);
            }
            if (p == null)
            {
                return(false);
            }
            if (price == null)
            {
                return(false);
            }
            if (currentDateTimeUtc == null)
            {
                return(false);
            }

            PromotionContext context = new PromotionContext(app, p, price, currentCustomer, currentDateTimeUtc);

            context.CustomerDescription = this.CustomerDescription;

            // Make sure we have an active promotion before applying
            if (GetStatus(context.CurrentDateAndTimeUtc) != PromotionStatus.Active)
            {
                return(false);
            }

            // Make sure we meet all requirements
            // NOTE: we order by processing cost which should allow us to check
            // the fastest items first. For example, checking userID is faster
            // than checking user group because ID is in the context and group
            // requires a database call.
            foreach (IPromotionQualification q in this._Qualifications.OrderBy(y => y.ProcessingCost))
            {
                if (!q.MeetsQualification(context))
                {
                    return(false);
                }
            }

            // We're qualified, do actions
            foreach (IPromotionAction a in this._Actions)
            {
                a.ApplyAction(context, PromotionActionMode.Unknown);
            }

            return(true);
        }
예제 #5
0
 public PromotionContext(MerchantTribeApplication app,
                         Catalog.Product p,
                         Catalog.UserSpecificPrice up,
                         Membership.CustomerAccount currentUser,
                         DateTime currentTimeUtc)
 {
     this.CustomerDescription = string.Empty;
     this.Mode                  = PromotionType.Sale;
     this.MTApp                 = app;
     this.Order                 = null;
     this.Product               = p;
     this.UserPrice             = up;
     this.CurrentDateAndTimeUtc = DateTime.UtcNow;
     this.CurrentCustomer       = currentUser;
 }
예제 #6
0
        public static void RenderSingleProduct(ref StringBuilder sb,
                                               Catalog.Product p,
                                               bool isLastInRow,
                                               bool isFirstInRow,
                                               System.Web.UI.Page page,
                                               Catalog.UserSpecificPrice price)
        {
            string destinationLink = Utilities.UrlRewriter.BuildUrlForProduct(p, page);

            string imageUrl
                = MerchantTribe.Commerce.Storage.DiskStorage.ProductImageUrlSmall(
                      ((IMultiStorePage)page).MTApp,
                      p.Bvin,
                      p.ImageFileSmall,
                      page.Request.IsSecureConnection);

            if (isLastInRow)
            {
                sb.Append("<div class=\"record lastrecord\">");
            }
            else if (isFirstInRow)
            {
                sb.Append("<div class=\"record firstrecord\">");
            }
            else
            {
                sb.Append("<div class=\"record\">");
            }


            sb.Append("<div class=\"recordimage\">");
            sb.Append("<a href=\"" + destinationLink + "\">");
            sb.Append("<img src=\"" + imageUrl + "\" border=\"0\" alt=\"" + p.ImageFileSmallAlternateText + "\" /></a>");
            sb.Append("</div>");

            sb.Append("<div class=\"recordname\">");
            sb.Append("<a href=\"" + destinationLink + "\">" + p.ProductName + "</a>");
            sb.Append("</div>");
            sb.Append("<div class=\"recordsku\">");
            sb.Append("<a href=\"" + destinationLink + "\">" + p.Sku + "</a>");
            sb.Append("</div>");
            sb.Append("<div class=\"recordprice\">");
            sb.Append("<a href=\"" + destinationLink + "\">" + price.DisplayPrice(true) + "</a>");
            sb.Append("</div>");

            sb.Append("</div>");
        }
예제 #7
0
        public void CanPutAProductOnSalePricedByApp()
        {
            RequestContext           c   = new RequestContext();
            MerchantTribeApplication app = MerchantTribeApplication.InstantiateForMemory(c);

            app.CurrentStore    = new Accounts.Store();
            app.CurrentStore.Id = 1;

            // Create a Promotion to Test
            Promotion p = new Promotion();

            p.Mode                = PromotionType.Sale;
            p.IsEnabled           = true;
            p.Name                = "Product Sale Test";
            p.CustomerDescription = "$10.00 off Test Sale!";
            p.StartDateUtc        = DateTime.Now.AddDays(-1);
            p.EndDateUtc          = DateTime.Now.AddDays(1);
            p.StoreId             = 1;
            p.Id = 0;
            p.AddQualification(new ProductBvin("bvin1234"));
            p.AddAction(new ProductPriceAdjustment(AmountTypes.MonetaryAmount, -10m));
            app.MarketingServices.Promotions.Create(p);

            // Create a test Product
            Catalog.Product prod = new Catalog.Product();
            prod.Bvin      = "bvin1234";
            prod.SitePrice = 59.99m;
            prod.StoreId   = 1;

            Catalog.UserSpecificPrice actualPrice = app.PriceProduct(prod, null, null);

            Assert.IsNotNull(actualPrice, "Price should not be null");
            Assert.AreEqual(49.99m, actualPrice.PriceWithAdjustments(), "Price should be $49.99");
            Assert.AreEqual(1, actualPrice.DiscountDetails.Count, "Discount Details count should be one");
            Assert.AreEqual(p.CustomerDescription, actualPrice.DiscountDetails[0].Description, "Description should match promotion");
        }
예제 #8
0
        public void CanPutAProductOnSale()
        {
            Promotion p = new Promotion();
            p.IsEnabled = true;
            p.Name = "Product Sale Test";
            p.CustomerDescription = "A Customer Discount";
            p.StartDateUtc = DateTime.Now.AddDays(-1);
            p.EndDateUtc = DateTime.Now.AddDays(1);
            p.StoreId = 1;
            p.Id = 1;
            Assert.IsTrue(p.AddQualification(new ProductBvin("bvin1234")), "Add Qualification Failed");
            Assert.IsTrue(p.AddAction(new ProductPriceAdjustment(AmountTypes.MonetaryAmount, -20m)), "Add Action Failed");

            Catalog.Product prod = new Catalog.Product();
            prod.Bvin = "bvin1234";
            prod.SitePrice = 59.99m;
            prod.StoreId = 1;

            Catalog.UserSpecificPrice userPrice = new Catalog.UserSpecificPrice(prod, null);

            RequestContext c = new RequestContext();
            MerchantTribeApplication app = MerchantTribeApplication.InstantiateForMemory(c);

            bool actual = p.ApplyToProduct(app, prod, userPrice, null, DateTime.UtcNow);

            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");
        }