Esempio n. 1
0
        protected void Page_Init(object sender, EventArgs e)
        {
            _ProductId = AlwaysConvert.ToInt(Request.QueryString["ProductId"]);
            _Product   = ProductDataSource.Load(_ProductId);
            if (_Product != null)
            {
                if (_Product.VolumeDiscounts.Count > 0)
                {
                    _VolumeDiscountId = _Product.VolumeDiscounts[0].Id;
                    _VolumeDiscount   = _Product.VolumeDiscounts[0];
                    _IsAdd            = false;
                }
                else
                {
                    _IsAdd               = true;
                    _VolumeDiscount      = new VolumeDiscount();
                    _VolumeDiscount.Name = _Product.Name;
                    _VolumeDiscount.Products.Add(_Product);
                    _VolumeDiscount.Save();
                    _VolumeDiscountId = _VolumeDiscount.Id;
                    VolumeDiscountLevel newDiscountLevel = new VolumeDiscountLevel();
                    _VolumeDiscount.Levels.Add(newDiscountLevel);
                }

                DiscountLevelGrid.DataSource = _VolumeDiscount.Levels;
                DiscountLevelGrid.DataBind();
            }
        }
Esempio n. 2
0
        private void SaveDiscount()
        {
            VolumeDiscount discount = _VolumeDiscount;

            discount.Name = _Product.Name;
            //LOOP THROUGH GRID ROWS AND SET MATRIX
            int rowIndex = 0;

            foreach (GridViewRow row in DiscountLevelGrid.Rows)
            {
                if (discount.Levels.Count < (rowIndex + 1))
                {
                    // ADD A NEW DISCOUNT LEVEL FOR NEW ROWS
                    VolumeDiscountLevel newDiscountLevel = new VolumeDiscountLevel();
                    newDiscountLevel.VolumeDiscountId = _VolumeDiscountId;
                    discount.Levels.Add(newDiscountLevel);
                }
                decimal             minValue       = AlwaysConvert.ToDecimal(((TextBox)row.FindControl("MinValue")).Text);
                decimal             maxValue       = AlwaysConvert.ToDecimal(((TextBox)row.FindControl("MaxValue")).Text);
                decimal             discountAmount = AlwaysConvert.ToDecimal(((TextBox)row.FindControl("DiscountAmount")).Text);
                bool                isPercent      = false;
                VolumeDiscountLevel thisLevel      = discount.Levels[rowIndex];
                thisLevel.MinValue       = minValue;
                thisLevel.MaxValue       = maxValue;
                thisLevel.DiscountAmount = discountAmount;
                thisLevel.IsPercent      = isPercent;
                rowIndex++;
            }
            //SCOPE
            discount.IsGlobal = false;
            discount.Save();
        }
Esempio n. 3
0
        private bool ValidateVolumeOrder(IPersistableList <BasketItem> items)
        {
            foreach (var rec in items)
            {
                if (rec.OrderItemType == OrderItemType.Product)
                {
                    decimal MinQuantity = 0;

                    if (rec.Product.VolumeDiscounts.Any() && rec.Product.VolumeDiscounts[0].Levels.Any())
                    {
                        VolumeDiscount VolumeDiscount = rec.Product.VolumeDiscounts[0];
                        MinQuantity = VolumeDiscount.Levels.First().MinValue;
                    }
                    else
                    {
                        MinQuantity = rec.Product.MinQuantity;
                    }

                    if (rec.Quantity < MinQuantity)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            //CLEAR OUT EXISTING ASSIGNMENTS
            foreach (GridViewRow row in DiscountGrid.Rows)
            {
                int            discountId = (int)DiscountGrid.DataKeys[row.DataItemIndex].Value;
                VolumeDiscount discount   = VolumeDiscountDataSource.Load(discountId);
                CheckBox       attached   = (CheckBox)row.FindControl("Attached");
                if ((attached != null) && attached.Checked)
                {
                    if (!discount.Products.Contains(_Product))
                    {
                        discount.Products.Add(_Product);
                    }
                }
                else
                {
                    if (discount.Products.Contains(_Product))
                    {
                        discount.Products.Remove(_Product);
                    }
                }

                discount.Save();
            }
            SavedMessage.Visible = true;
        }
Esempio n. 5
0
        public static decimal GetShopPrice(OrderItem item)
        {
            if (item.OrderItemType == OrderItemType.Discount)
            {
                return(0);
            }

            if (item.Product == null || !item.Product.VolumeDiscounts.Any() || !item.Product.VolumeDiscounts[0].Levels.Any())
            {
                return(Math.Abs(item.Price));
            }

            VolumeDiscount      volumeDiscount = item.Product.VolumeDiscounts[0];
            VolumeDiscountLevel lastLevel      = volumeDiscount.Levels.Last();
            decimal             discountAmount = 0;

            foreach (var rec in volumeDiscount.Levels)
            {
                if (item.Quantity >= rec.MinValue && item.Quantity <= rec.MaxValue)
                {
                    discountAmount = rec.DiscountAmount;
                    break;
                }
            }

            if (item.Quantity >= lastLevel.MinValue)
            {
                discountAmount = lastLevel.DiscountAmount;
            }

            return(discountAmount);
        }
Esempio n. 6
0
        protected string GetNames(VolumeDiscount item)
        {
            List <string> groupNames = new List <string>();

            foreach (Group group in item.Groups)
            {
                groupNames.Add(group.Name);
            }
            return(string.Join(", ", groupNames.ToArray()));
        }
        private void Initialize()
        {
            // Load prices from a database...
            Products = new List <Product> {
                new Product {
                    ProductCode = "A"
                },
                new Product {
                    ProductCode = "B"
                },
                new Product {
                    ProductCode = "C"
                },
                new Product {
                    ProductCode = "D"
                }
            };

            Prices = new Dictionary <string, VolumeDiscount[]>();


            // For  lack of instruction to the contrary I interpret the instructions for Product A to be the
            // same as for product C:
            // "$2 each or $1.75 each for multiples of four (only)."

            // Volume discounts are added in ascending order.
            // The first price is always for a quantity of one since that is the default quantity.  Using this allows us to bypassing scanning
            // the VolumeDiscount array when the customer purchases a quantity of one.

            Prices["A"] = new VolumeDiscount[2] {
                new VolumeDiscount {
                    MinQty = 1, Price = 2m
                }, new VolumeDiscount {
                    MinQty = 4, Price = 1.75m
                }
            };
            Prices["B"] = new VolumeDiscount[1] {
                new VolumeDiscount {
                    MinQty = 1, Price = 12.00m
                }
            };
            Prices["C"] = new VolumeDiscount[2] {
                new VolumeDiscount {
                    MinQty = 1, Price = 1.25m
                }, new VolumeDiscount {
                    MinQty = 6, Price = 1.0m
                }
            };
            Prices["D"] = new VolumeDiscount[1] {
                new VolumeDiscount {
                    MinQty = 1, Price = .15m
                }
            };
        }
        protected void AddRowButton_Click(object sender, EventArgs e)
        {
            SaveDiscount();
            VolumeDiscount      discount         = _VolumeDiscount;
            VolumeDiscountLevel newDiscountLevel = new VolumeDiscountLevel(discount, 0, 0, 0, true);

            discount.Levels.Add(newDiscountLevel);
            discount.Save();
            DiscountLevelGrid.DataSource = discount.Levels;
            DiscountLevelGrid.DataBind();
        }
        private void SaveDiscount()
        {
            VolumeDiscount discount = _VolumeDiscount;

            discount.Name         = Name.Text;
            discount.IsValueBased = IsValueBased.SelectedIndex == 1 ? true : false;
            //LOOP THROUGH GRID ROWS AND SET MATRIX
            int rowIndex = 0;

            foreach (GridViewRow row in DiscountLevelGrid.Rows)
            {
                if (discount.Levels.Count < (rowIndex + 1))
                {
                    // ADD A NEW DISCOUNT LEVEL FOR NEW ROWS
                    VolumeDiscountLevel newDiscountLevel = new VolumeDiscountLevel();
                    newDiscountLevel.Id = _VolumeDiscountId;
                    discount.Levels.Add(newDiscountLevel);
                }
                decimal             minValue       = AlwaysConvert.ToDecimal(((TextBox)row.FindControl("MinValue")).Text);
                decimal             maxValue       = AlwaysConvert.ToDecimal(((TextBox)row.FindControl("MaxValue")).Text);
                decimal             discountAmount = AlwaysConvert.ToDecimal(((TextBox)row.FindControl("DiscountAmount")).Text);
                bool                isPercent      = (((DropDownList)row.FindControl("IsPercent")).SelectedIndex == 0);
                VolumeDiscountLevel thisLevel      = discount.Levels[rowIndex];
                thisLevel.MinValue       = minValue;
                thisLevel.MaxValue       = maxValue;
                thisLevel.DiscountAmount = discountAmount;
                thisLevel.IsPercent      = isPercent;
                thisLevel.Save();
                rowIndex++;
            }
            //SCOPE
            discount.IsGlobal = (UseGlobalScope.SelectedIndex == 0);
            //GROUP RESTRICTION
            if (UseGroupRestriction.SelectedIndex > 0)
            {
                _VolumeDiscount.Groups.Clear();
                _VolumeDiscount.Save();
                foreach (ListItem item in GroupList.Items)
                {
                    Group group = GroupDataSource.Load(AlwaysConvert.ToInt(item.Value));
                    if (item.Selected)
                    {
                        _VolumeDiscount.Groups.Add(group);
                    }
                }
            }
            else
            {
                _VolumeDiscount.Groups.Clear();
            }
            discount.Save();
        }
Esempio n. 10
0
        protected void AddButton_Click(object sender, EventArgs e)
        {
            VolumeDiscount newDiscount = new VolumeDiscount();

            newDiscount.Store = AbleContext.Current.Store;
            newDiscount.Name  = "New Discount";
            newDiscount.Save();

            VolumeDiscountLevel newDiscountLevel = new VolumeDiscountLevel(newDiscount, 0, 0, 0, true);

            newDiscount.Levels.Add(newDiscountLevel);
            newDiscount.Save();
            Response.Redirect("EditDiscount.aspx?VolumeDiscountId=" + newDiscount.Id.ToString() + "&IsAdd=1");
        }
        protected string GetNames(VolumeDiscount discount)
        {
            if (discount.Groups.Count == 0)
            {
                return(string.Empty);
            }
            List <string> groupNames = new List <string>();

            foreach (CommerceBuilder.Users.Group group in discount.Groups)
            {
                groupNames.Add(group.Name);
            }
            return(string.Join(",", groupNames.ToArray()));
        }
        public decimal GetVolumePrice(string productCode, int qtyPurchased)
        {
            if (String.IsNullOrEmpty(productCode))
            {
                throw new ArgumentNullException("productCode is required.");
            }

            if (qtyPurchased == 0)
            {
                throw new ArgumentException("quantity cannot be zero.");
            }

            // Customer may be returning some items in which case qtyPurchased will be less than zero.
            // We need to be able to credit them the correct amount.  Use absolute value of qty for lookups:

            int qty = Math.Abs(qtyPurchased);

            VolumeDiscount[] priceBreaks = null;
            decimal          totalPrice, price = 0;


            // Get the Volume Discount for the product being purchased:

            if (!Prices.TryGetValue(productCode, out priceBreaks))
            {
                throw new Exception($"ProductCode {productCode} was not found in the pricing table.");
            }

            // If customer is purchasing a quantity of one we know the price is the first price break.
            // For quantities greater than one we take the greatest price break where the minimum quantity that must be purchased is
            // less than or equal to the quantity the customer actually purchased.
            // Recall that VolumeDiscounts are in ascending order.

            if (qty == 1)
            {
                price      = priceBreaks[0].Price;
                totalPrice = qty * price;
            }
            else
            {
                VolumeDiscount volDis    = priceBreaks.Last(y => y.MinQty <= qty);
                int            multiple  = qty / volDis.MinQty;
                int            remainder = qty - (multiple * volDis.MinQty);

                // Call this method recursively with remainders, finding each successively lower price break.
                totalPrice = (multiple * volDis.MinQty * volDis.Price) + (remainder == 0 ? 0 : GetVolumePrice(productCode, remainder));
            }
            return(totalPrice * (qtyPurchased < 0 ? -1 : 1));
        }
Esempio n. 13
0
 protected void VolumeDiscountGrid_RowCommand(object sender, GridViewCommandEventArgs e)
 {
     if (e.CommandName.Equals("Copy"))
     {
         int            volumeDiscountId = AlwaysConvert.ToInt(e.CommandArgument);
         VolumeDiscount volumeDiscount   = VolumeDiscountDataSource.Load(volumeDiscountId);
         VolumeDiscount copy             = volumeDiscount.Copy(true);
         if (copy != null)
         {
             copy.Name = "Copy of " + copy.Name;
             copy.Save();
         }
         VolumeDiscountGrid.DataBind();
     }
 }
        protected void DiscountLevelGrid_OnRowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int index = e.RowIndex;

            SaveDiscount();
            VolumeDiscount discount = _VolumeDiscount;

            if (discount.Levels.Count >= (index + 1))
            {
                discount.Levels.DeleteAt(index);
                discount.Save();
            }
            DiscountLevelGrid.DataSource = discount.Levels;
            DiscountLevelGrid.DataBind();
        }
Esempio n. 15
0
        protected void Page_Load(object sender, EventArgs e)
        {
            _VolumeDiscount = VolumeDiscountDataSource.Load(_VolumeDiscountId);

            //Removed '!Page.IsPostBack check
            AddCaption.Visible  = _IsAdd;
            EditCaption.Visible = !AddCaption.Visible;
            if (EditCaption.Visible)
            {
                if (_VolumeDiscount != null)
                {
                    EditCaption.Text = string.Format(EditCaption.Text, _VolumeDiscount.Name);
                }
            }
        }
Esempio n. 16
0
        protected void DiscountLevelGrid_PreRender(object sender, EventArgs e)
        {
            VolumeDiscount discount = _VolumeDiscount;

            if (discount != null)
            {
                if (discount.Levels.Count == 0)
                {
                    VolumeDiscountLevel newDiscountLevel = new VolumeDiscountLevel();
                    discount.Levels.Add(newDiscountLevel);
                }
            }

            //Moved DataBind to Page_Init
        }
        protected void DiscountLevelGrid_PreRender(object sender, EventArgs e)
        {
            VolumeDiscount discount = _VolumeDiscount;

            if (discount != null)
            {
                if (discount.Levels.Count == 0)
                {
                    VolumeDiscountLevel newDiscountLevel = new VolumeDiscountLevel();
                    discount.Levels.Add(newDiscountLevel);
                }

                DiscountLevelGrid.DataSource = _VolumeDiscount.Levels;
                DiscountLevelGrid.DataBind();
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            _VolumeDiscountId = AlwaysConvert.ToInt(Request.QueryString["VolumeDiscountId"]);
            _VolumeDiscount   = VolumeDiscountDataSource.Load(_VolumeDiscountId);
            if (_VolumeDiscount == null)
            {
                Response.Redirect("Default.aspx");
            }
            Caption.Text = string.Format(Caption.Text, _VolumeDiscount.Name);
            if (!Page.IsPostBack)
            {
                // initialize the category tree
                CategoryTree.SelectedCategories = _VolumeDiscount.Categories.Select(x => x.Id).ToList().ToArray();
            }

            FindAssignProducts1.AssignmentValue  = _VolumeDiscountId;
            FindAssignProducts1.OnAssignProduct += new AssignProductEventHandler(FindAssignProducts1_AssignProduct);
            FindAssignProducts1.OnLinkCheck     += new AssignProductEventHandler(FindAssignProducts1_LinkCheck);
            FindAssignProducts1.OnCancel        += new EventHandler(FindAssignProducts1_CancelButton);
        }
        protected string GetLevels(VolumeDiscount discount)
        {
            if (discount.Levels.Count == 0)
            {
                return(string.Empty);
            }
            List <string> levels = new List <string>();
            string        from;
            string        to;
            string        amount;

            foreach (VolumeDiscountLevel level in discount.Levels)
            {
                if (level.MinValue == 0)
                {
                    from = "any";
                }
                else
                {
                    from = level.MinValue.ToString("0.##");
                }
                if (level.MaxValue == 0)
                {
                    to = "any";
                }
                else
                {
                    to = level.MaxValue.ToString("0.##");
                }
                if (level.IsPercent)
                {
                    amount = string.Format("{0:0.##}%", level.DiscountAmount);
                }
                else
                {
                    amount = level.DiscountAmount.LSCurrencyFormat("lc");
                }
                levels.Add(string.Format("from {0} to {1} - {2}", from, to, amount));
            }
            return(string.Join("<br />", levels.ToArray()));
        }
Esempio n. 20
0
        private IList <BasketItem> ValidateVolumeOrder(IList <BasketItem> items)
        {
            IList <BasketItem> newBasketItems  = new List <BasketItem>();
            List <string>      warningMessages = new List <string>();

            foreach (var rec in items)
            {
                if (rec.OrderItemType == OrderItemType.Product)
                {
                    decimal MinQuantity = 0;

                    if (rec.Product.VolumeDiscounts.Any() && rec.Product.VolumeDiscounts[0].Levels.Any())
                    {
                        VolumeDiscount VolumeDiscount = rec.Product.VolumeDiscounts[0];
                        MinQuantity = VolumeDiscount.Levels.First().MinValue;
                    }
                    else
                    {
                        MinQuantity = rec.Product.MinQuantity;
                    }

                    if (rec.Quantity < MinQuantity)
                    {
                        _volumeDiscountError = true;
                        warningMessages.Add(String.Format("Cannot order '{0}' below the minumum quantity amount of '{1}'.", rec.Name, MinQuantity.ToString("0")));
                    }
                }
                //Remove Discount row from Basket
                if (rec.OrderItemType != OrderItemType.Discount)
                {
                    newBasketItems.Add(rec);
                }
            }

            OrderVolumeAmountMessageList.DataSource = warningMessages;
            OrderVolumeAmountMessageList.DataBind();

            return(newBasketItems);
        }
Esempio n. 21
0
        protected void Page_Load(object sender, EventArgs e)
        {
            bool    discountsFound = false;
            int     _ProductId     = AlwaysConvert.ToInt(Request.QueryString["ProductId"]);
            Product _Product       = ProductDataSource.Load(_ProductId);

            if (_Product != null)
            {
                IList <VolumeDiscount> availableDiscounts = VolumeDiscountDataSource.GetAvailableDiscounts(_ProductId);
                if (availableDiscounts.Count > 0)
                {
                    //SEE WHETHER THERE IS ONE DISCOUNT
                    //AND IT ALWAYS HAS NO VALUE
                    bool show = true;
                    if (availableDiscounts.Count == 1)
                    {
                        VolumeDiscount testDiscount = availableDiscounts[0];
                        if (testDiscount.Levels.Count == 1)
                        {
                            VolumeDiscountLevel testLevel = testDiscount.Levels[0];
                            show = ((testLevel.MinValue > 1) || (testLevel.DiscountAmount > 0));
                        }
                    }
                    if (show)
                    {
                        phCaption.Text           = this.Caption;
                        DiscountsGrid.DataSource = availableDiscounts;
                        DiscountsGrid.DataBind();
                        discountsFound = true;
                    }
                }
            }
            //DO NOT DISPLAY THIS CONTROL IF NO DISCOUNTS AVAILABLE
            if (!discountsFound)
            {
                this.Controls.Clear();
            }
        }
 protected void Page_Load(object sender, EventArgs e)
 {
     _VolumeDiscountId = AlwaysConvert.ToInt(Request.QueryString["VolumeDiscountId"]);
     _VolumeDiscount   = VolumeDiscountDataSource.Load(_VolumeDiscountId);
     if (!Page.IsPostBack)
     {
         AddCaption.Visible  = this.IsAdd;
         EditCaption.Visible = !AddCaption.Visible;
         if (EditCaption.Visible)
         {
             EditCaption.Text = string.Format(EditCaption.Text, _VolumeDiscount.Name);
         }
         Name.Text = _VolumeDiscount.Name;
         IsValueBased.SelectedIndex = (_VolumeDiscount.IsValueBased ? 1 : 0);
         //SCOPE
         UseGlobalScope.SelectedIndex = (_VolumeDiscount.IsGlobal) ? 0 : 1;
         //GROUP RESTRICTION
         UseGroupRestriction.SelectedIndex = (_VolumeDiscount.Groups.Count > 0) ? 1 : 0;
         BindGroups();
     }
     BindScope();
     hdnScope.Value = Scope.Text;
 }
Esempio n. 23
0
        public static decimal GetInvoiceExtendedPrice(BasketItem item)
        {
            if (item.OrderItemType == OrderItemType.Discount)
            {
                return(0);
            }
            if (item.Product == null || !item.Product.VolumeDiscounts.Any() || !item.Product.VolumeDiscounts[0].Levels.Any())
            {
                return(Math.Abs(item.Price * item.Quantity));
            }

            VolumeDiscount volumeDiscount = item.Product.VolumeDiscounts[0];

            if (volumeDiscount.Levels.Count < 1)
            {
                return(item.Price * item.Quantity);
            }


            decimal lastMinValue   = volumeDiscount.Levels.Last().MinValue;
            decimal discountAmount = 0;

            foreach (var rec in volumeDiscount.Levels)
            {
                if (item.Quantity >= rec.MinValue && item.Quantity <= rec.MaxValue)
                {
                    discountAmount = rec.DiscountAmount;
                    break;
                }
                else if (item.Quantity >= lastMinValue)
                {
                    discountAmount = rec.DiscountAmount;
                    break;
                }
            }
            return(discountAmount * item.Quantity);
        }
Esempio n. 24
0
        private void ProcessRules(BreadCrumbItem breadCrumbItem)
        {
            int id;

            if (breadCrumbItem.Url == "#")
            {
                return;
            }
            switch (breadCrumbItem.Url.ToLowerInvariant())
            {
            case "~/admin/orders/shipments/editshipment.aspx":
                id = AlwaysConvert.ToInt(Request.QueryString["OrderShipmentId"]);
                breadCrumbItem.Url  += "?OrderShipmentId=" + id;
                breadCrumbItem.Title = string.Format(breadCrumbItem.Title, id);
                break;

            case "~/admin/products/editproduct.aspx":
            case "~/admin/products/variants/variants.aspx":
            case "~/admin/products/variants/options.aspx":
            case "~/admin/products/digitalgoods/digitalgoods.aspx":
            case "~/admin/products/kits/editkit.aspx":
            case "~/admin/products/assets/images.aspx":
            case "~/admin/products/editproducttemplate.aspx":
            case "~/admin/products/specials/default.aspx":
                int categoryId = AbleCommerce.Code.PageHelper.GetCategoryId();
                id = AbleCommerce.Code.PageHelper.GetProductId();
                Product product = ProductDataSource.Load(id);
                if (categoryId > 0)
                {
                    breadCrumbItem.Url += "?CategoryId=" + categoryId + "&ProductId=" + id;
                }
                else
                {
                    breadCrumbItem.Url += "?ProductId=" + id;
                }
                breadCrumbItem.Title = string.Format(breadCrumbItem.Title, product.Name);
                break;

            case "~/admin/orders/vieworder.aspx":
            case "~/admin/orders/edit/editorderitems.aspx":
            case "~/admin/orders/viewdigitalgoods.aspx":
            case "~/admin/orders/payments/default.aspx":
            case "~/admin/orders/shipments/default.aspx":
                id = AbleCommerce.Code.PageHelper.GetOrderId();
                Order order = OrderDataSource.Load(id);
                breadCrumbItem.Url  += "?OrderNumber=" + order.OrderNumber;
                breadCrumbItem.Title = string.Format(breadCrumbItem.Title, order.OrderNumber);
                break;

            case "~/admin/marketing/coupons/editcoupon.aspx":
                id = AlwaysConvert.ToInt(Request.QueryString["CouponId"]);
                Coupon coupon = CouponDataSource.Load(id);
                breadCrumbItem.Url  += "?CouponId=" + id;
                breadCrumbItem.Title = string.Format(breadCrumbItem.Title, coupon.Name);
                break;

            case "~/admin/products/variants/editoption.aspx":
            case "~/admin/products/variants/editchoices.aspx":
                id = AlwaysConvert.ToInt(Request.QueryString["OptionId"]);
                Option option = OptionDataSource.Load(id);
                breadCrumbItem.Url  += "?OptionId=" + id;
                breadCrumbItem.Title = string.Format(breadCrumbItem.Title, option.Name);
                break;

            case "~/admin/products/giftwrap/editwrapgroup.aspx":
                id = AlwaysConvert.ToInt(Request.QueryString["WrapGroupId"]);
                WrapGroup wrapGroup = WrapGroupDataSource.Load(id);
                breadCrumbItem.Url  += "?WrapGroupId=" + id;
                breadCrumbItem.Title = string.Format(breadCrumbItem.Title, wrapGroup.Name);
                break;

            case "~/admin/marketing/email/managelist.aspx":
                id = AlwaysConvert.ToInt(Request.QueryString["EmailListId"]);
                EmailList emailList = EmailListDataSource.Load(id);
                if (emailList != null)
                {
                    breadCrumbItem.Url  += "?EmailListId=" + id;
                    breadCrumbItem.Title = string.Format(breadCrumbItem.Title, emailList.Name);
                }
                break;

            case "~/admin/marketing/discounts/editdiscount.aspx":
                id = AlwaysConvert.ToInt(Request.QueryString["VolumeDiscountId"]);
                VolumeDiscount discount = VolumeDiscountDataSource.Load(id);
                breadCrumbItem.Url  += "?VolumeDiscountId=" + id;
                breadCrumbItem.Title = string.Format(breadCrumbItem.Title, discount.Name);
                break;

            case "~/admin/catalog/editwebpage.aspx":
                id = AbleCommerce.Code.PageHelper.GetWebpageId();
                Webpage webpage = WebpageDataSource.Load(id);
                breadCrumbItem.Url  += "?WebpageId=" + id;
                breadCrumbItem.Title = string.Format(breadCrumbItem.Title, webpage.Name);
                break;

            case "~/admin/catalog/editLink.aspx":
                id = AbleCommerce.Code.PageHelper.GetLinkId();
                Link link = LinkDataSource.Load(id);
                breadCrumbItem.Url  += "?LinkId=" + id;
                breadCrumbItem.Title = string.Format(breadCrumbItem.Title, link.Name);
                break;

            case "~/admin/people/users/edituser.aspx":
                id = AlwaysConvert.ToInt(Request.QueryString["UserId"]);
                User user = UserDataSource.Load(id);
                breadCrumbItem.Url  += "?UserId=" + id;
                breadCrumbItem.Title = string.Format(breadCrumbItem.Title, user.UserName);
                break;

            case "~/admin/digitalgoods/editdigitalgood.aspx":
            case "~/admin/digitalgoods/serialkeyproviders/defaultprovider/configure.aspx":
                id = AlwaysConvert.ToInt(Request.QueryString["DigitalGoodId"]);
                DigitalGood dg = DigitalGoodDataSource.Load(id);
                if (dg != null)
                {
                    breadCrumbItem.Url  += "?DigitalGoodId=" + id;
                    breadCrumbItem.Title = string.Format(breadCrumbItem.Title, dg.Name);
                }
                break;

            case "~/admin/products/producttemplates/editproducttemplate.aspx":
                id = AlwaysConvert.ToInt(Request.QueryString["ProductTemplateId"]);
                ProductTemplate template = ProductTemplateDataSource.Load(id);
                if (template == null)
                {
                    InputField field = InputFieldDataSource.Load(AlwaysConvert.ToInt(Request.QueryString["InputFieldId"]));
                    if (field != null)
                    {
                        template = field.ProductTemplate;
                        id       = template.Id;
                    }
                }
                if (template != null)
                {
                    breadCrumbItem.Url  += "?ProductTemplateId=" + id;
                    breadCrumbItem.Title = string.Format(breadCrumbItem.Title, template.Name);
                }
                else
                {
                }
                break;

            case "~/admin/reports/dailyabandonedbaskets.aspx":
                id = AlwaysConvert.ToInt(Request.QueryString["BasketId"]);
                Basket basket = BasketDataSource.Load(id);
                if (basket != null)
                {
                    breadCrumbItem.Url += "?ReportDate=" + basket.User.LastActivityDate.Value.ToShortDateString();
                }
                break;
            }

            // resolve relative urls
            if (breadCrumbItem.Url.StartsWith("~/"))
            {
                breadCrumbItem.Url = Page.ResolveUrl(breadCrumbItem.Url);
            }
        }
        protected string GetLevels(object dataItem)
        {
            StringBuilder levelList  = new StringBuilder();
            StringBuilder levelPrice = new StringBuilder();

            levelList.Append("<tbody><tr><td class='header-qty'>Qty</td>");
            levelPrice.Append("<tr><td class='header-price'>Price</td>");
            VolumeDiscount discount = (VolumeDiscount)dataItem;

            foreach (VolumeDiscountLevel level in discount.Levels)
            {
                levelList.Append("<td>");
                levelPrice.Append("<td>");
                if (level.MinValue != 0)
                {
                    if (level.MaxValue != 0)
                    {
                        if (discount.IsValueBased)
                        {
                            levelList.Append(string.Format("{0} - {1}", level.MinValue.LSCurrencyFormat("ulc"), level.MaxValue.LSCurrencyFormat("ulc")));
                        }
                        else
                        {
                            levelList.Append(string.Format("{0:F0} - {1:F0}", level.MinValue, level.MaxValue));
                        }
                    }
                    else
                    {
                        //Was "at least {number}"
                        if (discount.IsValueBased)
                        {
                            levelList.Append(string.Format("{0}+", level.MinValue.LSCurrencyFormat("ulc")));
                        }
                        else
                        {
                            levelList.Append(string.Format("{0:F0}+", level.MinValue));
                        }
                    }
                }
                else if (level.MaxValue != 0)
                {
                    if (discount.IsValueBased)
                    {
                        levelList.Append(string.Format("up to {0}", level.MaxValue.LSCurrencyFormat("ulc")));
                    }
                    else
                    {
                        levelList.Append(string.Format("up to {0:F0}", level.MaxValue));
                    }
                }
                else
                {
                    levelList.Append("any");
                }
                if (level.IsPercent)
                {
                    levelPrice.Append(string.Format("{0:0.##}%", level.DiscountAmount));
                }
                else
                {
                    levelPrice.Append(string.Format("{0}", level.DiscountAmount.LSCurrencyFormat("ulc")));
                }

                levelPrice.Append("</td>");
                levelList.Append("</td>");
            }

            levelList.Append("</tr>").Append(levelPrice.Append("</tr></tbody>"));
            return(levelList.ToString());
        }
Esempio n. 26
0
        protected string GetLevels(object dataItem)
        {
            StringBuilder levelList = new StringBuilder();

            levelList.Append("<ul>");
            VolumeDiscount discount = (VolumeDiscount)dataItem;

            foreach (VolumeDiscountLevel level in discount.Levels)
            {
                levelList.Append("<li>buy ");
                if (level.MinValue != 0)
                {
                    if (level.MaxValue != 0)
                    {
                        if (discount.IsValueBased)
                        {
                            levelList.Append(string.Format("{0} to {1}", level.MinValue.LSCurrencyFormat("ulc"), level.MaxValue.LSCurrencyFormat("ulc")));
                        }
                        else
                        {
                            levelList.Append(string.Format("{0:F0} to {1:F0}", level.MinValue, level.MaxValue));
                        }
                    }
                    else
                    {
                        if (discount.IsValueBased)
                        {
                            levelList.Append(string.Format("at least {0}", level.MinValue.LSCurrencyFormat("ulc")));
                        }
                        else
                        {
                            levelList.Append(string.Format("at least {0:F0}", level.MinValue));
                        }
                    }
                }
                else if (level.MaxValue != 0)
                {
                    if (discount.IsValueBased)
                    {
                        levelList.Append(string.Format("up to {0}", level.MaxValue.LSCurrencyFormat("ulc")));
                    }
                    else
                    {
                        levelList.Append(string.Format("up to {0:F0}", level.MaxValue));
                    }
                }
                else
                {
                    levelList.Append("any");
                }
                levelList.Append(", save ");
                if (level.IsPercent)
                {
                    levelList.Append(string.Format("{0:0.##}%", level.DiscountAmount));
                }
                else
                {
                    levelList.Append(string.Format("{0} each", level.DiscountAmount.LSCurrencyFormat("ulc")));
                }
                levelList.Append("</li>");
            }
            levelList.Append("</ul>");
            return(levelList.ToString());
        }