private Order DoCreateOrder()
        {
            var shoppingCart = ShoppingCartService.CurrentShoppingCart;

            if (shoppingCart.GetHashCode() != PageData.OrderConfirmationData.CheckSum || !shoppingCart.HasItems)
            {
                Response.Redirect("shoppingcart.aspx");
                return(null);
            }

            if (PageData.OrderConfirmationData.UserType == EnUserType.JustRegistredUser)
            {
                RegistrationNow();
            }

            if (PageData.OrderConfirmationData.UserType == EnUserType.RegisteredUserWithoutAddress)
            {
                UpdateCustomerContact();
            }

            var order = CreateOrder(shoppingCart);

            SendOrderMail(order, shoppingCart);

            var certificate = shoppingCart.Certificate;

            if (certificate != null)
            {
                certificate.ApplyOrderNumber = order.Number;
                certificate.Used             = true;
                certificate.Enable           = true;

                GiftCertificateService.DeleteCustomerCertificate(certificate.CertificateId);
                GiftCertificateService.UpdateCertificateById(certificate);
            }

            var coupon = shoppingCart.Coupon;

            if (coupon != null && shoppingCart.TotalPrice >= coupon.MinimalOrderPrice)
            {
                coupon.ActualUses += 1;
                CouponService.UpdateCoupon(coupon);
                CouponService.DeleteCustomerCoupon(coupon.CouponID);
            }

            ShoppingCartService.ClearShoppingCart(ShoppingCartType.ShoppingCart, PageData.OrderConfirmationData.Customer.Id);
            ShoppingCartService.ClearShoppingCart(ShoppingCartType.ShoppingCart, CustomerContext.CustomerId);

            ShippingManager.CurrentShippingRates.Clear();

            OrderConfirmationService.Delete(CustomerContext.CustomerId);

            return(order);
        }
Exemplo n.º 2
0
    private Order DoCreateOrder()
    {
        var shoppingCart = ShoppingCartService.CurrentShoppingCart;

        if (shoppingCart.GetHashCode() != PageData.OrderConfirmationData.CheckSum || !shoppingCart.HasItems)
        {
            Redirect("shoppingcart.aspx");
            return(null);
        }

        if (PageData.OrderConfirmationData.UserType == EnUserType.JustRegistredUser)
        {
            RegistrationNow();
        }


        var ord = CreateOrder(shoppingCart);

        var    paymentMethod = PaymentService.GetPaymentMethod(ord.PaymentMethodId);
        string email         = PageData.OrderConfirmationData.Customer.EMail;

        string htmlOrderTable = OrderService.GenerateHtmlOrderTable(ord.OrderItems, CurrencyService.CurrentCurrency,
                                                                    shoppingCart.TotalPrice,
                                                                    shoppingCart.DiscountPercentOnTotalPrice,
                                                                    ord.Coupon, ord.Certificate,
                                                                    shoppingCart.TotalDiscount,
                                                                    ord.ShippingCost,
                                                                    PageData.OrderConfirmationData.TaxesTotal,
                                                                    PageData.OrderConfirmationData.BillingContact,
                                                                    PageData.OrderConfirmationData.ShippingContact);

        // declare class to collect info about what was buy
        var googleAnalystic = new GoogleAnalyticsString();
        var trans           = new GoogleAnalyticsTrans
        {
            OrderId     = ord.OrderID.ToString(),
            Affiliation = SettingsMain.ShopName,
            Total       = shoppingCart.TotalPrice.ToString("F2", System.Globalization.CultureInfo.InvariantCulture),
            Tax         = (PageData.OrderConfirmationData.TaxesTotal).ToString("F2", System.Globalization.CultureInfo.InvariantCulture),
            Shipping    = ord.ShippingCost.ToString("F2", System.Globalization.CultureInfo.InvariantCulture),
            City        = string.Empty,
            State       = string.Empty,
            Country     = string.Empty,
        };

        googleAnalystic.Trans = trans;
        googleAnalystic.Items = GetListItemForGoogleAnalytics(shoppingCart, ord.OrderID.ToString());
        ltGaECommerce.Text    = googleAnalystic.GetGoogleAnalyticsEComerceString();


        // Build a new mail
        var customerSb = new StringBuilder();

        customerSb.AppendFormat(Resource.Client_Registration_Name + ": {0}<br/>", PageData.OrderConfirmationData.Customer.FirstName);
        customerSb.AppendFormat(Resource.Client_Registration_Surname + ": {0}<br/>", PageData.OrderConfirmationData.Customer.LastName);
        customerSb.AppendFormat(Resource.Client_Registration_Phone + ": {0}<br/>", PageData.OrderConfirmationData.Customer.Phone);
        customerSb.AppendFormat(Resource.Client_Registration_Country + ": {0}<br/>", PageData.OrderConfirmationData.ShippingContact.Country);
        customerSb.AppendFormat(Resource.Client_Registration_State + ": {0}<br/>", PageData.OrderConfirmationData.ShippingContact.RegionName);
        customerSb.AppendFormat(Resource.Client_Registration_City + ": {0}<br/>", PageData.OrderConfirmationData.ShippingContact.City);
        customerSb.AppendFormat(Resource.Client_Registration_Zip + ": {0}<br/>", PageData.OrderConfirmationData.ShippingContact.Zip);
        customerSb.AppendFormat(Resource.Client_Registration_Address + ": {0}<br/>", string.IsNullOrEmpty(PageData.OrderConfirmationData.ShippingContact.Address) ? Resource.Client_OrderConfirmation_NotDefined : PageData.OrderConfirmationData.ShippingContact.Address);
        customerSb.AppendFormat("Email: {0}<br/>", PageData.OrderConfirmationData.Customer.EMail);


        string htmlMessage = SendMail.BuildMail(new ClsMailParamOnNewOrder
        {
            CustomerContacts    = customerSb.ToString(),
            PaymentType         = PageData.OrderConfirmationData.SelectPaymentName,
            ShippingMethod      = PageData.OrderConfirmationData.SelectShippingName,
            CurrentCurrencyCode = CurrencyService.CurrentCurrency.Iso3,
            TotalPrice          = ord.Sum.ToString(),
            Comments            = ord.CustomerComment,
            Email      = email,
            OrderTable = htmlOrderTable,
            OrderID    = ord.OrderID.ToString(),
            Number     = ord.Number
        });

        if (!CustomerSession.CurrentCustomer.IsVirtual)
        {
            if (paymentMethod != null)
            {
                SendMail.SendMailNow(email, Resource.Client_OrderConfirmation_ReceivedOrder + " " + ord.OrderID,
                                     htmlMessage, true);
                SendMail.SendMailNow(SettingsMail.EmailForOrders,
                                     Resource.Client_OrderConfirmation_ReceivedOrder + " " + ord.OrderID, htmlMessage,
                                     true);
            }
            else
            {
                htmlMessage += " ERROR: \'" + "\'";
                SendMail.SendMailNow(SettingsMail.EmailForOrders,
                                     Resource.Client_OrderConfirmation_OrderError + " " + ord.OrderID, htmlMessage, true);
            }
        }

        var certificate = shoppingCart.Certificate;

        if (certificate != null)
        {
            certificate.OrderNumber = ord.Number;
            certificate.Used        = true;
            certificate.Enable      = true;

            GiftCertificateService.DeleteCustomerCertificate(certificate.CertificateId);
            GiftCertificateService.UpdateCertificateById(certificate);
        }

        var coupon = shoppingCart.Coupon;

        if (coupon != null && shoppingCart.TotalPrice >= coupon.MinimalOrderPrice)
        {
            coupon.ActualUses += 1;
            CouponService.UpdateCoupon(coupon);
            CouponService.DeleteCustomerCoupon(coupon.CouponID);
        }

        ShoppingCartService.ClearShoppingCart(ShoppingCartType.ShoppingCart, PageData.OrderConfirmationData.Customer.Id);
        ShoppingCartService.ClearShoppingCart(ShoppingCartType.ShoppingCart, CustomerSession.CustomerId);
        return(ord);
    }