Esempio n. 1
0
        protected string GetShoppingCartSum()
        {
            ShoppingCart cart                   = ShoppingCartManager.GetCurrentShoppingCart(ShoppingCartTypeEnum.ShoppingCart);
            bool         isUsd                  = Request.Cookies["Currency"] != null && Request.Cookies["Currency"].Value == "USD";
            decimal      indOrderTotal          = 0;
            IndividualOrderCollection indOrders = new IndividualOrderCollection();

            if (NopContext.Current.Session != null)
            {
                Guid customerSessionGuid = NopContext.Current.Session.CustomerSessionGUID;
                indOrders     = IndividualOrderManager.GetIndividualOrderByCurrentUserSessionGuid(customerSessionGuid);
                indOrderTotal = IndividualOrderManager.GetTotalPriceIndOrders(indOrders);
                if (isUsd)
                {
                    indOrderTotal = Math.Round(PriceConverter.ToUsd(indOrderTotal));
                }
            }

            if (cart.Count > 0 || indOrders.Count > 0)
            {
                //subtotal
                string  subTotalError = string.Empty;
                decimal shoppingCartSubTotalDiscountBase;
                decimal shoppingCartSubTotalBase = ShoppingCartManager.GetShoppingCartSubTotal(cart, NopContext.Current.User,
                                                                                               out shoppingCartSubTotalDiscountBase,
                                                                                               ref subTotalError);
                if (String.IsNullOrEmpty(subTotalError))
                {
                    decimal shoppingCartSubTotal = CurrencyManager.ConvertCurrency(shoppingCartSubTotalBase,
                                                                                   CurrencyManager.PrimaryStoreCurrency,
                                                                                   NopContext.Current.WorkingCurrency);
                    shoppingCartSubTotal += indOrderTotal;
                    return(AddCurrency(PriceHelper.FormatPrice(shoppingCartSubTotal), isUsd));
                }
            }

            return(AddCurrency("0", isUsd));
        }
        protected void btnNextStep_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                try
                {
                    PaymentInfo paymentInfo = this.PaymentInfo;
                    //if (paymentInfo == null)
                    //    Response.Redirect("~/CheckoutPaymentInfo.aspx");
                    paymentInfo.BillingAddress   = NopContext.Current.User.BillingAddress;
                    paymentInfo.ShippingAddress  = NopContext.Current.User.ShippingAddress;
                    paymentInfo.CustomerLanguage = NopContext.Current.WorkingLanguage;
                    paymentInfo.CustomerCurrency = NopContext.Current.WorkingCurrency;

                    int    orderId = 0;
                    string result  = "";
                    if (Request["OrderId"] == null)
                    {
                        result = OrderManager.PlaceOrder(paymentInfo, NopContext.Current.User, out orderId);
                    }
                    else
                    {
                        orderId = int.Parse(Request["OrderId"]);
                    }

                    this.PaymentInfo = null;
                    Order order = OrderManager.GetOrderByID(orderId);
                    if (!String.IsNullOrEmpty(result))
                    {
                        lError.Text = Server.HtmlEncode(result);
                        return;
                    }

                    if (Request["OrderId"] != null)
                    {
                        order.PaymentMethodID   = paymentInfo.PaymentMethodID;
                        order.PaymentMethodName = PaymentMethodManager.GetPaymentMethodByID(paymentInfo.PaymentMethodID).Name;
                    }

                    Guid customerSessionGUID            = NopContext.Current.Session.CustomerSessionGUID;
                    IndividualOrderCollection indOrders = IndividualOrderManager.GetIndividualOrderByCurrentUserSessionGuid(customerSessionGUID);

                    string        subj = "Заказ в магазине Voobrazi.by";
                    StringBuilder body = new StringBuilder();
                    body.AppendFormat("Доставка: {0}<br /><br />", ((bool)Session["Delivery"]) ? "Курьером" : "Самовывоз").AppendLine();
                    body.AppendFormat("<b>Заказчик</b><br />").AppendLine();
                    body.AppendFormat("ФИО: {0} {1}<br />", paymentInfo.BillingAddress.FirstName, paymentInfo.BillingAddress.LastName).AppendLine();
                    body.AppendFormat("Телефоны: {0} {1}<br />", paymentInfo.BillingAddress.PhoneNumber, !string.IsNullOrEmpty(paymentInfo.BillingAddress.FaxNumber) ? ", " + paymentInfo.BillingAddress.FaxNumber : "").AppendLine();
                    body.AppendFormat("Адрес: {0} {1}<br />", paymentInfo.BillingAddress.City, paymentInfo.BillingAddress.Address1).AppendLine();
                    body.AppendFormat("Email: {0}<br /><br />", !string.IsNullOrEmpty(NopContext.Current.User.BillingAddress.Email) ? NopContext.Current.User.BillingAddress.Email : NopContext.Current.User.Email).AppendLine();
                    body.AppendFormat("Комментарии: {0}<br /><br />", tbComments.Text).AppendLine();
                    PaymentMethod pm = PaymentMethodManager.GetPaymentMethodByID(order.PaymentMethodID);
                    if (pm != null)
                    {
                        body.AppendFormat("Способ оплаты: {0}<br /><br />", pm.Name).AppendLine();
                    }

                    decimal total         = 0;
                    decimal indOrderTotal = IndividualOrderManager.GetTotalPriceIndOrders(indOrders);
                    if (Request.Cookies["Currency"] != null && Request.Cookies["Currency"].Value == "USD")
                    {
                        indOrderTotal = Math.Round(PriceConverter.ToUsd(indOrderTotal));
                    }

                    total += indOrderTotal;
                    body.AppendFormat("Индивидуальные заказы:<br />");
                    foreach (var indOrder in indOrders)
                    {
                        body.Append(indOrder.OrderText + "<br />");
                    }

                    if (Session["fn"] != null)
                    {
                        body.AppendLine();
                        body.Append("<b>Получатель не заказчик</b><br />").AppendLine();
                        body.AppendFormat("ФИО: {0} {1}<br />", Session["fn"], Session["ln"]).AppendLine();
                        body.AppendFormat("Телефон: {0}<br />", Session["pn"]).AppendLine();
                        body.AppendFormat("Адрес: {0}<br />", Session["address"]).AppendLine();
                        body.AppendFormat("Дополнительная информация: {0}<br />", Session["ai"]).AppendLine();
                    }
                    body.AppendFormat("Уведомление о доставке: {0} | {1}<br />", chbByMail.Checked ? "Письмом на Email" : "", chbSMS.Checked ? "СМС сообщение" : "").AppendLine();

                    body.AppendFormat("<br /><br /> Заказано:<br />");

                    foreach (OrderProductVariant variant in order.OrderProductVariants)
                    {
                        body.AppendFormat(" - {0} ({1}) x {2}шт. -- {3}; <br />", variant.ProductVariant.Product.Name, PriceHelper.FormatShippingPrice(variant.ProductVariant.Price, true), variant.Quantity, PriceHelper.FormatShippingPrice(variant.ProductVariant.Price * variant.Quantity, true));
                        total += variant.ProductVariant.Price * variant.Quantity;
                    }

                    string shipping = GetLocaleResourceString("ShoppingCart.ShippingNotRequired");

                    bool shoppingCartRequiresShipping = ShippingManager.ShoppingCartRequiresShipping(Cart) && Session["SelfOrder"] == null;
                    if (shoppingCartRequiresShipping)
                    {
                        decimal?shoppingCartShippingBase = ShippingManager.GetShoppingCartShippingTotal(Cart, NopContext.Current.User);
                        if (shoppingCartShippingBase.HasValue)
                        {
                            decimal shoppingCartShipping = CurrencyManager.ConvertCurrency(shoppingCartShippingBase.Value, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
                            shipping = PriceHelper.FormatShippingPrice(shoppingCartShipping, true);
                            total   += shoppingCartShipping;
                        }
                    }

                    body.AppendFormat("Доставка: {0}<br />", shipping).AppendLine();
                    body.AppendFormat("<b>Итого:</b> {0}<br />", total).AppendLine();

                    body.AppendFormat("<br />Дополнительная информация: {0}<br />", Session["ai"]).AppendLine();
                    MessageManager.SendEmail(subj, body.ToString(), MessageManager.AdminEmailAddress, MessageManager.AdminEmailAddress);
                    StartPaymentMethod(indOrders, order);
                    Session.Remove("SelfOrder");
                    Response.Redirect("~/CheckoutCompleted.aspx");
                }
                catch (Exception exc)
                {
                    Session.Remove("SelfOrder");
                    LogManager.InsertLog(LogTypeEnum.OrderError, exc.Message, exc);
                    lError.Text = Server.HtmlEncode("Во время обработки заказа произошла ошибка. Для выполнения заказа, пожалуйста, свяжитесь с администратором. Контактную информацию можно найти на странице Контакты.");
                }
            }
        }
        public void BindData()
        {
            ShoppingCart Cart = ShoppingCartManager.GetCurrentShoppingCart(ShoppingCartTypeEnum.ShoppingCart);

            decimal indOrderTotal = 0;
            IndividualOrderCollection indOrders = new IndividualOrderCollection();

            if (NopContext.Current.Session != null)
            {
                Guid CustomerSessionGUID = NopContext.Current.Session.CustomerSessionGUID;
                indOrders     = IndividualOrderManager.GetIndividualOrderByCurrentUserSessionGuid(CustomerSessionGUID);
                indOrderTotal = IndividualOrderManager.GetTotalPriceIndOrders(indOrders);
                if (Request.Cookies["Currency"] != null && Request.Cookies["Currency"].Value == "USD")
                {
                    indOrderTotal = Math.Round(PriceConverter.ToUsd(indOrderTotal));
                }
            }

            if (Cart.Count > 0 || indOrders.Count > 0)
            {
                //payment method (if already selected)
                int paymentMethodID = 0;
                if (NopContext.Current.User != null)
                {
                    paymentMethodID = NopContext.Current.User.LastPaymentMethodID;
                }

                //subtotal
                string  SubTotalError = string.Empty;
                decimal shoppingCartSubTotalDiscountBase;
                decimal shoppingCartSubTotalBase = ShoppingCartManager.GetShoppingCartSubTotal(Cart, NopContext.Current.User, out shoppingCartSubTotalDiscountBase, ref SubTotalError);
                if (String.IsNullOrEmpty(SubTotalError))
                {
                    decimal shoppingCartSubTotal = CurrencyManager.ConvertCurrency(shoppingCartSubTotalBase, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
                    shoppingCartSubTotal  += indOrderTotal;
                    lblSubTotalAmount.Text = PriceHelper.FormatPrice(shoppingCartSubTotal);
                    if (Request.Cookies["Currency"] != null && Request.Cookies["Currency"].Value == "USD")
                    {
                        lblSubTotalAmount.Text += "$";
                    }

                    lblSubTotalAmount.CssClass = "productPrice";

                    if (shoppingCartSubTotalDiscountBase > decimal.Zero)
                    {
                        decimal shoppingCartSubTotalDiscount = CurrencyManager.ConvertCurrency(shoppingCartSubTotalDiscountBase, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
                        lblSubTotalDiscountAmount.Text = PriceHelper.FormatPrice(shoppingCartSubTotalDiscount, true, false);
                        phSubTotalDiscount.Visible     = true;
                    }
                    else
                    {
                        phSubTotalDiscount.Visible = false;
                    }
                }
                else
                {
                    lblSubTotalAmount.Text     = GetLocaleResourceString("ShoppingCart.CalculatedDuringCheckout");
                    lblSubTotalAmount.CssClass = string.Empty;
                }

                //shipping info
                bool shoppingCartRequiresShipping = ShippingManager.ShoppingCartRequiresShipping(Cart) && Session["SelfOrder"] == null;
                if (shoppingCartRequiresShipping)
                {
                    decimal?shoppingCartShippingBase = ShippingManager.GetShoppingCartShippingTotal(Cart, NopContext.Current.User);
                    if (shoppingCartShippingBase.HasValue)
                    {
                        decimal shoppingCartShipping = CurrencyManager.ConvertCurrency(shoppingCartShippingBase.Value, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);

                        lblShippingAmount.Text = PriceHelper.FormatShippingPrice(shoppingCartShipping, true);
                        if (Request.Cookies["Currency"] != null && Request.Cookies["Currency"].Value == "USD")
                        {
                            lblShippingAmount.Text += "$";
                        }

                        lblShippingAmount.CssClass = "productPrice";
                    }
                    else
                    {
                        lblShippingAmount.Text     = GetLocaleResourceString("ShoppingCart.CalculatedDuringCheckout");
                        lblShippingAmount.CssClass = string.Empty;
                    }
                }
                else
                {
                    lblShippingAmount.Text     = GetLocaleResourceString("ShoppingCart.ShippingNotRequired");
                    lblShippingAmount.CssClass = string.Empty;
                }

                //payment method fee
                bool    displayPaymentMethodFee               = true;
                decimal paymentMethodAdditionalFee            = PaymentManager.GetAdditionalHandlingFee(paymentMethodID);
                decimal paymentMethodAdditionalFeeWithTaxBase = TaxManager.GetPaymentMethodAdditionalFee(paymentMethodAdditionalFee, NopContext.Current.User);
                if (paymentMethodAdditionalFeeWithTaxBase > decimal.Zero)
                {
                    decimal paymentMethodAdditionalFeeWithTax = CurrencyManager.ConvertCurrency(paymentMethodAdditionalFeeWithTaxBase, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
                    lblPaymentMethodAdditionalFee.Text = PriceHelper.FormatPaymentMethodAdditionalFee(paymentMethodAdditionalFeeWithTax, true);
                }
                else
                {
                    displayPaymentMethodFee = false;
                }
                phPaymentMethodAdditionalFee.Visible = displayPaymentMethodFee;

                //tax
                bool displayTax = true;
                if (TaxManager.HideTaxInOrderSummary && NopContext.Current.TaxDisplayType == TaxDisplayTypeEnum.IncludingTax)
                {
                    displayTax = false;
                }
                else
                {
                    string  TaxError            = string.Empty;
                    decimal shoppingCartTaxBase = TaxManager.GetTaxTotal(Cart, paymentMethodID, NopContext.Current.User, ref TaxError);
                    decimal shoppingCartTax     = CurrencyManager.ConvertCurrency(shoppingCartTaxBase, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);

                    //if (String.IsNullOrEmpty(TaxError))
                    //{
                    //    if (shoppingCartTaxBase == 0 && TaxManager.HideZeroTax)
                    //    {
                    //        displayTax = false;
                    //    }
                    //    else
                    //    {
                    //        lblTaxAmount.Text = PriceHelper.FormatPrice(shoppingCartTax, true, false);
                    //        lblTaxAmount.CssClass = "productPrice";
                    //    }
                    //}
                    //else
                    //{
                    //    lblTaxAmount.Text = GetLocaleResourceString("ShoppingCart.CalculatedDuringCheckout");
                    //    lblTaxAmount.CssClass = string.Empty;
                    //}
                }
                phTaxTotal.Visible = false;// displayTax;

                //total
                decimal?shoppingCartTotalBase = ShoppingCartManager.GetShoppingCartTotal(Cart, paymentMethodID, NopContext.Current.User);
                if (shoppingCartTotalBase.HasValue)
                {
                    decimal shoppingCartTotal = CurrencyManager.ConvertCurrency(shoppingCartTotalBase.Value, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);

                    if (Session["SelfOrder"] != null)
                    {
                        shoppingCartTotal -= ShippingManager.GetShoppingCartShippingTotal(Cart).Value;
                    }
                    shoppingCartTotal  += indOrderTotal;
                    lblTotalAmount.Text = PriceHelper.FormatPrice(shoppingCartTotal);
                    if (Request.Cookies["Currency"] != null && Request.Cookies["Currency"].Value == "USD")
                    {
                        lblTotalAmount.Text += "$";
                    }

                    lblTotalAmount.CssClass = "productPrice";
                }
                else
                {
                    lblTotalAmount.Text     = GetLocaleResourceString("ShoppingCart.CalculatedDuringCheckout");
                    lblTotalAmount.CssClass = string.Empty;
                }
            }
            else
            {
                this.Visible = false;
            }
        }