Exemplo n.º 1
0
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.PreRender"/> event.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs"/> object that contains the event data.</param>
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);

            var membershipUser = Membership.GetUser();

            if (membershipUser != null)
            {
                this.UserName = membershipUser.UserName.Replace(Sitecore.Context.Domain.Name + @"\", string.Empty);
            }

            var isLoggedIn = MainUtil.IsLoggedIn();

            this.liStatusNotLoggedIn.Visible = !isLoggedIn;
            this.liStatusLoggedIn.Visible    = isLoggedIn;
            this.liMypage.Visible            = isLoggedIn;
            this.btnLogIn.Visible            = !isLoggedIn;
            this.btnLogOut.Visible           = isLoggedIn;

            GeneralSettings generalSettings = Sitecore.Ecommerce.Context.Entity.GetConfiguration <GeneralSettings>();

            this.btnLogIn.HRef = ItemUtil.GetItemUrl(generalSettings.MainLoginLink, true);

            this.lblLogedInAs.Text = string.Format(Translate.Text(Sitecore.Ecommerce.Examples.Texts.YouAreLoggedInAs), this.UserName);
        }
Exemplo n.º 2
0
        /// <summary>
        /// The form load event handler.
        /// </summary>
        /// <param name="isPostback">Gets a value that indicates whether the form is being rendered for the first time or is being loaded in response to a postback.</param>
        /// <param name="args">The Render Form arguments.</param>
        public void Load(bool isPostback, RenderFormArgs args)
        {
            HtmlFormModifier form = new HtmlFormModifier(args);

            if (!MainUtil.IsLoggedIn())
            {
                form.ChangeFormIntroduction(string.Empty);
            }
            else
            {
                ICustomerManager <CustomerInfo> customerManager = Context.Entity.Resolve <ICustomerManager <CustomerInfo> >();
                string name = customerManager.CurrentUser.BillingAddress.Name;
                form.ChangeFormTitle(string.Format("{0} {1}.", Translate.Text(Examples.Texts.Welcome), name));
                form.HideSectionByField("Returning customer", "UserName");
                //Note: hiding of submit form button :)
                form.HideElement("div", "class", "scfSubmitButtonBorder");
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets the most recent set options from the ShoppingCart and customerInfo instance
        /// and displays the options in the web form.
        /// If there are no items in the ShoppingCart, the user will be redirected to the
        /// home page.
        /// </summary>
        /// <param name="isPostback">Gets a value that indicates whether the form is being rendered for the first time or is being loaded in response to a postback.</param>
        /// <param name="args">The render form arguments.</param>
        public void Load(bool isPostback, RenderFormArgs args)
        {
            // Checks if the user has appropiate access.
            ICheckOut checkOut = Context.Entity.GetInstance <ICheckOut>();

            if (checkOut != null && checkOut is CheckOut)
            {
                if (!((CheckOut)checkOut).BeginCheckOut || !((CheckOut)checkOut).DeliveryDone)
                {
                    HttpContext.Current.Response.Redirect("/");
                }
            }

            HtmlFormModifier form = new HtmlFormModifier(args);

            form.DisableInputField("UserName");

            /*
             * Item navigationLinkItem = Utils.ItemUtil.GetNavigationLinkItem("Previous");
             * if (navigationLinkItem != null)
             * {
             * form.AddButtonFromNavigationLink(navigationLinkItem, true);
             * }
             */

            // If the user is logged in we hide the Create User boks.
            if (MainUtil.IsLoggedIn())
            {
                form.HideSectionByField("Create Username", "HideCreateUserSection");
            }

            ICustomerManager <CustomerInfo> customerManager = Context.Entity.Resolve <ICustomerManager <CustomerInfo> >();

            form.SetInputValue("UserName", customerManager.CurrentUser.Email);

            if (isPostback)
            {
                return;
            }

            ShoppingCart shoppingCart = Context.Entity.GetInstance <ShoppingCart>();

            shoppingCart.CustomerInfo = customerManager.CurrentUser;

            Context.Entity.SetInstance(shoppingCart);

            // Checks the Use other shipping address checkbox.
            // form.SetCheckboxSelected("HideThisSection", true);

            form.SetInputValue("Name", customerManager.CurrentUser.BillingAddress.Name);
            form.SetInputValue("Address", customerManager.CurrentUser.BillingAddress.Address);
            form.SetInputValue("Zip", customerManager.CurrentUser.BillingAddress.Zip);
            form.SetInputValue("City", customerManager.CurrentUser.BillingAddress.City);
            form.SetInputValue("Email", customerManager.CurrentUser.Email);

            if (customerManager.CurrentUser.BillingAddress.Country.Code != "US")
            {
                form.HideField("State");
            }
            else
            {
                form.SetSelectedDropListValue("State", customerManager.CurrentUser.BillingAddress.State);
            }

            if (customerManager.CurrentUser.ShippingAddress.Country.Code != "US")
            {
                form.HideField("ShippingState");
            }
            else
            {
                form.SetSelectedDropListValue("ShippingState", customerManager.CurrentUser.ShippingAddress.State);
            }

            form.SetSelectedDropListValue("Country", customerManager.CurrentUser.BillingAddress.Country.Name);

            /*
             * // Only field out shipping address if it was checked before.
             * if (checkOut is CheckOut)
             * {
             * if (!((CheckOut)checkOut).HasOtherShippingAddressBeenChecked)
             * {
             *  return;
             * }
             * }
             */
            form.SetInputValue("ShippingName", customerManager.CurrentUser.ShippingAddress.Name);
            form.SetInputValue("ShippingAddress", customerManager.CurrentUser.ShippingAddress.Address);
            form.SetInputValue("ShippingZip", customerManager.CurrentUser.ShippingAddress.Zip);
            form.SetInputValue("ShippingCity", customerManager.CurrentUser.ShippingAddress.City);

            form.SetSelectedDropListValue("ShippingCountry", customerManager.CurrentUser.ShippingAddress.Country.Title);

            foreach (string key in customerManager.CurrentUser.CustomProperties.AllKeys)
            {
                form.SetInputValue(key, customerManager.CurrentUser.CustomProperties[key]);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Handles the Load event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        /// <exception cref="ValidatorException">Order could not be created.</exception>
        protected void Page_Load(object sender, EventArgs e)
        {
            DomainModel.Carts.ShoppingCart shoppingCart = Sitecore.Ecommerce.Context.Entity.GetInstance <DomainModel.Carts.ShoppingCart>();
            if (string.IsNullOrEmpty(shoppingCart.PaymentSystem.Code))
            {
                return;
            }

            PaymentUrlResolver paymentUrlResolver = new PaymentUrlResolver();
            PaymentArgs        paymentArgs        = new PaymentArgs
            {
                PaymentUrls  = paymentUrlResolver.Resolve(),
                ShoppingCart = shoppingCart
            };

            ITransactionData transactionData = Sitecore.Ecommerce.Context.Entity.Resolve <ITransactionData>();

            PaymentProvider paymentProvider = Sitecore.Ecommerce.Context.Entity.Resolve <PaymentProvider>(shoppingCart.PaymentSystem.Code);

            DomainModel.Payments.PaymentSystem paymentSystem = shoppingCart.PaymentSystem;

            try
            {
                paymentProvider.ProcessCallback(paymentSystem, paymentArgs);
            }
            catch (Exception exception)
            {
                IOrderManager <Order> orderManager = Sitecore.Ecommerce.Context.Entity.Resolve <IOrderManager <Order> >();
                shoppingCart.OrderNumber = orderManager.GenerateOrderNumber();
                transactionData.DeletePersistentValue(shoppingCart.OrderNumber);

                HttpContext.Current.Session["paymentErrorMessage"] = exception.Message;
                this.Response.Redirect(paymentArgs.PaymentUrls.FailurePageUrl);

                return;
            }

            switch (paymentProvider.PaymentStatus)
            {
            case PaymentStatus.Succeeded:
            {
                IOrderManager <Order> orderManager = Sitecore.Ecommerce.Context.Entity.Resolve <IOrderManager <Order> >();
                Order order = orderManager.CreateOrder(shoppingCart);

                if (order != null)
                {
                    // Redirect to order confirmation page
                    string    orderId  = shoppingCart.OrderNumber;
                    ICheckOut checkOut = Sitecore.Ecommerce.Context.Entity.Resolve <ICheckOut>();
                    if (checkOut is CheckOut)
                    {
                        ((CheckOut)checkOut).ResetCheckOut();
                    }

                    if (MainUtil.IsLoggedIn())
                    {
                        orderId = string.Format("orderid={0}", orderId);
                    }
                    else
                    {
                        string encryptKey = Crypto.EncryptTripleDES(orderId, "5dfkjek5");
                        orderId = string.Format("key={0}", Uri.EscapeDataString(encryptKey));
                    }

                    this.StartOrderCreatedPipeline(order.OrderNumber);

                    if (!string.IsNullOrEmpty(orderId))
                    {
                        UrlString url = new UrlString(paymentArgs.PaymentUrls.SuccessPageUrl);
                        url.Append(new UrlString(orderId));
                        this.Response.Redirect(url.ToString());
                    }
                }
                else
                {
                    IOrderManager <Order> orderProvider = Sitecore.Ecommerce.Context.Entity.Resolve <IOrderManager <Order> >();
                    shoppingCart.OrderNumber = orderProvider.GenerateOrderNumber();
                    transactionData.DeletePersistentValue(shoppingCart.OrderNumber);

                    HttpContext.Current.Session["paymentErrorMessage"] = "Order could not be created.";
                    this.Response.Redirect(paymentArgs.PaymentUrls.FailurePageUrl);
                }

                break;
            }

            case PaymentStatus.Canceled:
            {
                IOrderManager <Order> orderProvider = Sitecore.Ecommerce.Context.Entity.Resolve <IOrderManager <Order> >();
                shoppingCart.OrderNumber = orderProvider.GenerateOrderNumber();
                transactionData.DeletePersistentValue(shoppingCart.OrderNumber);

                HttpContext.Current.Session["paymentErrorMessage"] = "Payment has been aborted by user.";
                this.Response.Redirect(paymentArgs.PaymentUrls.CancelPageUrl);

                break;
            }

            case PaymentStatus.Failure:
            {
                IOrderManager <Order> orderProvider = Sitecore.Ecommerce.Context.Entity.Resolve <IOrderManager <Order> >();
                shoppingCart.OrderNumber = orderProvider.GenerateOrderNumber();
                transactionData.DeletePersistentValue(shoppingCart.OrderNumber);

                this.Response.Redirect(paymentArgs.PaymentUrls.FailurePageUrl);

                break;
            }
            }
        }