protected void Page_PreRender(object sender, EventArgs e)
        {
            if (_customer.BonusCardNumber != null && (Card = BonusSystemService.GetCard(_customer.BonusCardNumber)) != null)
            {
                txtBonusFirstName.Text  = Card.FirstName;
                txtBonusLastName.Text   = Card.LastName;
                txtBonusSecondName.Text = Card.SecondName;
                txtBonusDate.Text       = Card.DateOfBirth != null
                                        ? ((DateTime)Card.DateOfBirth).ToString("dd.MM.yyyy")
                                        : string.Empty;
                txtBonusDate.Disabled = true;

                txtBonusPhone.Text   = Card.CellPhone;
                genderMale.Checked   = !Card.Gender;
                genderFemale.Checked = Card.Gender;

                btnMaAddBonusCard.Text     = Resource.Client_Bonuses_SaveChanges;
                btnMaAddBonusCard.CssClass = "ma-changecard";
            }
            else
            {
                txtBonusFirstName.Text     = _customer.FirstName;
                txtBonusLastName.Text      = _customer.LastName;
                txtBonusSecondName.Text    = _customer.Patronymic;
                btnMaAddBonusCard.Text     = Resource.Client_Bonuses_AddCard;
                btnMaAddBonusCard.CssClass = "ma-addcard";
                txtBonusDate.CssClass     += " mask-inp";
                txtBonusPhone.CssClass    += " mask-inp";
            }
        }
Esempio n. 2
0
        protected void btnChangeCommonInfo_Click(object sender, EventArgs e)
        {
            int groupId;

            Int32.TryParse(ddlCustomerGroup.SelectedValue, out groupId);
            lblError.Visible           = false;
            customer.FirstName         = HttpUtility.HtmlEncode(txtFirstName.Text);
            customer.LastName          = txtLastName.Text;
            customer.Phone             = txtWWW.Text;
            customer.CustomerGroupId   = groupId;
            customer.SubscribedForNews = chkSubscribed4News.Checked;

            if (customer.EMail != txtEmail.Text && CustomerService.ExistsEmail(txtEmail.Text))
            {
                lblError.Text    = Resource.Admin_CreateCustomer_CustomerErrorEmailExist;
                lblError.Visible = true;
                return;
            }

            customer.EMail = txtEmail.Text; customer.EMail = txtEmail.Text;

            var cardNumber = txtBonusCardNumber.Text.TryParseLong(true);

            if (BonusSystem.IsActive && txtBonusCardNumber.Text.IsNotEmpty())
            {
                if (BonusSystemService.GetCard(cardNumber) == null)
                {
                    lblError.Text    = Resource.Admin_ViewCustomer_WrongCardNumber;
                    lblError.Visible = true;
                    return;
                }
            }

            customer.BonusCardNumber = cardNumber;

            var prevCustomerRole = customer.CustomerRole;

            customer.CustomerRole = (Role)SQLDataHelper.GetInt(ddlCustomerRole.SelectedValue);

            if (customer.CustomerRole == Role.Moderator)
            {
                CustomerRoleActionsAdmin.SaveRole();
            }
            else if (prevCustomerRole == Role.Moderator && (customer.CustomerRole != Role.Moderator))
            {
                RoleActionService.DeleteCustomerRoleActions(customer.Id);
            }

            CustomerService.UpdateCustomer(customer);
            ShowRoleAccess = customer.CustomerRole == Role.Moderator;
            CustomerRoleActionsAdmin.Visible = ShowRoleAccess;
        }
Esempio n. 3
0
        protected void Page_PreRender(object sender, EventArgs e)
        {
            if (PageData == null)
            {
                return;
            }

            if (!BonusSystem.IsActive)
            {
                this.Visible = false;
                return;
            }

            var customer   = CustomerContext.CurrentCustomer;
            var cardNumber = customer.RegistredUser ? customer.BonusCardNumber : PageData.Customer.BonusCardNumber;

            Card = BonusSystemService.GetCard(cardNumber);
            if (Card != null)
            {
                liBonusAmount.Text = string.Format("({0} {1} {2})",
                                                   Resource.Client_StepBonus_YourBonuses,
                                                   Card.BonusAmount,
                                                   Strings.Numerals(Card.BonusAmount, Resource.Client_StepBonus_Empty,
                                                                    Resource.Client_StepBonus_1Bonus,
                                                                    Resource.Client_StepBonus_2Bonus,
                                                                    Resource.Client_StepBonus_5Bonus));

                chkBonus.Checked = PageData.UseBonuses;
            }

            if (customer.RegistredUser)
            {
                txtBonusLastName.Text   = customer.LastName;
                txtBonusFirstName.Text  = customer.FirstName;
                txtBonusSecondName.Text = customer.Patronymic;
                if (customer.Phone.IsNotEmpty())
                {
                    txtBonusPhone.Text = customer.Phone;
                }
            }

            if (BonusSystem.BonusesForNewCard != 0)
            {
                liBonusesForNewCard.Text = string.Format(Resource.Client_StepBonus_NewCardBonuses,
                                                         CatalogService.GetStringPrice(BonusSystem.BonusesForNewCard));
                liBonusesForNewCard.Visible = true;
            }
        }
Esempio n. 4
0
        protected void Page_PreRender(object sender, EventArgs e)
        {
            if (BonusSystem.IsActive)
            {
                divBonusCard.Visible  = true;
                trBonusAmount.Visible = false;

                var card = BonusSystemService.GetCard(customer.BonusCardNumber);
                if (card != null)
                {
                    txtBonusCardNumber.Text = card.CardNumber.ToString();
                    lblBonusCardAmount.Text = card.BonusAmount.ToString();
                    trBonusAmount.Visible   = true;
                }
            }
        }
Esempio n. 5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack && CustomerContext.CurrentCustomer.RegistredUser)
            {
                Response.Redirect("default.aspx");
            }

            SetRequiredFields();

            if (!Page.IsPostBack && Demo.IsDemoEnabled)
            {
                txtEmail.Text = Demo.GetRandomEmail();
                dvDemoDataUserNotification.Visible = true;
                txtFirstName.Text = Demo.GetRandomName();
                txtLastName.Text  = Demo.GetRandomLastName();
                txtPhone.Text     = Demo.GetRandomPhone();
            }

            if (SettingsMain.EnablePhoneMask)
            {
                txtPhone.CssClass = "mask-phone mask-inp";
            }

            if (BonusSystem.IsActive)
            {
                var bonusCard = Session["bonuscard"] != null ? Session["bonuscard"].ToString() : null;
                if (bonusCard.IsNotEmpty())
                {
                    Card = BonusSystemService.GetCard(bonusCard.TryParseLong(true));
                }

                if (BonusSystem.BonusesForNewCard != 0)
                {
                    liBonusesForNewCard.Text = string.Format(Resource.Client_StepBonus_NewCardBonuses,
                                                             CatalogService.GetStringPrice(BonusSystem.BonusesForNewCard));
                    liBonusesForNewCard.Visible = true;
                }
            }

            NewsSubscription.Visible = SettingsDesign.NewsSubscriptionVisibility;

            liCaptcha.Visible = SettingsMain.EnableCaptcha;

            SetMeta(
                new MetaInfo(string.Format("{0} - {1}", SettingsMain.ShopName, Resource.Client_Registration_Registration)),
                string.Empty);
        }
Esempio n. 6
0
        private void LoadBonusCard()
        {
            if (!BonusSystem.IsActive || CurrentOffer.Price <= 0)
            {
                return;
            }

            var bonusCard = BonusSystemService.GetCard(CustomerContext.CurrentCustomer.BonusCardNumber);

            if (bonusCard != null)
            {
                lblProductBonus.Text =
                    CatalogService.RenderBonusPrice(bonusCard.BonusPercent, CurrentOffer.Price,
                                                    CurrentProduct.CalculableDiscount, CustomerContext.CurrentCustomer.CustomerGroup, CustomOptionsService.SerializeToXml(productCustomOptions.CustomOptions, productCustomOptions.SelectedOptions));
            }
            else if (BonusSystem.BonusFirstPercent != 0)
            {
                lblProductBonus.Text =
                    CatalogService.RenderBonusPrice(BonusSystem.BonusFirstPercent, CurrentOffer.Price,
                                                    CurrentProduct.CalculableDiscount, CustomerContext.CurrentCustomer.CustomerGroup, CustomOptionsService.SerializeToXml(productCustomOptions.CustomOptions, productCustomOptions.SelectedOptions));
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            AdvantShop.BonusSystem.BonusSystem.ApiKey            = txtNewKey.Text.IsNotEmpty() ? txtNewKey.Text : txtApiKey.Text;
            AdvantShop.BonusSystem.BonusSystem.BonusType         = (AdvantShop.BonusSystem.BonusSystem.EBonusType)SQLDataHelper.GetInt(ddlBonusType.SelectedValue);
            AdvantShop.BonusSystem.BonusSystem.MaxOrderPercent   = txtMaxOrderPercent.Text.TryParseFloat(100);
            AdvantShop.BonusSystem.BonusSystem.BonusesForNewCard = txtBonusesForNewCard.Text.TryParseFloat();

            AdvantShop.BonusSystem.BonusSystem.UseOrderId = ckbUseOrderId.Checked;

            if (BonusSystemService.IsActive())
            {
                lblMessage.Text      = (String)GetLocalResourceObject("BonusSystem_Message");
                lblMessage.ForeColor = Color.Blue;
                lblMessage.Visible   = true;
            }
            else
            {
                lblMessage.Text      = (String)GetLocalResourceObject("BonusSystem_Save_Error");
                lblMessage.ForeColor = Color.Red;
                lblMessage.Visible   = true;
            }
        }
        //protected string RenderPrice(float productPrice, float discount)
        //{
        //    if (productPrice == 0)
        //    {
        //        return string.Format("<div class=\'price\'>{0}</div>", Resource.Client_Catalog_ContactWithUs);
        //    }

        //    string res;

        //    float price = CatalogService.CalculateProductPrice(productPrice, 0, customerGroup, null);
        //    float priceWithDiscount = CatalogService.CalculateProductPrice(productPrice, discount, customerGroup, null);

        //    if (price.Equals(priceWithDiscount))
        //    {
        //        res = string.Format("<div class=\'price\'>{0}</div>", CatalogService.GetStringPrice(price));
        //    }
        //    else
        //    {
        //        res = string.Format("<div class=\"price-old\">{0}</div><div class=\"price\">{1}</div><div class=\"price-benefit\">{2} {3} {4} {5}% </div>",
        //                            CatalogService.GetStringPrice(productPrice),
        //                            CatalogService.GetStringPrice(priceWithDiscount),
        //                            Resource.Client_Catalog_Discount_Benefit,
        //                            CatalogService.GetStringPrice(price - priceWithDiscount),
        //                            Resource.Client_Catalog_Discount_Or,
        //                            CatalogService.FormatPriceInvariant(discount));
        //    }

        //    return res;
        //}

        private void LoadModules()
        {
            var discountModule = AttachedModules.GetModules <IDiscount>().FirstOrDefault();

            if (discountModule != null)
            {
                var classInstance = (IDiscount)Activator.CreateInstance(discountModule);
                _productDiscountModels = classInstance.GetProductDiscountsList();
            }

            _customLabels = new List <ProductLabel>();
            foreach (var labelModule in AttachedModules.GetModules <ILabel>())
            {
                var classInstance = (ILabel)Activator.CreateInstance(labelModule);
                var labelCode     = classInstance.GetLabel();
                if (labelCode != null)
                {
                    _customLabels.Add(labelCode);
                }
            }

            var bonusSystem = AttachedModules.GetModules <IBonusSystem>().FirstOrDefault();

            if (bonusSystem != null)
            {
                if (CustomerContext.CurrentCustomer.BonusCardNumber != null)
                {
                    _bonusCard = BonusSystemService.GetCard(CustomerContext.CurrentCustomer.BonusCardNumber);
                }
                else if (BonusSystem.BonusFirstPercent != 0)
                {
                    _bonusCard = new BonusCard()
                    {
                        BonusPercent = BonusSystem.BonusFirstPercent
                    };
                }
            }
        }
Esempio n. 9
0
        private void LoadOrder()
        {
            order = OrderService.GetOrder(OrderId);
            if (order == null)
            {
                Response.Redirect("OrderSearch.aspx");
            }

            lnkExportToExcel.NavigateUrl = "HttpHandlers/ExportOrderExcel.ashx?OrderID=" + order.OrderID;
            lnkEditOrder.NavigateUrl     = "EditOrder.aspx?OrderID=" + order.OrderID;

            OrderNumber         = order.Number;
            lblOrderId.Text     = order.OrderID.ToString();
            lblOrderDate.Text   = AdvantShop.Localization.Culture.ConvertDate(order.OrderDate);
            lblOrderNumber.Text = order.Number;

            IsPaid = order.PaymentDate != null && order.PaymentDate != DateTime.MinValue;

            if (order.OrderCurrency != null)
            {
                CurrencyValue = order.OrderCurrency.CurrencyValue;
                CurrencyCode  = order.OrderCurrency.CurrencyCode;
            }

            if (order.OrderCustomer != null)
            {
                var customer = CustomerService.GetCustomer(order.OrderCustomer.CustomerID);
                if (customer != null && customer.Id != Guid.Empty)
                {
                    lnkCustomerName.Text         = order.OrderCustomer.FirstName + @" " + order.OrderCustomer.LastName;
                    lnkCustomerName.NavigateUrl  = @"viewcustomer.aspx?customerid=" + order.OrderCustomer.CustomerID;
                    lnkCustomerEmail.Text        = order.OrderCustomer.Email;
                    lnkCustomerEmail.NavigateUrl = "mailto:" + order.OrderCustomer.Email;
                }
                else
                {
                    lblCustomerEmail.Text = order.OrderCustomer.Email;
                    lblCustomerName.Text  = order.OrderCustomer.FirstName + @" " + order.OrderCustomer.LastName;
                }

                lblCustomerPhone.Text = order.OrderCustomer.MobilePhone;
            }

            if (order.ShippingContact != null)
            {
                lblShippingCountry.Text = order.ShippingContact.Country;
                lblShippingCity.Text    = order.ShippingContact.City;
                lblShippingRegion.Text  = order.ShippingContact.Zone;
                lblShippingZipCode.Text = order.ShippingContact.Zip;
                lblShippingAddress.Text = order.ShippingContact.Address;

                if (!string.IsNullOrEmpty(order.ShippingContact.Country) && !string.IsNullOrEmpty(order.ShippingContact.City) &&
                    !string.IsNullOrEmpty(order.ShippingContact.Zone) && !string.IsNullOrEmpty(order.ShippingContact.Address))
                {
                    lnkShippingAddressOnMap.NavigateUrl = (SettingsOrderConfirmation.PrintOrder_MapType == "googlemap"
                                                                ? "https://maps.google.com/maps?ie=UTF8&z=15&q="
                                                                : "http://maps.yandex.ru/?text=") +
                                                          HttpUtility.UrlEncode(order.ShippingContact.Country + "," + order.ShippingContact.Zone + "," +
                                                                                order.ShippingContact.City + "," + order.ShippingContact.Address);
                }
                else
                {
                    lnkShippingAddressOnMap.Visible = false;
                }
            }

            if (order.BillingContact != null)
            {
                lblBuyerCountry.Text = order.BillingContact.Country;
                lblBuyerRegion.Text  = order.BillingContact.Zone;
                lblBuyerCity.Text    = order.BillingContact.City;
                lblBuyerZip.Text     = order.BillingContact.Zip;
                lblBuyerAddress.Text = order.BillingContact.Address;

                if (!string.IsNullOrEmpty(order.BillingContact.Country) && !string.IsNullOrEmpty(order.BillingContact.City) &&
                    !string.IsNullOrEmpty(order.BillingContact.Zone) && !string.IsNullOrEmpty(order.BillingContact.Address))
                {
                    lnkBuyerAddressOnMap.NavigateUrl = (SettingsOrderConfirmation.PrintOrder_MapType == "googlemap"
                                                            ? "https://maps.google.com/maps?ie=UTF8&z=15&q="
                                                            : "http://maps.yandex.ru/?text=") +
                                                       HttpUtility.UrlEncode(order.BillingContact.Country + "," + order.BillingContact.Zone + "," +
                                                                             order.BillingContact.City + "," + order.BillingContact.Address);
                }
                else
                {
                    lnkBuyerAddressOnMap.Visible = false;
                }
            }

            lblShippingMethodName.Text = order.ArchivedShippingName + (order.OrderPickPoint != null ? "<br />" + order.OrderPickPoint.PickPointAddress : "");
            lblPaymentMethodName.Text  = order.PaymentMethodName;

            var statusesList = OrderService.GetOrderStatuses();

            if (statusesList != null && statusesList.Any(status => status.StatusID == order.OrderStatus.StatusID))
            {
                ddlViewOrderStatus.DataSource = statusesList;
                ddlViewOrderStatus.DataBind();
                ddlViewOrderStatus.SelectedValue = order.OrderStatus.StatusID.ToString();
            }
            else
            {
                ddlViewOrderStatus.Items.Add(new ListItem(order.OrderStatus.StatusName, order.OrderStatus.StatusID.ToString()));
                ddlViewOrderStatus.SelectedValue = order.OrderStatus.StatusID.ToString();
            }
            ddlViewOrderStatus.Attributes["data-orderid"] = order.OrderID.ToString();

            pnlOrderNumber.Attributes["style"] = "border-left-color: #" + order.OrderStatus.Color;

            if (order.OrderCertificates == null || order.OrderCertificates.Count == 0)
            {
                lvOrderItems.DataSource = order.OrderItems;
                lvOrderItems.DataBind();
                lvOrderCertificates.Visible = false;
            }
            else
            {
                lvOrderCertificates.DataSource = order.OrderCertificates;
                lvOrderCertificates.DataBind();
                lvOrderItems.Visible = false;
            }

            lblUserComment.Text = string.IsNullOrEmpty(order.CustomerComment)
                                        ? Resource.Admin_OrderSearch_NoComment
                                        : order.CustomerComment;

            txtAdminOrderComment.Text = string.Format("{0}", order.AdminOrderComment);
            txtStatusComment.Text     = string.Format("{0}", order.StatusComment);

            txtStatusComment.Attributes["data-orderid"]     = order.OrderID.ToString();
            txtAdminOrderComment.Attributes["data-orderid"] = order.OrderID.ToString();

            var shipping = ShippingMethodService.GetShippingMethod(order.ShippingMethodId);

            if (shipping != null)
            {
                OrderPickPoint = order.OrderPickPoint;

                liMultiship.Visible = shipping.Type == ShippingType.Multiship;

                liSendBillingLink.Visible = order.OrderCustomer != null && order.ShippingMethod != null && !order.Payed;

                ShippingTypeIsCdek = shipping.Type == ShippingType.Cdek;

                ShippingTypeIsCheckout = lblCheckoutAdressNotice.Visible = shipping.Type == ShippingType.CheckoutRu;

                if (CustomerContext.CurrentCustomer.CustomerRole == Role.Moderator)
                {
                    var  actions             = RoleActionService.GetCustomerRoleActionsByCustomerId(CustomerContext.CurrentCustomer.Id);
                    bool showSendPaymentLink =
                        actions.Any(a => a.Key == RoleActionKey.DisplaySendPaymentLink && a.Enabled);

                    liSendBillingLink.Visible &= showSendPaymentLink;
                }
            }

            if (BonusSystem.IsActive)
            {
                var purchase = BonusSystemService.GetPurchase(order.Number, order.OrderID);
                if (purchase != null)
                {
                    bonusCardBlock.Visible  = true;
                    lblBonusCardNumber.Text = purchase.CardNumber;
                    lblBonusCardAmount.Text = purchase.NewBonusAmount.ToString();
                }
            }

            if (Settings1C.Enabled)
            {
                divUseIn1C.Visible = true;
                chkUseIn1C.Checked = order.UseIn1C;
                chkUseIn1C.Attributes["data-orderid"] = order.OrderID.ToString();

                var status1C = OrderService.GetStatus1C(order.OrderID);
                if (status1C != null)
                {
                    divStatus1C.Visible = true;
                    lbl1CStatus.Text    = status1C.Status1C;
                }
            }
            else
            {
                divUseIn1C.Visible = false;
            }

            LoadTotal(order);
        }
Esempio n. 10
0
        private void LoadShoppingCart()
        {
            var orderConfirmData = PageData.OrderConfirmationData;

            var shpCart = ShoppingCartService.CurrentShoppingCart;

            if (shpCart.Count > 0 && shpCart.Count <= 5)
            {
                lvOrderList.DataSource = shpCart;
                lvOrderList.DataBind();
                lvOrderList.Visible = true;
            }
            else
            {
                lvOrderList.Visible = false;
            }

            var productsPrice        = shpCart.TotalPrice;
            var discountOnTotalPrice = shpCart.DiscountPercentOnTotalPrice;
            var totalDiscount        = shpCart.TotalDiscount;
            var shippingPrice        = orderConfirmData.SelectedShippingItem.Rate;

            if (discountOnTotalPrice > 0)
            {
                discountRow.Visible    = true;
                liDiscountPercent.Text = string.Format("<span class=\"per\">-{0}%</span>", discountOnTotalPrice);
                lblOrderDiscount.Text  = "-" + CatalogService.GetStringPrice(productsPrice * discountOnTotalPrice / 100);
            }
            else
            {
                discountRow.Visible = false;
            }

            if (shpCart.Certificate != null)
            {
                certificateRow.Visible   = true;
                lblCertificatePrice.Text = String.Format("-{0}",
                                                         CatalogService.GetStringPrice(shpCart.Certificate.Sum, 1,
                                                                                       shpCart.Certificate.CertificateOrder.OrderCurrency.CurrencyCode,
                                                                                       shpCart.Certificate.CertificateOrder.OrderCurrency.CurrencyValue));
            }

            if (shpCart.Coupon != null)
            {
                couponRow.Visible = true;
                if (shpCart.TotalPrice < shpCart.Coupon.MinimalOrderPrice)
                {
                    lblCouponPrice.Text = String.Format(Resource.Client_OrderConfirmation_CouponMessage,
                                                        CatalogService.GetStringPrice(shpCart.Coupon.MinimalOrderPrice));
                }
                else
                {
                    if (totalDiscount == 0)
                    {
                        lblCouponPrice.Text = String.Format("-{0} ({1}) <img src='images/question_mark.png' title='{3}'> <a class=\"cross\"  data-cart-remove-cupon=\"true\" title=\"{2}\"></a>",
                                                            CatalogService.GetStringPrice(0), shpCart.Coupon.Code,
                                                            Resource.Client_ShoppingCart_DeleteCoupon,
                                                            Resource.Client_ShoppingCart_CouponNotApplied);
                    }
                    else
                    {
                        switch (shpCart.Coupon.Type)
                        {
                        case CouponType.Fixed:
                            lblCouponPrice.Text = String.Format("-{0} ({1})",
                                                                CatalogService.GetStringPrice(totalDiscount), shpCart.Coupon.Code);
                            break;

                        case CouponType.Percent:
                            lblCouponPrice.Text = String.Format("-{0} ({1}%) ({2})",
                                                                CatalogService.GetStringPrice(totalDiscount),
                                                                CatalogService.FormatPriceInvariant(shpCart.Coupon.Value), shpCart.Coupon.Code);
                            break;
                        }
                    }
                }
            }

            if (BonusSystem.IsActive)
            {
                var bonusCard = BonusSystemService.GetCard(orderConfirmData.Customer.BonusCardNumber);
                if (bonusCard != null)
                {
                    if (orderConfirmData.UseBonuses)
                    {
                        var bonusPrice = BonusSystemService.GetBonusCost(productsPrice + shippingPrice - totalDiscount, productsPrice - totalDiscount, bonusCard.BonusAmount);
                        totalDiscount += bonusPrice;

                        lblOrderBonuses.Text = "-" + CatalogService.GetStringPrice(bonusPrice);
                        bonusesRow.Visible   = true;
                    }

                    var bonusPlusPrice = BonusSystemService.GetBonusPlusCost(productsPrice + shippingPrice - totalDiscount, productsPrice - totalDiscount, bonusCard.BonusPercent);
                    if (bonusPlusPrice > 0)
                    {
                        liBonusPlus.Text  = "+" + CatalogService.GetStringPrice(bonusPlusPrice);
                        bonusPlus.Visible = true;
                    }
                    orderConfirmData.BonusPlus = bonusPlusPrice;
                }
            }



            if (orderConfirmData.SelectedPaymentItem.Type == PaymentType.CashOnDelivery && orderConfirmData.SelectedShippingItem.Ext != null)
            {
                shippingPrice = orderConfirmData.SelectedShippingItem.Ext.PriceCash;
            }

            var taxesItems = TaxServices.CalculateTaxes(productsPrice - totalDiscount + shippingPrice);
            var taxesTotal = taxesItems.Where(tax => !tax.Key.ShowInPrice).Sum(item => item.Value);

            var paymentExtraCharge = orderConfirmData.SelectedPaymentItem.Extracharge;

            paymentExtraChargeRow.Visible = paymentExtraCharge != 0;

            if (orderConfirmData.SelectedPaymentItem.ExtrachargeType == ExtrachargeType.Percent)
            {
                paymentExtraCharge = paymentExtraCharge * (productsPrice - totalDiscount + shippingPrice + taxesTotal) / 100;
            }

            lPaymentCost.Text = paymentExtraCharge > 0
                ? Resource.Client_OrderConfirmation_PaymentCost
                : Resource.Client_OrderConfirmation_PaymentDiscount;

            var totalPrice = productsPrice - totalDiscount + shippingPrice + paymentExtraCharge + taxesTotal;


            lblProductsPrice.Text      = CatalogService.GetStringPrice(productsPrice);
            lblShippingPrice.Text      = shippingPrice != 0 ? "+" + CatalogService.GetStringPrice(shippingPrice) : orderConfirmData.SelectedShippingItem.ZeroPriceMessage;
            lblPaymentExtraCharge.Text = (paymentExtraCharge > 0 ? "+" : "") +
                                         CatalogService.GetStringPrice(paymentExtraCharge);

            //todo tax
            if (taxesItems.Count > 0)
            {
                literalTaxCost.Text = BuildTaxTable(taxesItems, CurrencyService.CurrentCurrency.Value,
                                                    CurrencyService.CurrentCurrency.Iso3);
            }

            lblTotalPrice.Text = CatalogService.GetStringPrice(totalPrice > 0 ? totalPrice : 0);

            orderConfirmData.Sum      = totalPrice > 0 ? totalPrice : 0;
            orderConfirmData.CheckSum = ShoppingCartService.CurrentShoppingCart.GetHashCode();
        }
        private Order CreateOrder(ShoppingCart shoppingCart)
        {
            var orderConfirmData = PageData.OrderConfirmationData;
            var customerGroup    = CustomerContext.CurrentCustomer.CustomerGroup;

            var baseCurrency = CurrencyService.BaseCurrency;

            var ord = new Order
            {
                OrderCustomer = new OrderCustomer
                {
                    CustomerIP  = Request.UserHostAddress,
                    CustomerID  = orderConfirmData.Customer.Id,
                    FirstName   = orderConfirmData.Customer.FirstName,
                    LastName    = orderConfirmData.Customer.LastName,
                    Patronymic  = orderConfirmData.Customer.Patronymic,
                    Email       = orderConfirmData.Customer.EMail,
                    MobilePhone = orderConfirmData.Customer.Phone,
                },
                OrderCurrency = new OrderCurrency
                {
                    //CurrencyCode = CurrencyService.CurrentCurrency.Iso3,
                    //CurrencyValue = CurrencyService.CurrentCurrency.Value,
                    //CurrencySymbol = CurrencyService.CurrentCurrency.Symbol,
                    //CurrencyNumCode = CurrencyService.CurrentCurrency.NumIso3,
                    //IsCodeBefore = CurrencyService.CurrentCurrency.IsCodeBefore
                    CurrencyCode    = baseCurrency.Iso3,
                    CurrencyValue   = baseCurrency.Value,
                    CurrencySymbol  = baseCurrency.Symbol,
                    CurrencyNumCode = baseCurrency.NumIso3,
                    IsCodeBefore    = baseCurrency.IsCodeBefore
                },
                OrderStatusId   = OrderService.DefaultOrderStatus,
                AffiliateID     = 0,
                OrderDate       = DateTime.Now,
                CustomerComment = orderConfirmData.CustomerComment,
                ShippingContact = new OrderContact
                {
                    Name         = orderConfirmData.ShippingContact.Name,
                    Country      = orderConfirmData.ShippingContact.Country,
                    Zone         = orderConfirmData.ShippingContact.RegionName,
                    City         = orderConfirmData.ShippingContact.City,
                    Zip          = orderConfirmData.ShippingContact.Zip,
                    Address      = orderConfirmData.ShippingContact.Address,
                    CustomField1 = orderConfirmData.ShippingContact.CustomField1,
                    CustomField2 = orderConfirmData.ShippingContact.CustomField2,
                    CustomField3 = orderConfirmData.ShippingContact.CustomField3
                },

                GroupName     = customerGroup.GroupName,
                GroupDiscount = customerGroup.GroupDiscount,
                OrderDiscount = shoppingCart.DiscountPercentOnTotalPrice
            };

            foreach (var orderItem in shoppingCart.Select(item => (OrderItem)item))
            {
                ord.OrderItems.Add(orderItem);
            }

            if (!orderConfirmData.BillingIsShipping)
            {
                ord.BillingContact = new OrderContact
                {
                    Name         = orderConfirmData.BillingContact.Name,
                    Country      = orderConfirmData.BillingContact.Country,
                    Zone         = orderConfirmData.BillingContact.RegionName,
                    City         = orderConfirmData.BillingContact.City,
                    Zip          = orderConfirmData.BillingContact.Zip,
                    Address      = orderConfirmData.BillingContact.Address,
                    CustomField1 = orderConfirmData.BillingContact.CustomField1,
                    CustomField2 = orderConfirmData.BillingContact.CustomField2,
                    CustomField3 = orderConfirmData.BillingContact.CustomField3
                };
            }

            ord.ShippingMethodId = orderConfirmData.SelectedShippingItem.MethodId;
            ord.PaymentMethodId  = orderConfirmData.SelectedPaymentItem.PaymenMethodtId;

            ord.ArchivedShippingName = orderConfirmData.SelectedShippingItem.MethodNameRate;
            ord.ArchivedPaymentName  = orderConfirmData.SelectedPaymentItem.Name;

            ord.PaymentDetails = orderConfirmData.PaymentDetails;

            if (orderConfirmData.SelectedShippingItem.Ext != null &&
                orderConfirmData.SelectedShippingItem.Ext.PickpointAddress.IsNotEmpty())
            {
                ord.OrderPickPoint = new OrderPickPoint
                {
                    PickPointId      = orderConfirmData.SelectedShippingItem.Ext.PickpointId,
                    PickPointAddress = orderConfirmData.SelectedShippingItem.Ext.PickpointAddress,
                    AdditionalData   = orderConfirmData.SelectedShippingItem.Ext.AdditionalData
                };
            }
            else if (orderConfirmData.SelectedShippingItem.Ext != null &&
                     orderConfirmData.SelectedShippingItem.Ext.Type == ExtendedType.Cdek &&
                     orderConfirmData.SelectedShippingItem.Ext.PickpointAddress.IsNullOrEmpty())
            {
                ord.OrderPickPoint = new OrderPickPoint
                {
                    PickPointId      = orderConfirmData.SelectedShippingItem.Ext.PickpointId,
                    PickPointAddress = ord.ShippingContact.Address,
                    AdditionalData   = orderConfirmData.SelectedShippingItem.Ext.AdditionalData
                };
            }
            else if (orderConfirmData.SelectedShippingItem.Type == ShippingType.CheckoutRu &&
                     orderConfirmData.SelectedShippingItem.Ext != null)
            {
                ord.OrderPickPoint = new OrderPickPoint
                {
                    PickPointId      = orderConfirmData.SelectedShippingItem.Ext.PickpointId,
                    PickPointAddress = orderConfirmData.SelectedShippingItem.Ext.Type != ExtendedType.CashOnDelivery
                        ? ord.ShippingContact.Address
                        : string.Empty,
                    AdditionalData = orderConfirmData.SelectedShippingItem.Ext.AdditionalData
                };
            }

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

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

            var shippingPrice = orderConfirmData.SelectedPaymentItem.Type == PaymentType.CashOnDelivery && (orderConfirmData.SelectedShippingItem.Type != ShippingType.Cdek || orderConfirmData.SelectedShippingItem.Type != ShippingType.CheckoutRu)
                                ? orderConfirmData.SelectedShippingItem.Ext != null
                                      ? orderConfirmData.SelectedShippingItem.Ext.PriceCash
                                      : 0
                                : orderConfirmData.SelectedShippingItem.Rate;

            BonusCard bonusCard = null;

            if (BonusSystem.IsActive)
            {
                bonusCard = BonusSystemService.GetCard(orderConfirmData.Customer.BonusCardNumber);
                if (bonusCard != null && orderConfirmData.UseBonuses && bonusCard.BonusAmount > 0)
                {
                    ord.BonusCost =
                        BonusSystemService.GetBonusCost(
                            shoppingCart.TotalPrice - shoppingCart.TotalDiscount + shippingPrice,
                            shoppingCart.TotalPrice - shoppingCart.TotalDiscount, bonusCard.BonusAmount);
                }
            }

            var taxTotal =
                AdvantShop.Taxes.TaxServices.CalculateTaxes(shoppingCart.TotalPrice - shoppingCart.TotalDiscount +
                                                            shippingPrice - ord.BonusCost).Where(tax => !tax.Key.ShowInPrice).Sum(tax => tax.Value);

            var paymentPrice = orderConfirmData.SelectedPaymentItem.ExtrachargeType == ExtrachargeType.Percent
                                    ? (shoppingCart.TotalPrice - shoppingCart.TotalDiscount + shippingPrice - ord.BonusCost + taxTotal) * orderConfirmData.SelectedPaymentItem.Extracharge / 100
                                    : orderConfirmData.SelectedPaymentItem.Extracharge;

            ord.ShippingCost = shippingPrice;
            ord.PaymentCost  = paymentPrice;


            ord.Number = OrderService.GenerateNumber(1); // For crash protection

            ord.OrderID = OrderService.AddOrder(ord);
            ord.Number  = OrderService.GenerateNumber(ord.OrderID); // new number
            OrderService.UpdateNumber(ord.OrderID, ord.Number);

            ModulesRenderer.OrderAdded(ord.OrderID);

            OrderService.ChangeOrderStatus(ord.OrderID, OrderService.DefaultOrderStatus);

            if (BonusSystem.IsActive && bonusCard != null)
            {
                var sumPrice = BonusSystem.BonusType == BonusSystem.EBonusType.ByProductsCostWithShipping
                       ? shoppingCart.TotalPrice - shoppingCart.TotalDiscount + shippingPrice
                       : shoppingCart.TotalPrice - shoppingCart.TotalDiscount;

                BonusSystemService.MakeBonusPurchase(bonusCard.CardNumber, sumPrice, ord.BonusCost, ord.Number, ord.OrderID);
            }



            TrialService.TrackEvent(
                ord.OrderItems.Any(item => item.Name.Contains("SM-G900F"))
                    ? TrialEvents.BuyTheProduct
                    : TrialEvents.CheckoutOrder, string.Empty);

            return(ord);
        }
Esempio n. 12
0
        protected void btnRegister_Click(object sender, EventArgs e)
        {
            if (!DataValidation())
            {
                return;
            }

            long?bonusCardNumber = null;
            var  bonusCard       = Session["bonuscard"] != null ? Session["bonuscard"].ToString() : null;

            if (bonusCard.IsNotEmpty())
            {
                var card = BonusSystemService.GetCard(bonusCard.TryParseLong(true));
                if (card != null)
                {
                    bonusCardNumber = card.CardNumber;
                }
                Session["bonuscard"] = null;
            }

            lblMessage.Visible = false;

            CustomerService.InsertNewCustomer(new Customer
            {
                CustomerGroupId = CustomerGroupService.DefaultCustomerGroup,
                Password        = HttpUtility.HtmlEncode(txtPassword.Text),
                FirstName       = HttpUtility.HtmlEncode(txtFirstName.Text),
                LastName        =
                    SettingsOrderConfirmation.IsShowLastName ? HttpUtility.HtmlEncode(txtLastName.Text) : string.Empty,
                Patronymic =
                    SettingsOrderConfirmation.IsShowPatronymic
                        ? HttpUtility.HtmlEncode(txtPatronymic.Text)
                        : string.Empty,
                Phone             = SettingsOrderConfirmation.IsShowPhone ? HttpUtility.HtmlEncode(txtPhone.Text) : string.Empty,
                SubscribedForNews = chkSubscribed4News.Checked,
                EMail             = HttpUtility.HtmlEncode(txtEmail.Text),
                CustomerRole      = Role.User,
                BonusCardNumber   = bonusCardNumber
            });

            AuthorizeService.SignIn(txtEmail.Text, txtPassword.Text, false, true);

            //------------------------------------------

            var regMailTemplate = new RegistrationMailTemplate(SettingsMain.SiteUrl,
                                                               HttpUtility.HtmlEncode(txtFirstName.Text),
                                                               HttpUtility.HtmlEncode(txtLastName.Text),
                                                               AdvantShop.Localization.Culture.ConvertDate(DateTime.Now),
                                                               HttpUtility.HtmlEncode(txtPassword.Text),
                                                               chkSubscribed4News.Checked
                                                                   ? Resource.Client_Registration_Yes
                                                                   : Resource.Client_Registration_No,
                                                               HttpUtility.HtmlEncode(txtEmail.Text));

            regMailTemplate.BuildMail();

            if (CustomerContext.CurrentCustomer.IsVirtual)
            {
                ShowMessage(Notify.NotifyType.Error,
                            Resource.Client_Registration_Whom + txtEmail.Text + '\r' + Resource.Client_Registration_Text +
                            regMailTemplate.Body);
            }
            else
            {
                SendMail.SendMailNow(txtEmail.Text, regMailTemplate.Subject, regMailTemplate.Body, true);
                SendMail.SendMailNow(SettingsMail.EmailForRegReport, regMailTemplate.Subject, regMailTemplate.Body, true);
            }

            Response.Redirect("myaccount.aspx");
        }