コード例 #1
0
        protected void UmbracoDefaultBeforeRequestInit(object sender, RequestInitEventArgs e)
        {
            try
            {
                //Domain.Core.Initialize.Init();
            }
            catch (Exception)
            {
                //throw;
            }
            try
            {
                var currentNode = Node.GetCurrent();

                if (ProductVariant.IsAlias(currentNode.NodeTypeAlias))
                {
                    var product = DomainHelper.GetProductById(currentNode.Parent.Id);
                    if (product != null)
                    {
                        HttpContext.Current.Response.RedirectPermanent(product.NiceUrl(), true);
                    }
                }
                else if (Product.IsAlias(currentNode.NodeTypeAlias))
                {
                    var product = DomainHelper.GetProductById(currentNode.Id);
                    if (product != null)
                    {
                        HttpContext.Current.Response.RedirectPermanent(product.NiceUrl(), true);
                    }
                }
                else if (Category.IsAlias(currentNode.NodeTypeAlias))
                {
                    var category = DomainHelper.GetCategoryById(currentNode.Id);
                    if (category != null)
                    {
                        HttpContext.Current.Response.RedirectPermanent(/* todo nicer */ RazorExtensions.ExtensionMethods.NiceUrl(category), true);
                    }
                }
            }
// ReSharper disable once EmptyGeneralCatchClause
            catch (Exception)
            {
                // intentionally left empty, because Umbraco will serve a 404
            }
        }
コード例 #2
0
        private static void UmbracoDefaultAfterRequestInit(object sender, RequestInitEventArgs e)
        {
            var currentMember = Membership.GetUser();

            var currentorder = UwebshopRequest.Current.OrderInfo ?? OrderHelper.GetOrder();

            var orderRepository = IO.Container.Resolve <IOrderRepository>();

            if (currentorder != null && (currentMember != null && currentorder.CustomerInfo.LoginName != currentMember.UserName))
            {
                orderRepository.SetCustomer(currentorder.UniqueOrderId, currentMember.UserName);
                currentorder.CustomerInfo.LoginName = currentMember.UserName;

                if (currentMember.ProviderUserKey != null)
                {
                    orderRepository.SetCustomerId(currentorder.UniqueOrderId, (int)currentMember.ProviderUserKey);
                    currentorder.CustomerInfo.CustomerId = (int)currentMember.ProviderUserKey;
                }


                currentorder.ResetDiscounts();
                currentorder.Save();
            }

            if (currentorder != null && currentMember == null && !string.IsNullOrEmpty(currentorder.CustomerInfo.LoginName))
            {
                orderRepository.SetCustomer(currentorder.UniqueOrderId, string.Empty);
                currentorder.CustomerInfo.LoginName = string.Empty;

                orderRepository.SetCustomerId(currentorder.UniqueOrderId, 0);
                currentorder.CustomerInfo.CustomerId = 0;

                currentorder.ResetDiscounts();
                currentorder.Save();
            }

            var cookie = HttpContext.Current.Request.Cookies["StoreInfo"];

            if (cookie != null)
            {
                if (currentMember != null && !string.IsNullOrEmpty(cookie["Wishlist"]))
                {
                    var wishlistId = cookie["Wishlist"];

                    Guid wishGuid;
                    Guid.TryParse(wishlistId, out wishGuid);

                    if (wishGuid != default(Guid) || wishGuid != Guid.Empty)
                    {
                        var wishlist = OrderHelper.GetOrder(wishGuid);

                        wishlist.CustomerInfo.LoginName = currentMember.UserName;

                        var userKey = 0;
                        if (currentMember.ProviderUserKey != null)
                        {
                            int.TryParse(currentMember.ProviderUserKey.ToString(), out userKey);
                            if (userKey != 0)
                            {
                                wishlist.CustomerInfo.CustomerId = userKey;
                            }
                        }
                        var wishlistName = "Wishlist";

                        var wishlistCount = Customers.GetWishlists(currentMember.UserName).Count() + 1;
                        wishlist.Name = string.Format("{0}{1}", wishlistName, wishlistCount);
                        wishlist.Save();

                        cookie.Values.Remove("Wishlist");
                    }
                }
            }

            var paymentProvider = UwebshopRequest.Current.PaymentProvider;

            if (paymentProvider != null)
            {
                new PaymentRequestHandler().HandleuWebshopPaymentRequest(paymentProvider);

                Log.Instance.LogDebug("UmbracoDefaultAfterRequestInit paymentProvider: " + paymentProvider.Name);

                var paymentProviderTemplate = paymentProvider.Node.template;

                ((UmbracoDefault)sender).MasterPageFile = template.GetMasterPageName(paymentProviderTemplate);

                return;
            }

            // todo: ombouwen naar UwebshopRequest.Current.Category, UwebshopRequest.Current lostrekken (ivm speed)
            var currentCategoryId = HttpContext.Current.Request["resolvedCategoryId"];
            var currentProductId  = HttpContext.Current.Request["resolvedProductId"];

            if (!string.IsNullOrEmpty(currentCategoryId))             //string.IsNullOrEmpty(currentProductUrl))
            {
                int categoryId;
                if (!int.TryParse(currentCategoryId, out categoryId))
                {
                    return;
                }
                var categoryFromUrl = DomainHelper.GetCategoryById(categoryId);
                if (categoryFromUrl == null)
                {
                    return;
                }

                if (categoryFromUrl.Disabled)
                {
                    HttpContext.Current.Response.StatusCode = 404;
                    HttpContext.Current.Response.Redirect(library.NiceUrl(int.Parse(GetCurrentNotFoundPageId())), true);
                    return;
                }

                if (Access.HasAccess(categoryFromUrl.Id, categoryFromUrl.GetUmbracoPath(), Membership.GetUser()))
                {
                    if (categoryFromUrl.Template != 0)
                    {
                        //umbraco.cms.businesslogic.template.Template.GetTemplate(currentCategory.Template).TemplateFilePath
                        ((UmbracoDefault)sender).MasterPageFile = template.GetMasterPageName(categoryFromUrl.Template);
                        //// get the template
                        //var t = template.GetMasterPageName(currentCategory.Template);
                        //// you did this and it works pre-4.10, right?
                        //page.MasterPageFile = t;
                        //// now this should work starting with 4.10
                        //e.Page.Template = t;
                    }

                    var altTemplate = HttpContext.Current.Request["altTemplate"];
                    if (!string.IsNullOrEmpty(altTemplate))
                    {
                        var altTemplateId = umbraco.cms.businesslogic.template.Template.GetTemplateIdFromAlias(altTemplate);

                        if (altTemplateId != 0)
                        {
                            ((UmbracoDefault)sender).MasterPageFile = template.GetMasterPageName(altTemplateId);
                        }
                    }
                }
                else
                {
                    if (HttpContext.Current.User.Identity.IsAuthenticated)
                    {
                        HttpContext.Current.Response.Redirect(library.NiceUrl(Access.GetErrorPage(categoryFromUrl.GetUmbracoPath())), true);
                    }
                    HttpContext.Current.Response.Redirect(library.NiceUrl(Access.GetLoginPage(categoryFromUrl.GetUmbracoPath())), true);
                }
            }
            else if (!string.IsNullOrEmpty(currentProductId))             // else
            {
                int productId;
                if (!int.TryParse(currentProductId, out productId))
                {
                    return;
                }
                var productFromUrl = DomainHelper.GetProductById(productId);
                if (productFromUrl == null)
                {
                    return;
                }

                if (Access.HasAccess(productFromUrl.Id, productFromUrl.Path(), Membership.GetUser()))
                {
                    if (productFromUrl.Template != 0)
                    {
                        ((UmbracoDefault)sender).MasterPageFile = template.GetMasterPageName(productFromUrl.Template);
                    }

                    var altTemplate = HttpContext.Current.Request["altTemplate"];
                    if (!string.IsNullOrEmpty(altTemplate))
                    {
                        var altTemplateId = umbraco.cms.businesslogic.template.Template.GetTemplateIdFromAlias(altTemplate);

                        if (altTemplateId != 0)
                        {
                            ((UmbracoDefault)sender).MasterPageFile = template.GetMasterPageName(altTemplateId);
                        }
                    }
                }
                else
                {
                    if (HttpContext.Current.User.Identity.IsAuthenticated)
                    {
                        HttpContext.Current.Response.Redirect(library.NiceUrl(Access.GetErrorPage(productFromUrl.Path())), true);
                    }
                    HttpContext.Current.Response.Redirect(library.NiceUrl(Access.GetLoginPage(productFromUrl.Path())), true);
                }
            }
        }