Beispiel #1
0
        private string SaveOrder(bool saveToDB)
        {
            try
            {
                //validation
                SiteSettings siteSettings = CacheHelper.GetCurrentSiteSettings();
                var          cart         = CartHelper.GetShoppingCart(siteSettings.SiteId, ShoppingCartTypeEnum.ShoppingCart);

                if (cart.Count == 0)
                {
                    return(StringHelper.ToJsonString(new
                    {
                        success = false,
                        message = ProductResources.CartIsEmptyLabel
                    }));
                }

                //if (!ProductConfiguration.OnePageCheckoutEnabled)
                //{
                //    return StringHelper.ToJsonString(new
                //    {
                //        success = false,
                //        message = "One page checkout is disabled"
                //    });
                //}

                if ((!Request.IsAuthenticated && !ProductConfiguration.AnonymousCheckoutAllowed))
                {
                    return(StringHelper.ToJsonString(new
                    {
                        success = false,
                        message = ProductResources.CheckoutAnonymousNotAllowed
                    }));
                }

                //string validateResult = string.Empty;
                //bool validate = CheckValidate(out validateResult);
                //if (!validate)
                //    return validateResult;

                Order order = CartHelper.GetOrderSession(siteSettings.SiteId);
                if (order == null)
                {
                    order        = new Order();
                    order.SiteId = siteSettings.SiteId;
                }

                order.BillingFirstName = GetPostValue("Address_FirstName", order.BillingFirstName);
                order.BillingLastName  = GetPostValue("Address_LastName", order.BillingLastName);
                order.BillingEmail     = GetPostValue("Address_Email", order.BillingEmail);
                order.BillingAddress   = GetPostValue("Address_Address", order.BillingAddress);
                order.BillingPhone     = GetPostValue("Address_Phone", order.BillingPhone);
                order.BillingMobile    = GetPostValue("Address_Mobile", order.BillingMobile);
                order.BillingFax       = GetPostValue("Address_Fax", order.BillingFax);
                order.BillingStreet    = GetPostValue("Address_Street", order.BillingStreet);
                order.BillingWard      = GetPostValue("Address_Ward", order.BillingWard);

                string district = GetPostValue("Address_District", order.BillingDistrictGuid.ToString());
                if (district.Length == 36)
                {
                    order.BillingDistrictGuid = new Guid(district);
                }
                else
                {
                    order.BillingDistrictGuid = Guid.Empty;
                }

                string province = GetPostValue("Address_Province", order.BillingProvinceGuid.ToString());
                if (province.Length == 36)
                {
                    order.BillingProvinceGuid = new Guid(province);
                }
                else
                {
                    order.BillingProvinceGuid = Guid.Empty;
                }

                string country = GetPostValue("Address_Country", order.BillingCountryGuid.ToString());
                if (country.Length == 36)
                {
                    order.BillingCountryGuid = new Guid(country);
                }
                else
                {
                    order.BillingCountryGuid = Guid.Empty;
                }

                // Shipping method
                bool hasShipping = false;
                foreach (var key in postParams.AllKeys)
                {
                    if (key == "ShippingMethod")
                    {
                        hasShipping = true;
                        break;
                    }
                }
                if (hasShipping)
                {
                    order.ShippingMethod = -1;
                    string shippingMethod     = GetPostValue("ShippingMethod");
                    var    lstShippingMethods = ShippingMethod.GetByActive(siteSettings.SiteId, 1);
                    foreach (ShippingMethod shipping in lstShippingMethods)
                    {
                        if (shippingMethod == shipping.ShippingMethodId.ToString())
                        {
                            order.ShippingMethod = shipping.ShippingMethodId;
                            break;
                        }
                    }

                    if (order.ShippingMethod == -1)
                    {
                        return(StringHelper.ToJsonString(new
                        {
                            success = false,
                            message = ProductResources.CheckoutShippingMethodRequired
                        }));
                    }
                }

                // Payment method
                bool hasPayment = false;
                foreach (var key in postParams.AllKeys)
                {
                    if (key == "PaymentMethod")
                    {
                        hasPayment = true;
                        break;
                    }
                }
                if (hasPayment)
                {
                    order.PaymentMethod = -1;
                    string paymentMethod     = GetPostValue("PaymentMethod");
                    var    lstPaymentMethods = PaymentMethod.GetByActive(siteSettings.SiteId, 1);
                    foreach (PaymentMethod payment in lstPaymentMethods)
                    {
                        if (paymentMethod == payment.PaymentMethodId.ToString())
                        {
                            order.PaymentMethod = payment.PaymentMethodId;
                            break;
                        }
                    }

                    if (order.PaymentMethod == -1)
                    {
                        return(StringHelper.ToJsonString(new
                        {
                            success = false,
                            message = ProductResources.CheckoutPaymentMethodRequired
                        }));
                    }
                }

                // Company Info
                order.InvoiceCompanyName    = GetPostValue("Invoice.CompanyName", order.InvoiceCompanyName);
                order.InvoiceCompanyAddress = GetPostValue("Invoice.CompanyAddress", order.InvoiceCompanyAddress);
                order.InvoiceCompanyTaxCode = GetPostValue("Invoice.CompanyTaxCode", order.InvoiceCompanyTaxCode);
                order.OrderNote             = GetPostValue("OrderNote", order.OrderNote);

                string result = string.Empty;
                if (!IsBillingAddressValid(order, out result))
                {
                    return(result);
                }
                if (!IsShippingAddressValid(order, out result))
                {
                    return(result);
                }

                if (saveToDB)
                {
                    order.OrderCode     = ProductHelper.GenerateOrderCode(order.SiteId);
                    order.CreatedFromIP = SiteUtils.GetIP4Address();
                    if (Request.IsAuthenticated)
                    {
                        SiteUser siteUser = SiteUtils.GetCurrentSiteUser();
                        if (siteUser != null)
                        {
                            order.UserGuid = siteUser.UserGuid;
                            siteUser.ICQ   = order.BillingProvinceGuid.ToString();
                            siteUser.AIM   = order.BillingDistrictGuid.ToString();
                            siteUser.Save();
                        }
                    }

                    order.Save();
                    if (SaveOrderSummary(order, cart))
                    {
                        //CartHelper.CouponCodeInput = null;
                        CartHelper.ClearCartCookie(order.SiteId);
                        CartHelper.SetOrderSession(siteSettings.SiteId, null);
                        HttpContext.Current.Session[GetOrderIDSessionKey(order.SiteId)] = order.OrderId;

                        var onePayUrl = OnePayHelper.GetPaymentUrlIfNeeded(order);
                        if (!string.IsNullOrEmpty(onePayUrl))
                        {
                            //System.Timers.Timer timer1 = new System.Timers.Timer();
                            //timer1.Interval = 5 * 60 * 1000; //ms, 5 minutes
                            //timer1.Elapsed += new System.Timers.ElapsedEventHandler(timer1_Elapsed);
                            //timer1.Enabled = true;
                            //GC.KeepAlive(timer1);

                            return(StringHelper.ToJsonString(new
                            {
                                success = true,
                                redirect = onePayUrl
                            }));
                        }
                    }
                }
                else
                {
                    CartHelper.SetOrderSession(siteSettings.SiteId, order);
                }

                return(StringHelper.ToJsonString(new
                {
                    success = true,
                    redirect = GetPostValue("redirect", string.Empty)
                }));
            }
            catch (Exception ex)
            {
                log.Error(ex.Message);
                return(StringHelper.ToJsonString(new { success = false, message = ex.Message }));
            }
        }
Beispiel #2
0
        private DataTable GetOrdersForExport()
        {
            DataTable dt = new DataTable();

            dt.Columns.Add("Number", typeof(int));
            dt.Columns.Add("OrderCode", typeof(string));
            dt.Columns.Add("OrderStatus", typeof(string));
            dt.Columns.Add("Date", typeof(string));
            dt.Columns.Add("CreatedTime", typeof(string));
            dt.Columns.Add("Products", typeof(string));
            dt.Columns.Add("SubTotal", typeof(double));
            dt.Columns.Add("OrderDiscount", typeof(double));
            dt.Columns.Add("OrderShipping", typeof(double));
            dt.Columns.Add("OrderTax", typeof(double));
            dt.Columns.Add("OrderTotal", typeof(double));

            List <ShippingMethod> lstShippingMethods = ShippingMethod.GetByActive(siteSettings.SiteId, 1);
            List <PaymentMethod>  lstPaymentMethods  = PaymentMethod.GetByActive(siteSettings.SiteId, 1);

            if (lstShippingMethods.Count > 0)
            {
                dt.Columns.Add("ShippingMethod", typeof(string));
            }
            if (lstPaymentMethods.Count > 0)
            {
                dt.Columns.Add("PaymentMethod", typeof(string));
            }

            dt.Columns.Add("FirstName", typeof(string));
            dt.Columns.Add("LastName", typeof(string));
            dt.Columns.Add("Customer Code", typeof(string));

            int      status   = Convert.ToInt32(ddOrderStatus.SelectedValue);
            DateTime?fromdate = null;
            DateTime?todate   = null;

            if (dpFromDate.Text.Trim().Length > 0)
            {
                DateTime localTime = DateTime.Parse(dpFromDate.Text);
                localTime = new DateTime(localTime.Year, localTime.Month, localTime.Day, 0, 0, 0);

                if (timeZone != null)
                {
                    fromdate = localTime.ToUtc(timeZone);
                }
                else
                {
                    fromdate = localTime.AddHours(-timeOffset);
                }
            }
            if (dpToDate.Text.Trim().Length > 0)
            {
                DateTime localTime = DateTime.Parse(dpToDate.Text);
                localTime = new DateTime(localTime.Year, localTime.Month, localTime.Day, 23, 59, 59);

                if (timeZone != null)
                {
                    todate = localTime.ToUtc(timeZone);
                }
                else
                {
                    todate = localTime.AddHours(-timeOffset);
                }
            }

            var iCount    = Order.GetCount(siteSettings.SiteId, -1, status, -1, -1, fromdate, todate, null, null, null, txtKeyword.Text.Trim());
            var lstOrders = Order.GetPage(siteSettings.SiteId, -1, status, -1, -1, fromdate, todate, null, null, null, txtKeyword.Text.Trim(), 1, iCount);

            if (lstOrders.Count > 0)
            {
                List <Guid> lstProvinceGuids = new List <Guid>();
                List <Guid> lstDistrictGuids = new List <Guid>();
                foreach (Order o in lstOrders)
                {
                    if (!lstProvinceGuids.Contains(o.BillingProvinceGuid))
                    {
                        lstProvinceGuids.Add(o.BillingProvinceGuid);
                    }
                    if (!lstDistrictGuids.Contains(o.BillingDistrictGuid))
                    {
                        lstDistrictGuids.Add(o.BillingDistrictGuid);
                    }
                }

                List <GeoZone> lstProvinces = new List <GeoZone>();
                List <GeoZone> lstDistricts = new List <GeoZone>();
                if (lstProvinceGuids.Count > 0)
                {
                    lstProvinces = GeoZone.GetByGuids(string.Join(";", lstProvinceGuids.ToArray()), 1);
                }
                if (lstDistrictGuids.Count > 0)
                {
                    lstDistricts = GeoZone.GetByGuids(string.Join(";", lstDistrictGuids.ToArray()), 1);
                }
                if (lstProvinces.Count > 0)
                {
                    dt.Columns.Add("Province", typeof(string));
                }
                if (lstDistricts.Count > 0)
                {
                    dt.Columns.Add("District", typeof(string));
                }

                int i = 1;
                foreach (Order o in lstOrders)
                {
                    DataRow row = dt.NewRow();

                    row["Number"]      = i;
                    row["OrderCode"]   = o.OrderCode;
                    row["OrderStatus"] = ProductHelper.GetOrderStatus(o.OrderStatus);
                    row["Date"]        = ProductHelper.FormatDate(o.CreatedUtc, timeZone, timeOffset, "dd/MM/yyyy");
                    row["CreatedTime"] = ProductHelper.FormatDate(o.CreatedUtc, timeZone, timeOffset, "HH:mm");

                    var    lstProducts = Product.GetByOrder(siteSettings.SiteId, o.OrderId);
                    string products    = string.Empty;
                    string sepa        = string.Empty;
                    foreach (Product product in lstProducts)
                    {
                        products += sepa + product.Title;
                        sepa      = ";" + System.Environment.NewLine;
                    }
                    row["Products"] = products;

                    row["SubTotal"]      = Convert.ToDouble(o.OrderSubtotal);
                    row["OrderDiscount"] = Convert.ToDouble(o.OrderDiscount);
                    row["OrderShipping"] = Convert.ToDouble(o.OrderShipping);
                    row["OrderTax"]      = Convert.ToDouble(o.OrderTax);
                    row["OrderTotal"]    = Convert.ToDouble(o.OrderTotal);

                    if (lstShippingMethods.Count > 0)
                    {
                        string name = string.Empty;
                        if (o.ShippingMethod > 0)
                        {
                            foreach (ShippingMethod method in lstShippingMethods)
                            {
                                if (method.ShippingMethodId == o.ShippingMethod)
                                {
                                    name = method.Name;
                                    break;
                                }
                            }
                        }

                        row["ShippingMethod"] = name;
                    }
                    if (lstPaymentMethods.Count > 0)
                    {
                        string name = string.Empty;
                        if (o.PaymentMethod > 0)
                        {
                            foreach (PaymentMethod method in lstPaymentMethods)
                            {
                                if (method.PaymentMethodId == o.PaymentMethod)
                                {
                                    name = method.Name;
                                    break;
                                }
                            }
                        }

                        row["PaymentMethod"] = name;
                    }

                    row["FirstName"] = o.BillingFirstName;
                    row["LastName"]  = o.BillingLastName;
                    var user = new SiteUser(siteSettings, o.UserGuid);
                    row["Customer Code"] = user.Name;
                    if (lstProvinces.Count > 0)
                    {
                        string name = string.Empty;
                        if (o.BillingProvinceGuid != Guid.Empty)
                        {
                            foreach (GeoZone gz in lstProvinces)
                            {
                                if (gz.Guid == o.BillingProvinceGuid)
                                {
                                    name = gz.Name;
                                    break;
                                }
                            }
                        }

                        row["Province"] = name;
                    }
                    if (lstDistricts.Count > 0)
                    {
                        string name = string.Empty;
                        if (o.BillingDistrictGuid != Guid.Empty)
                        {
                            foreach (GeoZone gz in lstDistricts)
                            {
                                if (gz.Guid == o.BillingDistrictGuid)
                                {
                                    name = gz.Name;
                                    break;
                                }
                            }
                        }

                        row["District"] = name;
                    }

                    i += 1;
                    dt.Rows.Add(row);
                }
            }

            return(dt);
        }
        private void PopulateControls()
        {
            var doc = new XmlDocument();

            doc.LoadXml("<CheckoutMethod></CheckoutMethod>");
            XmlElement root = doc.DocumentElement;

            XmlHelper.AddNode(doc, root, "ModuleTitle", this.Title);
            XmlHelper.AddNode(doc, root, "ZoneTitle", CurrentZone.Name);
            if (ModuleConfiguration.ResourceFileDef.Length > 0 && ModuleConfiguration.ResourceKeyDef.Length > 0)
            {
                List <string> lstResourceKeys = ModuleConfiguration.ResourceKeyDef.SplitOnCharAndTrim(';');

                foreach (string item in lstResourceKeys)
                {
                    XmlHelper.AddNode(doc, root, item, ResourceHelper.GetResourceString(ModuleConfiguration.ResourceFileDef, item));
                }
            }

            XmlHelper.AddNode(doc, root, "CompanyNameText", ProductResources.CheckoutCompanyName);
            XmlHelper.AddNode(doc, root, "CompanyTaxCodeText", ProductResources.CheckoutCompanyTaxCode);
            XmlHelper.AddNode(doc, root, "CompanyAddressText", ProductResources.CheckoutCompanyAddress);
            XmlHelper.AddNode(doc, root, "OrderNoteText", ProductResources.CheckoutOrderNote);

            if (config.CheckoutNextZoneId > 0)
            {
                XmlHelper.AddNode(doc, root, "NextPageUrl", CartHelper.GetZoneUrl(config.CheckoutNextZoneId));
            }

            int    languageId         = WorkingCulture.LanguageId;
            string shippingMethod     = string.Empty;
            string paymentMethod      = string.Empty;
            var    lstShippingMethods = ShippingMethod.GetByActive(siteSettings.SiteId, 1, languageId);

            foreach (ShippingMethod shipping in lstShippingMethods)
            {
                XmlElement shippingItemXml = doc.CreateElement("Shipping");
                root.AppendChild(shippingItemXml);

                XmlHelper.AddNode(doc, shippingItemXml, "Title", shipping.Name);
                XmlHelper.AddNode(doc, shippingItemXml, "Description", shipping.Description);
                XmlHelper.AddNode(doc, shippingItemXml, "Id", shipping.ShippingMethodId.ToString());

                if (order != null && shipping.ShippingMethodId == order.ShippingMethod)
                {
                    XmlHelper.AddNode(doc, shippingItemXml, "IsActive", "true");
                    shippingMethod = shipping.Name;
                }
            }

            var lstPaymentMethods = PaymentMethod.GetByActive(siteSettings.SiteId, 1, languageId);

            foreach (PaymentMethod payment in lstPaymentMethods)
            {
                XmlElement paymentItemXml = doc.CreateElement("Payment");
                root.AppendChild(paymentItemXml);

                XmlHelper.AddNode(doc, paymentItemXml, "Title", payment.Name);
                XmlHelper.AddNode(doc, paymentItemXml, "Description", payment.Description);
                XmlHelper.AddNode(doc, paymentItemXml, "Id", payment.PaymentMethodId.ToString());

                if (order != null && payment.PaymentMethodId == order.PaymentMethod)
                {
                    XmlHelper.AddNode(doc, paymentItemXml, "IsActive", "true");
                    paymentMethod = payment.Name;
                }
            }

            if (order != null)
            {
                XmlHelper.AddNode(doc, root, "CompanyName", order.InvoiceCompanyName);
                XmlHelper.AddNode(doc, root, "CompanyTaxCode", order.InvoiceCompanyTaxCode);
                XmlHelper.AddNode(doc, root, "CompanyAddress", order.InvoiceCompanyAddress);
                XmlHelper.AddNode(doc, root, "OrderNote", order.OrderNote);
                XmlHelper.AddNode(doc, root, "ShippingMethodId", order.ShippingMethod.ToString());
                XmlHelper.AddNode(doc, root, "ShippingMethod", shippingMethod);
                XmlHelper.AddNode(doc, root, "PaymentMethodId", order.PaymentMethod.ToString());
                XmlHelper.AddNode(doc, root, "PaymentMethod", paymentMethod);
            }

            XmlHelper.XMLTransform(xmlTransformer, SiteUtils.GetXsltBasePath("product", ModuleConfiguration.XsltFileName), doc);
        }
Beispiel #4
0
 void grid_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
 {
     grid.DataSource = PaymentMethod.GetByActive(siteSettings.SiteId, -1);
 }