예제 #1
0
        protected bool CreateCertificateOrder()
        {
            var certificate = new GiftCertificate
                {
                    CertificateCode = GiftCertificateService.GenerateCertificateCode(),
                    ToName = txtTo.Text,
                    FromName = txtFrom.Text,
                    Sum = Convert.ToSingle(txtSum.Text.Trim()) * CurrencyService.CurrentCurrency.Value,
                    CertificateMessage = txtMessage.Text,
                    Enable = true,
                    ToEmail = txtEmail.Text
                };

            var orderContact = new OrderContact
                {
                    Address = string.Empty,
                    City = string.Empty,
                    Country = string.Empty,
                    Name = string.Empty,
                    Zip = string.Empty,
                    Zone = string.Empty
                };

            float taxTotalPrice = 0;
            var orderTaxes = new List<TaxValue>();
            foreach (var taxId in GiftCertificateService.GetCertificateTaxesId())
            {
                var tax = TaxServices.GetTax(taxId);
                orderTaxes.Add(new TaxValue
                    {
                        TaxID = tax.TaxId,
                        TaxName = tax.Name,
                        TaxShowInPrice = tax.ShowInPrice,
                        TaxSum = tax.FederalRate
                    });
                taxTotalPrice += TaxServices.CalculateTax(certificate.Sum, tax);
            }

            float orderSum = certificate.Sum + taxTotalPrice;

            var payment = PaymentService.GetPaymentMethod(hfPaymentMethod.Value.TryParseInt());
            float paymentPrice = payment.Extracharge == 0 ? 0 : (payment.ExtrachargeType == ExtrachargeType.Fixed ? payment.Extracharge : payment.Extracharge / 100 * certificate.Sum + taxTotalPrice);

            var order = new Order
                {
                    OrderDate = DateTime.Now,
                    OrderCustomer = new OrderCustomer
                        {
                            CustomerID = CustomerSession.CurrentCustomer.Id,
                            Email = txtEmailFrom.Text,
                            FirstName = CustomerSession.CurrentCustomer.FirstName,
                            LastName = CustomerSession.CurrentCustomer.LastName,
                            CustomerIP = HttpContext.Current.Request.UserHostAddress
                        },
                    OrderCurrency = new OrderCurrency
                        {
                            CurrencyCode = CurrencyService.CurrentCurrency.Iso3,
                            CurrencyNumCode = CurrencyService.CurrentCurrency.NumIso3,
                            CurrencyValue = CurrencyService.CurrentCurrency.Value,
                            CurrencySymbol = CurrencyService.CurrentCurrency.Symbol,
                            IsCodeBefore = CurrencyService.CurrentCurrency.IsCodeBefore
                        },
                    OrderStatusId = OrderService.DefaultOrderStatus,
                    AffiliateID = 0,
                    ArchivedShippingName = Resource.Client_GiftCertificate_DeliveryByEmail,
                    PaymentMethodId = Convert.ToInt32(hfPaymentMethod.Value),
                    ArchivedPaymentName = payment.Name,
                    PaymentDetails = null,
                    Sum = orderSum + paymentPrice,
                    PaymentCost = paymentPrice,
                    OrderCertificates = new List<GiftCertificate>
                        {
                            certificate
                        },
                    TaxCost = taxTotalPrice,
                    Taxes = orderTaxes,
                    ShippingContact = orderContact,
                    BillingContact = orderContact,
                    Number = OrderService.GenerateNumber(1)
                };

            if (order.PaymentMethod.Type == PaymentType.QIWI)
            {
                order.PaymentDetails = new PaymentDetails() {Phone = txtPhone.Text};
            }

            OrderId = order.OrderID = OrderService.AddOrder(order);
            OrderNumber = order.Number = OrderService.GenerateNumber(order.OrderID);
            OrderService.UpdateNumber(order.OrderID, order.Number);
            OrderService.ChangeOrderStatus(order.OrderID, OrderService.DefaultOrderStatus);

            string email = txtEmailFrom.Text;

            string htmlOrderTable = OrderService.GenerateHtmlOrderCertificateTable(order.OrderCertificates,
                                                                                   CurrencyService.CurrentCurrency,
                                                                                   order.PaymentCost, order.TaxCost);

            string htmlMessage = SendMail.BuildMail(new ClsMailParamOnNewOrder
            {
                CustomerContacts = string.Empty,
                PaymentType = order.ArchivedPaymentName,
                ShippingMethod = order.ArchivedShippingName,
                CurrentCurrencyCode = CurrencyService.CurrentCurrency.Iso3,
                TotalPrice = order.Sum.ToString(),
                Comments = order.CustomerComment,
                Email = email,
                OrderTable = htmlOrderTable,
                OrderID = order.OrderID.ToString(),
                Number = order.Number
            });

            SendMail.SendMailNow(email, Resource.Client_OrderConfirmation_ReceivedOrder + " " + order.OrderID, htmlMessage, true);
            SendMail.SendMailNow(SettingsMail.EmailForOrders, Resource.Client_OrderConfirmation_ReceivedOrder + " " + order.OrderID, htmlMessage, true);

            return OrderId != 0;
        }
예제 #2
0
 /// <summary>
 /// Adds order contacts with equals shipping and billing contacts
 /// </summary>
 /// <param name="orderId"></param>
 /// <param name="onlyContact"></param>
 private static bool AddOrderContacts(int orderId, OrderContact onlyContact)
 {
     int contactID = AddOrderContact(orderId, onlyContact, OrderContactType.ShippingContact);
     UpdateOrderContactId(orderId, contactID, OrderContactType.BillingContact);
     return contactID != 0;
 }
예제 #3
0
 /// <summary>
 /// Adds order billing and shipping contacts
 /// </summary>
 /// <param name="orderId"></param>
 /// <param name="shippingContact"></param>
 /// <param name="billingContact"></param>
 private static bool AddOrderContacts(int orderId, OrderContact shippingContact, OrderContact billingContact)
 {
     bool res = true;
     res &= (AddOrderContact(orderId, shippingContact, OrderContactType.ShippingContact) != 0);
     res &= (AddOrderContact(orderId, billingContact, OrderContactType.BillingContact) != 0);
     return res;
 }
예제 #4
0
        private static int AddOrderContact(int orderID, OrderContact contact, OrderContactType type)
        {
            contact.OrderContactId = SQLDataHelper.GetInt(SQLDataAccess.ExecuteScalar(
                @"INSERT INTO [Order].[OrderContact]
                               ([Name],[Country],[Zone],[City],[Zip],[Address])
                         VALUES
                               (@Name,@Country,@Zone,@City,@Zip,@Address);
                    SELECT scope_identity();",
                CommandType.Text,
                new SqlParameter("@Name", contact.Name ?? string.Empty),
                new SqlParameter("@Country", contact.Country ?? string.Empty),
                new SqlParameter("@Zone", contact.Zone ?? string.Empty),
                new SqlParameter("@City", contact.City ?? string.Empty),
                new SqlParameter("@Zip", contact.Zip ?? string.Empty),
                new SqlParameter("@Address", contact.Address ?? string.Empty)
                ));

            UpdateOrderContactId(orderID, contact.OrderContactId, type);
            return contact.OrderContactId;
        }
예제 #5
0
        public static bool UpdateOrderContacts(int orderId, OrderContact shippingContact, OrderContact billingContact)
        {
            bool res = true;
            ClearOrderContacts(orderId);
            if (shippingContact == billingContact)
                res &= AddOrderContacts(orderId, shippingContact);
            else
                res &= AddOrderContacts(orderId, shippingContact, billingContact);
            if (res)
                return RefreshTotal(orderId);

            return false;
        }
예제 #6
0
        protected void btnBuyInOneClick_OnClick(object sender, EventArgs e)
        {
            if (txtName.Text.IsNullOrEmpty() || txtPhone.Text.IsNullOrEmpty())
            {
                errorMsg.Text = Resources.Resource.Client_OneClick_WrongData;
                return;
            }

            var shoppingCart = ShoppingCartService.CurrentShoppingCart;
            float totalPrice = shoppingCart.TotalPrice;
            float discountPercentOnTotalPrice = shoppingCart.DiscountPercentOnTotalPrice;

            if (shoppingCart.TotalPrice < AdvantShop.Configuration.SettingsOrderConfirmation.MinimalOrderPrice)
            {
                errorMsg.Text = string.Format(Resources.Resource.Client_ShoppingCart_MinimalOrderPrice,
                                              CatalogService.GetStringPrice(
                                                  AdvantShop.Configuration.SettingsOrderConfirmation
                                                            .MinimalOrderPrice),
                                              CatalogService.GetStringPrice(
                                                  AdvantShop.Configuration.SettingsOrderConfirmation
                                                            .MinimalOrderPrice - totalPrice));
                return;
            }

            var orderItems = shoppingCart.Select(item => (OrderItem) item).ToList();

            OrderCertificate orderCertificate = null;
            OrderCoupon orderCoupon = null;

            GiftCertificate certificate = shoppingCart.Certificate;
            Coupon coupon = shoppingCart.Coupon;

            if (certificate != null)
            {
                orderCertificate = new OrderCertificate()
                {
                    Code = certificate.CertificateCode,
                    Price = certificate.Sum
                };
            }
            if (coupon != null && shoppingCart.TotalPrice >= coupon.MinimalOrderPrice)
            {
                orderCoupon = new OrderCoupon()
                {
                    Code = coupon.Code,
                    Type = coupon.Type,
                    Value = coupon.Value
                };
            }

            var orderContact = new OrderContact
            {
                Address = string.Empty,
                City = string.Empty,
                Country = string.Empty,
                Name = string.Empty,
                Zip = string.Empty,
                Zone = string.Empty
            };

            var customerGroup = CustomerSession.CurrentCustomer.CustomerGroup;
            var order = new Order
            {
                CustomerComment = txtComment.Text,
                OrderDate = DateTime.Now,
                OrderCurrency = new OrderCurrency
                {
                    CurrencyCode = CurrencyService.CurrentCurrency.Iso3,
                    CurrencyNumCode = CurrencyService.CurrentCurrency.NumIso3,
                    CurrencySymbol = CurrencyService.CurrentCurrency.Symbol,
                    CurrencyValue = CurrencyService.CurrentCurrency.Value,
                    IsCodeBefore = CurrencyService.CurrentCurrency.IsCodeBefore
                },
                OrderCustomer = new OrderCustomer
                {
                    CustomerID = CustomerSession.CurrentCustomer.Id,
                    Email = CustomerSession.CurrentCustomer.EMail,
                    FirstName = txtName.Text,
                    LastName = string.Empty,
                    MobilePhone = txtPhone.Text,
                    CustomerIP = HttpContext.Current.Request.UserHostAddress
                },

                OrderStatusId = OrderService.DefaultOrderStatus,
                AffiliateID = 0,
                GroupName = customerGroup.GroupName,
                GroupDiscount = customerGroup.GroupDiscount,

                OrderItems = orderItems,
                OrderDiscount = discountPercentOnTotalPrice,
                Number = OrderService.GenerateNumber(1),
                ShippingContact = orderContact,
                BillingContact = orderContact,
                Certificate = orderCertificate,
                Coupon = orderCoupon,
                AdminOrderComment = Resources.Resource.Client_BuyInOneClick_Header
            };

            order.OrderID = OrderService.AddOrder(order);
            order.Number = OrderService.GenerateNumber(order.OrderID);
            OrderService.UpdateNumber(order.OrderID, order.Number);
            OrderService.ChangeOrderStatus(order.OrderID, OrderService.DefaultOrderStatus);

            if (order.OrderID != 0)
            {
               string message = SendMail.BuildMail(new ClsMailParamOnBuyInOneClick
                    {
                        Name = HttpUtility.HtmlEncode(txtName.Text),
                        Phone = HttpUtility.HtmlEncode(txtPhone.Text),
                        Comment = HttpUtility.HtmlEncode(txtComment.Text),
                        OrderTable = OrderService.GenerateHtmlOrderTable(
                            order.OrderItems,
                            CurrencyService.CurrentCurrency,
                            totalPrice,
                            discountPercentOnTotalPrice,
                            orderCoupon,
                            orderCertificate,
                            discountPercentOnTotalPrice > 0 ? discountPercentOnTotalPrice * totalPrice / 100 : 0,
                            0,
                            0,
                            0,
                            CustomerSession.CurrentCustomer.Contacts.Count > 0
                                ? CustomerSession.CurrentCustomer.Contacts[0]
                                : new CustomerContact(),
                            CustomerSession.CurrentCustomer.Contacts.Count > 0
                                ? CustomerSession.CurrentCustomer.Contacts[0]
                                : new CustomerContact()),
                    });

                    SendMail.SendMailNow(AdvantShop.Configuration.SettingsMail.EmailForOrders,
                                         AdvantShop.Configuration.SettingsMain.SiteUrl + " - " +
                                         Resources.Resource.Client_BuyInOneClick_Header, message, true);
            }

            ModulesRenderer.OrderAdded(order.OrderID);

            if (order.OrderID != 0)
            {
                ShoppingCartService.ClearShoppingCart(ShoppingCartType.ShoppingCart, CustomerSession.CustomerId);
                Response.Redirect("~/orderconfirmation.aspx?step=FinalTab");
            }
            else
            {
                errorMsg.Text = Resources.Resource.Client_ShoppingCart_Error;
            }
        }