Пример #1
0
        private Money CalculateShippingCostSubTotal(IEnumerable <Shipment> shipments, CartHelper cartHelper)
        {
            var retVal = new Money(0, cartHelper.Cart.BillingCurrency);

            foreach (Shipment shipment in shipments)
            {
                if (cartHelper.FindAddressByName(shipment.ShippingAddressId) == null)
                {
                    continue;
                }

                var methods = ShippingManager.GetShippingMethods(CurrentPage.LanguageID);

                var shippingMethod = methods.ShippingMethod.FirstOrDefault(c => c.ShippingMethodId.Equals(shipment.ShippingMethodId));
                if (shippingMethod == null)
                {
                    continue;
                }

                var shipmentRateMoney = SampleStoreHelper.GetShippingCost(shippingMethod, shipment, cartHelper.Cart.BillingCurrency);
                retVal += shipmentRateMoney;
            }

            return(retVal);
        }
Пример #2
0
        /// <summary>
        /// Handles the ItemUpdating event of the lvCartItem control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="ListViewUpdateEventArgs"/> instance containing the event data.</param>
        protected void lvCartItem_ItemUpdating(object sender, ListViewUpdateEventArgs e)
        {
            ListViewItem row             = lvCartItems.Items[e.ItemIndex];
            var          quantityTextBox = row.FindControl("Quantity") as TextBox;
            decimal      newQuantity;

            if (!decimal.TryParse(quantityTextBox.Text, out newQuantity))
            {
                BindData();
                return;
            }

            int lineItemId;

            if (!Int32.TryParse(lvCartItems.DataKeys[e.ItemIndex].Value.ToString(), out lineItemId))
            {
                return;
            }

            if (!CartHelper.IsEmpty)
            {
                foreach (var item in CartHelper.LineItems)
                {
                    var discounts = from Discount discount in item.Discounts
                                    where discount.DiscountName.EndsWith(":Gift")
                                    select discount;

                    if (discounts.Any())
                    {
                        ErrorManager.GenerateError(string.Format("[{0}]: {1}", item.DisplayName, "You can not change the quality of items of gift promotion"));
                        return;
                    }

                    if (item.LineItemId == lineItemId)
                    {
                        if (item.Quantity != newQuantity)
                        {
                            var errorMessage = "";
                            var entry        = CatalogContext.Current.GetCatalogEntry(item.CatalogEntryId,
                                                                                      new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryInfo |
                                                                                                                    CatalogEntryResponseGroup.ResponseGroup.Inventory));

                            if (SampleStoreHelper.AllowAddToCart(CartHelper.Cart, entry, true, newQuantity, item.WarehouseCode, out errorMessage))
                            {
                                item.Quantity = newQuantity;
                                CartHelper.Cart.AcceptChanges();
                            }
                            else
                            {
                                ErrorManager.GenerateError(string.Format("[{0}]: {1}", item.DisplayName, errorMessage));
                                return;
                            }
                        }
                        break;
                    }
                }
            }
            Context.RedirectFast(Request.RawUrl);
        }
Пример #3
0
        /// <summary>
        /// Handles the Click event of the PurchaseLink control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Web.UI.ImageClickEventArgs"/> instance containing the event data.</param>
        protected void BuyButton_Click(object sender, EventArgs e)
        {
            CartHelper ch       = new CartHelper(Cart.DefaultName);
            CartHelper wishList = new CartHelper(CartHelper.WishListName);

            if (VariationContent != null)
            {
                //get quantity when use AddToCart into Repeater (case: Relate Product)
                var linkButtonControl  = (sender as System.Web.UI.Control);
                var addToCartControl   = linkButtonControl.Parent;
                var txtQuantityControl = addToCartControl.FindControl("txtQuantity");

                var entry          = VariationContent.LoadEntry(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryInfo | CatalogEntryResponseGroup.ResponseGroup.Inventory);
                var warehouseField = FindControlRecursive(this.Parent, "hidWarehouseCode") as HiddenField;
                var warehouseCode  = String.Empty;
                if (warehouseField != null && !string.IsNullOrEmpty(warehouseField.Value))
                {
                    warehouseCode = warehouseField.Value;
                }

                decimal quantity = decimal.Parse(System.Web.HttpContext.Current.Request.Form[txtQuantityControl.UniqueID].ToString());
                string  errorMessage;
                if (!SampleStoreHelper.AllowAddToCart(
                        ch.Cart,
                        entry,
                        false,
                        quantity,
                        String.IsNullOrEmpty(warehouseCode) ? Constants.DefaultWarehouseCode : warehouseCode,
                        out errorMessage))
                {
                    ErrorMessage.Text = errorMessage;
                    divErrorMsg.Style.Add("display", "block");
                    //We will do a postback here, reset the warehouse code to empty
                    if (warehouseField != null)
                    {
                        warehouseField.Value = string.Empty;
                    }
                    return;
                }

                if (entry.IsAvailableInMarket(_marketId))
                {
                    ch.AddEntry(entry, quantity, false, warehouseCode, new CartHelper[] { wishList });
                    Response.Redirect(GetUrl(Settings.CartPage));
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Binds the shipping methods.
        /// </summary>
        private string BindShippingMethods()
        {
            var defaultShippingMethodId = String.Empty;
            var dtShippingMethods       = new DataTable();

            dtShippingMethods.Columns.Add(new DataColumn("ShippingName"));
            dtShippingMethods.Columns.Add(new DataColumn("Description"));
            dtShippingMethods.Columns.Add(new DataColumn("ShippingMethodId"));

            ShippingMethodDto shippingMethods = ShippingManager.GetShippingMethods("en");

            if (shippingMethods != null && shippingMethods.ShippingMethod != null &&
                shippingMethods.ShippingMethod.Count > 0)
            {
                foreach (var shippingMethod in shippingMethods.ShippingMethod.OrderBy(c => c.Ordering))
                {
                    string shippingMethodName;
                    if (shippingMethod.BasePrice == 0m)
                    {
                        shippingMethodName = string.Format("{0} - Free", shippingMethod.DisplayName);
                    }
                    else
                    {
                        Money currentPrice = SampleStoreHelper.ConvertCurrency(new Money(shippingMethod.BasePrice, shippingMethod.Currency), SiteContext.Current.Currency);
                        if (!string.IsNullOrEmpty(Shipment.ShippingAddressId))
                        {
                            var shipment = Cart.OrderForms[0].Shipments.ToArray().FirstOrDefault();
                            currentPrice = SampleStoreHelper.GetShippingCost(shippingMethod, shipment);
                        }
                        shippingMethodName = string.Format("{0} - {1}", shippingMethod.DisplayName, currentPrice.ToString());
                    }
                    dtShippingMethods.Rows.Add(shippingMethodName, shippingMethod.IsDescriptionNull() ? string.Empty : shippingMethod.Description, shippingMethod.ShippingMethodId);
                    if (shippingMethod.IsDefault)
                    {
                        defaultShippingMethodId = shippingMethod.ShippingMethodId.ToString();
                    }
                }

                shippingOptions.DataSource = dtShippingMethods;
                shippingOptions.DataBind();
            }

            return(defaultShippingMethodId);
        }
Пример #5
0
        /// <summary>
        /// Handles the ItemCommand event of the CartItemsList control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Web.UI.WebControls.RepeaterCommandEventArgs"/> instance containing the event data.</param>
        protected void CartItemsList_ItemCommand(object sender, RepeaterCommandEventArgs e)
        {
            var lineItemId = int.Parse(e.CommandArgument.ToString());
            var lineItem   = WishListHelper.LineItems.FirstOrDefault(l => l.LineItemId == lineItemId);

            switch (e.CommandName)
            {
            case "AddToCart":
                var cart = new CartHelper(Cart.DefaultName);
                if (lineItem != null)
                {
                    var entry = CatalogContext.Current.GetCatalogEntry(lineItem.CatalogEntryId,
                                                                       new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryInfo |
                                                                                                     CatalogEntryResponseGroup.ResponseGroup.Inventory));

                    if (entry != null)
                    {
                        string errorMessage;
                        if (!SampleStoreHelper.AllowAddToCart(cart.Cart, entry, false, lineItem.Quantity,
                                                              lineItem.WarehouseCode, out errorMessage))
                        {
                            return;
                        }

                        cart.AddEntry(entry, lineItem.Quantity, false, lineItem.WarehouseCode,
                                      new CartHelper[] { });
                        lineItem.Delete();
                    }
                }
                // If cart is empty, remove it from the database
                if (WishListHelper.IsEmpty)
                {
                    WishListHelper.Delete();
                }
                // Save changes to a wish list
                WishListHelper.Cart.AcceptChanges();
                cart.Cart.AcceptChanges();

                // Redirect to shopping cart
                Context.RedirectFast(GetUrl(Settings.CartPage));
                break;

            case "Remove":
                if (lineItem != null)
                {
                    // remove from wishlist
                    lineItem.Delete();
                }

                // If cart is empty, remove it from the database
                if (WishListHelper.IsEmpty)
                {
                    WishListHelper.Delete();
                }

                // Save changes to a wish list
                WishListHelper.Cart.AcceptChanges();

                BindData();
                break;
            }
        }