Пример #1
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");
        }
Пример #2
0
        public override string FriendlyDescription(MerchantTribeApplication app)
        {
            string result = "";

            switch (HasMode)
            {
            case QualificationHasMode.HasAtLeast:
                result += "When order has AT LEAST ";
                break;
            }
            result += this.Quantity.ToString();
            switch (SetMode)
            {
            case QualificationSetMode.AllOfTheseItems:
                result += " of ALL of these products";
                break;

            case QualificationSetMode.AnyOfTheseItems:
                result += " of ANY of these products";
                break;
            }
            result += ":<ul>";

            foreach (string bvin in this.CurrentProductIds())
            {
                Catalog.Product p = app.CatalogServices.Products.Find(bvin);
                if (p != null)
                {
                    result += "<li>[" + p.Sku + "] " + p.ProductName + "</li>";
                }
            }
            result += "</ul>";
            return(result);
        }
Пример #3
0
 private void InventoryUpdateProductVisibleStatus(Catalog.Product product)
 {
     if (product == null)
     {
         return;
     }
     product.IsAvailableForSale = InventoryIsProductVisible(product);
 }
Пример #4
0
        public static string GenerateSwatchHtmlForProduct(Catalog.Product p, MerchantTribeApplication app)
        {
            string result = string.Empty;

            if (app.CurrentStore.Settings.ProductEnableSwatches == false)
            {
                return(result);
            }

            if (p.Options.Count > 0)
            {
                bool found = false;

                string swatchBase = MerchantTribe.Commerce.Storage.DiskStorage.BaseUrlForSingleStore(app, app.IsCurrentRequestSecure());
                swatchBase += "swatches";

                string swatchPhysicalBase = MerchantTribe.Commerce.Storage.DiskStorage.BaseStorePhysicalPath(app.CurrentStore.Id);
                swatchPhysicalBase += "swatches\\";

                StringBuilder sb = new StringBuilder();
                sb.Append("<div class=\"productswatches\">");
                foreach (var opt in p.Options)
                {
                    if (opt.Name.Trim().ToUpperInvariant() == "COLOR" ||
                        opt.Name.Trim().ToUpperInvariant() == "COLOR:")
                    {
                        found = true;
                        foreach (var oi in opt.Items)
                        {
                            if (oi.IsLabel)
                            {
                                continue;
                            }

                            string prefix = CleanSwatchName(oi.Name);

                            if (File.Exists(swatchPhysicalBase + prefix + ".png"))
                            {
                                sb.Append("<img width=\"18\" height=\"18\" src=\"" + swatchBase + "/" + prefix + ".png\" border=\"0\" alt=\"" + prefix + "\" />");
                            }
                            else
                            {
                                sb.Append("<img width=\"18\" height=\"18\" src=\"" + swatchBase + "/" + prefix + ".gif\" border=\"0\" alt=\"" + prefix + "\" />");
                            }
                        }
                    }
                }
                sb.Append("</div>");

                if (found == true)
                {
                    result = sb.ToString();
                }
            }

            return(result);
        }
Пример #5
0
        public static bool EmailLowStockReport(string recipientEmail, string storeName, MerchantTribeApplication app)
        {
            bool result = false;

            try
            {
                string fromAddress = string.Empty;
                fromAddress = recipientEmail;

                System.Net.Mail.MailMessage m = new System.Net.Mail.MailMessage(fromAddress, recipientEmail);
                m.IsBodyHtml = false;
                m.Subject    = "Low Stock Report From " + storeName;

                System.Text.StringBuilder sb = new System.Text.StringBuilder();

                sb.AppendLine("The following are low in stock or out of stock:");
                sb.Append(Environment.NewLine);

                List <Catalog.ProductInventory> inventories = app.CatalogServices.ProductInventories.FindAllLowStock();

                if (inventories.Count < 1)
                {
                    sb.Append("No out of stock items found.");
                }
                else
                {
                    foreach (Catalog.ProductInventory item in inventories)
                    {
                        Catalog.Product product = app.CatalogServices.Products.Find(item.ProductBvin);
                        if (product != null)
                        {
                            sb.Append(WebAppSettings.InventoryLowReportLinePrefix);
                            sb.Append(product.Sku);
                            sb.Append(", ");
                            sb.Append(product.ProductName);
                            sb.Append(", ");
                            sb.Append(item.QuantityOnHand);
                            sb.AppendLine(" ");
                        }
                    }
                }
                m.Body = sb.ToString();

                result = Utilities.MailServices.SendMail(m, app.CurrentStore);
            }

            catch (Exception ex)
            {
                EventLog.LogEvent(ex);
                result = false;
            }

            return(result);
        }
Пример #6
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);
        }
Пример #7
0
        public bool InventoryIsProductVisible(Catalog.Product product)
        {
            if (product.Status == ProductStatus.Disabled)
            {
                return(false);
            }
            else
            {
                if (product.InventoryMode == ProductInventoryMode.AlwayInStock)
                {
                    return(true);
                }
                else
                {
                    List <Catalog.ProductInventory> inv = ProductInventories.FindByProductId(product.Bvin);

                    // no inventory info so assume it's available
                    if (inv == null)
                    {
                        return(true);
                    }
                    if (inv.Count < 1)
                    {
                        return(true);
                    }

                    bool foundStock = false;
                    foreach (ProductInventory piv in inv)
                    {
                        if (piv.InventoryEvaluateStatus(product) == ProductInventoryStatus.Available)
                        {
                            return(true);
                        }
                        else
                        {
                            if (product.InventoryMode != ProductInventoryMode.WhenOutOfStockHide)
                            {
                                return(true);
                            }
                        }
                    }

                    if (!foundStock)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Пример #8
0
        public override string FriendlyDescription(MerchantTribeApplication app)
        {
            string result = "When Product is:<ul>";

            foreach (string bvin in this.CurrentProductIds())
            {
                Catalog.Product p = app.CatalogServices.Products.Find(bvin);
                if (p != null)
                {
                    result += "<li>[" + p.Sku + "] " + p.ProductName + "</li>";
                }
            }
            result += "</ul>";
            return(result);
        }
Пример #9
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;
 }
Пример #10
0
 public static bool IsProductSlugInUse(string slug, string bvin, MerchantTribeApplication app)
 {
     Catalog.Product p = app.CatalogServices.Products.FindBySlug(slug);
     if (p != null)
     {
         if (p.Bvin != string.Empty)
         {
             if (p.Bvin != bvin)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Пример #11
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>");
        }
Пример #12
0
        private void PriceForSelections(Catalog.Product p, OptionSelectionList selections)
        {
            this.IsValid              = true;
            this.VariantId            = string.Empty;
            this._ModifierAdjustments = 0;

            if (selections == null)
            {
                return;
            }
            if (p == null)
            {
                return;
            }

            // Check for Option Price Modifiers
            if (!p.HasOptions())
            {
                return;
            }
            this._ModifierAdjustments = selections.GetPriceAdjustmentForSelections(p.Options);
            this.BasePrice           += this._ModifierAdjustments;

            // Check for Variant Changes
            if (!p.HasVariants())
            {
                return;
            }
            Variant v = p.Variants.FindBySelectionData(selections, p.Options);

            if (v == null)
            {
                this.IsValid = false;
                return;
            }

            // Assign Variant Attributes to this price data
            this.VariantId = v.Bvin;
            if (v.Sku.Trim().Length > 0)
            {
                this.Sku = v.Sku;
            }
            if (v.Price >= 0)
            {
                this.BasePrice = v.Price + this._ModifierAdjustments;
            }
        }
Пример #13
0
        public static string BuildUrlForProduct(Catalog.Product p, System.Web.UI.Page page, string additionalParams)
        {
            string result = string.Empty;

            if (p != null)
            {
                result = page.GetRouteUrl("bvroute", new { slug = p.UrlSlug });
            }
            else
            {
                result = page.GetRouteUrl("bvroute", new { slug = "" });
            }


            if (additionalParams != string.Empty)
            {
                result = JoinUrlAndQuery(result, additionalParams);
            }

            return(result);
        }
Пример #14
0
        public static string BuildUrlForProduct(Catalog.Product p, System.Web.Routing.RequestContext routingContext, string additionalParams)
        {
            string result = string.Empty;

            RouteCollection r = System.Web.Routing.RouteTable.Routes;

            if (p != null)
            {
                result = r.GetVirtualPath(routingContext, "bvroute", new RouteValueDictionary(new { slug = p.UrlSlug })).VirtualPath.ToString();
            }
            else
            {
                result = r.GetVirtualPath(routingContext, "bvroute", new RouteValueDictionary(new { slug = "" })).VirtualPath.ToString();
            }

            if (additionalParams != string.Empty)
            {
                result = JoinUrlAndQuery(result, additionalParams);
            }

            return(result);
        }
Пример #15
0
        public ProductInventoryStatus InventoryEvaluateStatus(Catalog.Product p)
        {
            ProductInventoryStatus result = ProductInventoryStatus.Available;

            if (p != null)
            {
                if (p.Status == ProductStatus.Disabled)
                {
                    return(ProductInventoryStatus.NotAvailable);
                }
            }

            if (QuantityAvailableForSale <= 0)
            {
                if (p != null)
                {
                    switch (p.InventoryMode)
                    {
                    case ProductInventoryMode.AlwayInStock:
                        result = ProductInventoryStatus.Available;
                        break;

                    case ProductInventoryMode.WhenOutOfStockAllowBackorders:
                        result = ProductInventoryStatus.Available;
                        break;

                    case ProductInventoryMode.WhenOutOfStockShow:
                        result = ProductInventoryStatus.NotAvailable;
                        break;

                    case ProductInventoryMode.WhenOutOfStockHide:
                        result = ProductInventoryStatus.NotAvailable;
                        break;
                    }
                }
            }
            return(result);
        }
Пример #16
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");
        }
Пример #17
0
        public int InventoryReserveQuantity(string productBvin, string variantId, int quantity, bool ReserveZeroWhenQuantityTooLow)
        {
            Catalog.ProductInventory inv = ProductInventories.FindByProductIdAndVariantId(productBvin, variantId);

            // If no inventory, assume available
            if (inv == null)
            {
                return(quantity);
            }

            Catalog.Product prod = Products.Find(productBvin);
            if (prod != null)
            {
                if (prod.InventoryMode == ProductInventoryMode.AlwayInStock)
                {
                    return(quantity);
                }

                if (inv != null && inv.Bvin != string.Empty)
                {
                    switch (prod.InventoryMode)
                    {
                    case ProductInventoryMode.AlwayInStock:
                        inv.QuantityReserved += quantity;
                        ProductInventories.Update(inv);
                        return(quantity);

                    case ProductInventoryMode.WhenOutOfStockAllowBackorders:
                        inv.QuantityReserved += quantity;
                        ProductInventories.Update(inv);
                        return(quantity);

                    case ProductInventoryMode.WhenOutOfStockShow:
                        if (inv.QuantityAvailableForSale < quantity)
                        {
                            if (ReserveZeroWhenQuantityTooLow)
                            {
                                return(0);
                            }
                            else
                            {
                                inv.QuantityReserved += inv.QuantityAvailableForSale;
                                ProductInventories.Update(inv);
                                return(inv.QuantityAvailableForSale);
                            }
                        }
                        else
                        {
                            inv.QuantityReserved += quantity;
                            ProductInventories.Update(inv);
                            return(quantity);
                        }

                    case ProductInventoryMode.WhenOutOfStockHide:
                        if (inv.QuantityAvailableForSale < quantity)
                        {
                            if (ReserveZeroWhenQuantityTooLow)
                            {
                                return(0);
                            }
                            else
                            {
                                inv.QuantityReserved += inv.QuantityAvailableForSale;
                                ProductInventories.Update(inv);
                                return(inv.QuantityAvailableForSale);
                            }
                        }
                        else
                        {
                            inv.QuantityReserved += quantity;
                            ProductInventories.Update(inv);
                            return(quantity);
                        }
                    }
                    return(0);
                }
                else
                {
                    if (prod != null)
                    {
                        if (prod.InventoryMode == ProductInventoryMode.AlwayInStock)
                        {
                            return(0);
                        }
                        else
                        {
                            return(quantity);
                        }
                    }
                    else
                    {
                        return(0);
                    }
                }
            }

            return(0);
        }
Пример #18
0
        public string Process(MerchantTribeApplication app, Dictionary <string, ITagHandler> handlers, ParsedTag tag, string contents)
        {
            StringBuilder sb = new StringBuilder();

            string mode  = tag.GetSafeAttribute("mode");
            string href  = string.Empty;
            string sysid = tag.GetSafeAttribute("sysid");

            switch (mode.Trim().ToLowerInvariant())
            {
            case "home":
                href = app.CurrentStore.RootUrl();
                break;

            case "checkout":
                href = app.CurrentStore.RootUrlSecure() + "checkout";
                if (contents == string.Empty)
                {
                    contents = "<span>Checkout</span>";
                }
                break;

            case "cart":
                href = app.CurrentStore.RootUrl() + "cart";
                if (contents == string.Empty)
                {
                    string itemCount = "0";
                    string subTotal  = "$0.00";

                    if (SessionManager.CurrentUserHasCart(app.CurrentStore))
                    {
                        itemCount = SessionManager.GetCookieString(WebAppSettings.CookieNameCartItemCount(app.CurrentStore.Id), app.CurrentStore);
                        subTotal  = SessionManager.GetCookieString(WebAppSettings.CookieNameCartSubTotal(app.CurrentStore.Id), app.CurrentStore);
                        if (itemCount.Trim().Length < 1)
                        {
                            itemCount = "0";
                        }
                        if (subTotal.Trim().Length < 1)
                        {
                            subTotal = "$0.00";
                        }
                    }

                    contents = "<span>View Cart: " + itemCount + " items</span>";
                }
                break;

            case "category":
                Catalog.Category cat = app.CatalogServices.Categories.Find(sysid);
                href = app.CurrentStore.RootUrl() + cat.RewriteUrl;
                break;

            case "product":
                Catalog.Product p = app.CatalogServices.Products.Find(sysid);
                href = app.CurrentStore.RootUrl() + p.UrlSlug;
                break;

            case "":
                string temp = tag.GetSafeAttribute("href");
                if (temp.StartsWith("http://") || temp.StartsWith("https://"))
                {
                    href = temp;
                }
                else
                {
                    href = app.CurrentStore.RootUrl() + temp.TrimStart('/');
                }
                break;

            case "myaccount":
                href = app.CurrentStore.RootUrlSecure() + "account";
                if (contents == string.Empty)
                {
                    contents = "<span>My Account</span>";
                }
                break;

            case "signin":
                string currentUserId = SessionManager.GetCurrentUserId(app.CurrentStore);
                if (currentUserId == string.Empty)
                {
                    href = app.CurrentStore.RootUrlSecure() + "signin";
                    if (contents == string.Empty)
                    {
                        contents = "<span>Sign In</span>";
                    }
                }
                else
                {
                    href = app.CurrentStore.RootUrlSecure() + "signout";
                    if (contents == string.Empty)
                    {
                        contents = "<span>Sign Out</span>";
                    }
                }

                break;
            }

            if (href.Trim().Length > 0)
            {
                sb.Append("<a href=\"" + href + "\"");

                PassAttribute(ref sb, tag, "id");
                PassAttribute(ref sb, tag, "title");
                PassAttribute(ref sb, tag, "style");
                PassAttribute(ref sb, tag, "class");
                PassAttribute(ref sb, tag, "dir");
                PassAttribute(ref sb, tag, "lang");
                PassAttribute(ref sb, tag, "target");
                PassAttribute(ref sb, tag, "rel");
                PassAttribute(ref sb, tag, "media");
                PassAttribute(ref sb, tag, "hreflang");
                PassAttribute(ref sb, tag, "type");
                PassAttribute(ref sb, tag, "name");

                sb.Append(">" + contents + "</a>");
            }
            return(sb.ToString());
        }
Пример #19
0
 // Products
 public static void AddProduct(Catalog.Product p)
 {
     StoreItem <Catalog.Product>("product-" + p.Bvin + "-" + p.StoreId, p, 60);
 }
Пример #20
0
        private void ApplyVolumeDiscounts(Order o)
        {
            // Count up how many of each item in order
            List <string>            products   = new List <string>();
            Dictionary <string, int> quantities = new Dictionary <string, int>();

            foreach (LineItem item in o.Items)
            {
                if (!products.Contains(item.ProductId))
                {
                    products.Add(item.ProductId);
                }
                if (quantities.ContainsKey(item.ProductId))
                {
                    quantities[item.ProductId] += (int)item.Quantity;
                }
                else
                {
                    quantities.Add(item.ProductId, (int)item.Quantity);
                }
            }

            // Check for discounts on each item
            foreach (string id in products)
            {
                List <MerchantTribe.Commerce.Catalog.ProductVolumeDiscount> volumeDiscounts = _app.CatalogServices.VolumeDiscounts.FindByProductId(id);
                int quantity = quantities[id];
                MerchantTribe.Commerce.Catalog.ProductVolumeDiscount volumeDiscountToApply = null;
                if (volumeDiscounts.Count > 0)
                {
                    // Locate the correct discount in the chart of discounts
                    foreach (MerchantTribe.Commerce.Catalog.ProductVolumeDiscount volumeDiscount in volumeDiscounts)
                    {
                        if (quantity >= volumeDiscount.Qty)
                        {
                            volumeDiscountToApply = volumeDiscount;
                        }
                    }
                    //now we have to go through the entire order and discount all items
                    //that are this id
                    if (volumeDiscountToApply != null)
                    {
                        foreach (LineItem item in o.Items)
                        {
                            if (item.ProductId == id)
                            {
                                Catalog.Product p = _app.CatalogServices.Products.Find(item.ProductId);
                                if (p != null)
                                {
                                    bool alreadyDiscounted = (p.SitePrice > item.AdjustedPricePerItem);
                                    if (!alreadyDiscounted)
                                    {
                                        // item isn't discounted yet so apply the exact price the merchant set
                                        decimal toDiscount = -1 * (item.AdjustedPricePerItem - volumeDiscountToApply.Amount);
                                        toDiscount = toDiscount * item.Quantity;
                                        item.DiscountDetails.Add(new Marketing.DiscountDetail()
                                        {
                                            Amount = toDiscount, Description = "Volume Discount"
                                        });
                                    }
                                    else
                                    {
                                        // item is already discounted (probably by user group) so figure out
                                        // the percentage of volume discount instead
                                        decimal originalPriceChange = p.SitePrice - volumeDiscountToApply.Amount;
                                        decimal percentChange       = originalPriceChange / p.SitePrice;
                                        decimal newDiscount         = -1 * (percentChange * item.AdjustedPricePerItem);
                                        newDiscount = newDiscount * item.Quantity;
                                        item.DiscountDetails.Add(new Marketing.DiscountDetail()
                                        {
                                            Amount = newDiscount, Description = percentChange.ToString("p0") + " Volume Discount"
                                        });
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #21
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");
        }
Пример #22
0
        public List <Content.HtmlTemplateTag> GetReplaceableTags(MerchantTribeApplication app)
        {
            List <Content.HtmlTemplateTag> result = new List <Content.HtmlTemplateTag>();

            result.Add(new Content.HtmlTemplateTag("[[Package.ShipDate]]", this.ShipDateUtc.ToString("d")));

            if (this.TrackingNumber == string.Empty)
            {
                result.Add(new Content.HtmlTemplateTag("[[Package.TrackingNumber]]", "None Available"));
            }
            else
            {
                result.Add(new Content.HtmlTemplateTag("[[Package.TrackingNumber]]", this.TrackingNumber));
            }

            bool tagsEntered = false;

            MerchantTribe.Commerce.Accounts.Store currentStore = app.CurrentRequestContext.CurrentStore;
            foreach (MerchantTribe.Shipping.IShippingService item in Shipping.AvailableServices.FindAll(currentStore))
            {
                if (item.Id.ToString() == this.ShippingProviderId)
                {
                    tagsEntered = true;
                    //Orders.Order order = Orders.Order.FindByBvin(this.OrderId);
                    //if (order != null && order.Bvin != string.Empty)
                    //{
                    //    //if (item.SupportsTracking()) {
                    //    //    if (this.TrackingNumber.Trim() != string.Empty) {
                    //    //        result.Add(new Content.EmailTemplateTag("[[Package.TrackingNumberLink]]", item.GetTrackingUrl(this.TrackingNumber)));
                    //    //    }
                    //    //    else {
                    //    //result.Add(new Content.EmailTemplateTag("[[Package.TrackingNumberLink]]", ""));
                    //    //    }
                    //    //}
                    //    //else {
                    //    result.Add(new Content.EmailTemplateTag("[[Package.TrackingNumberLink]]", ""));
                    //    //}
                    //}

                    result.Add(new Content.HtmlTemplateTag("[[Package.ShipperName]]", item.Name));
                    List <MerchantTribe.Shipping.IServiceCode> serviceCodes = item.ListAllServiceCodes();
                    bool shipperServiceFound = false;
                    foreach (MerchantTribe.Shipping.IServiceCode serviceCode in serviceCodes)
                    {
                        if (string.Compare(this.ShippingProviderServiceCode, serviceCode.Code, true) == 0)
                        {
                            shipperServiceFound = true;
                            result.Add(new Content.HtmlTemplateTag("[[Package.ShipperService]]", serviceCode.DisplayName));
                            break;
                        }
                    }

                    if (!shipperServiceFound)
                    {
                        result.Add(new Content.HtmlTemplateTag("[[Package.ShipperService]]", ""));
                    }
                }
            }

            if ((this.Items != null) && (this.Items.Count > 0))
            {
                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                sb.Append("<table class=\"packageitems\">");
                sb.Append("<tr>");
                sb.Append("<td class=\"itemnamehead\">Name</td>");
                sb.Append("<td class=\"itemquantityhead\">Quantity</td>");
                sb.Append("</tr>");
                //sb.Append("<ul>")
                int count = 0;
                foreach (OrderPackageItem item in this.Items)
                {
                    if (item.Quantity > 0)
                    {
                        if (count % 2 == 0)
                        {
                            sb.Append("<tr>");
                        }
                        else
                        {
                            sb.Append("<tr class=\"alt\">");
                        }

                        //sb.Append("<li>")
                        Catalog.Product prod = app.CatalogServices.Products.Find(item.ProductBvin);
                        if (prod != null)
                        {
                            sb.Append("<td class=\"itemname\">");
                            sb.Append(prod.ProductName);
                            sb.Append("</td>");
                            sb.Append("<td class=\"itemquantity\">");
                            sb.Append(item.Quantity.ToString());
                            sb.Append("</td>");
                        }
                        //sb.Append("</li>")
                        sb.Append("</tr>");
                        count += 1;
                    }
                }
                sb.Append("</table>");

                //sb.Append("</ul>")
                result.Add(new Content.HtmlTemplateTag("[[Package.Items]]", sb.ToString()));
            }
            else
            {
                result.Add(new Content.HtmlTemplateTag("[[Package.Items]]", ""));
            }

            //these are only here so that they get added to the list of available tags
            if (!tagsEntered)
            {
                result.Add(new Content.HtmlTemplateTag("[[Package.TrackingNumberLink]]", ""));
                result.Add(new Content.HtmlTemplateTag("[[Package.ShipperName]]", ""));
                result.Add(new Content.HtmlTemplateTag("[[Package.ShipperService]]", ""));
            }

            return(result);
        }
Пример #23
0
 // Products
 public void IndexSingleProduct(Catalog.Product p)
 {
     MerchantTribe.Web.Search.Indexers.ComplexIndexer indexer = new MerchantTribe.Web.Search.Indexers.ComplexIndexer(searcher);
     IndexProduct(p, indexer);
 }
Пример #24
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");
        }
Пример #25
0
 public void UpdateProductVisibleStatusAndSave(Catalog.Product p)
 {
     InventoryUpdateProductVisibleStatus(p);
     Products.Update(p);
 }
Пример #26
0
 public static string BuildUrlForProduct(Catalog.Product p, System.Web.UI.Page page)
 {
     return(BuildUrlForProduct(p, page, string.Empty));
 }