public override void LoadDataFromPropertiesDictionary(DiscountProduct discount, IPropertyProvider fields, ILocalization localization) { UmbracoOrderDiscountRepository.LoadBaseProperties(discount, fields, localization, _storeService); discount.Items = StoreHelper.ReadMultiStoreItemFromPropertiesDictionary(_aliasses.products, localization, fields).Split(',').Select(id => Common.Helpers.ParseInt(id)).Distinct().Where(id => id > 0).ToList(); var categories = discount.Items.Select(id => DomainHelper.GetCategoryById(id)).Where(x => x != null).ToList(); var products = discount.Items.Select(id => DomainHelper.GetProductById(id)).Where(x => x != null).ToList(); var discountProducts = new List <IProduct>(); foreach (var category in categories) { foreach (var catProduct in category.Products) { if (discountProducts.All(x => x.Id != catProduct.Id)) { discountProducts.Add(catProduct); } } } foreach (var product in products.Where(product => discountProducts.All(x => product != null && x.Id != product.Id))) { discountProducts.Add(product); } discount.Products = discountProducts; discount.ProductVariants = discount.Items.Select(id => DomainHelper.GetProductVariantById(id)).Where(variant => variant != null); var excludeVariants = StoreHelper.ReadMultiStoreItemFromPropertiesDictionary(_aliasses.excludeVariants, localization, fields); discount.ExcludeVariants = excludeVariants == "enable" || excludeVariants == "1" || excludeVariants == "true"; }
/// <summary> /// Gets the categories recursive. /// </summary> /// <param name="categoryId">The category unique identifier.</param> /// <param name="storeAlias">The store alias.</param> /// <param name="currencyCode">The currency code.</param> /// <returns></returns> public static IEnumerable <ICategory> GetCategoriesRecursive(int categoryId, string storeAlias = null, string currencyCode = null) { var category = DomainHelper.GetCategoryById(categoryId, storeAlias, currencyCode); var categoryList = new List <ICategory>(); GetCategoriesFromCategory(categoryList, category); return(categoryList); }
/// <summary> /// Gets the category. /// </summary> /// <param name="categoryId">The category unique identifier.</param> /// <param name="storeAlias">The store alias.</param> /// <param name="currencyCode">The currency code.</param> /// <returns></returns> public static ICategory GetCategory(int categoryId = 0, string storeAlias = null, string currencyCode = null) { if (categoryId == 0) { var currentCat = UwebshopRequest.Current.Category; if (storeAlias == null && currencyCode == null || currentCat == null) { return((ICategory)currentCat); } categoryId = currentCat.Id; } return(CategoryAdaptor.Create(DomainHelper.GetCategoryById(categoryId, storeAlias, currencyCode))); }
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 } }
/// <summary> /// Returns the catagory information for the given categoryId, with products & prices /// </summary> public static XPathNavigator GetCategory(int categoryId) { var category = DomainHelper.GetCategoryById(categoryId); var stream1 = new MemoryStream(); //Serialize the Record object to a memory stream using DataContractSerializer. var serializer = new DataContractSerializer(typeof(Category)); serializer.WriteObject(stream1, category); stream1.Position = 0; var result = new StreamReader(stream1).ReadToEnd(); var doc = new XmlDocument(); doc.LoadXml(result); return(doc.CreateNavigator()); }
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); } } }
public static IEnumerable <ICategory> GetCurrentCategoryPath() { return(UwebshopRequest.Current.CategoryPath.Select(c => CategoryAdaptor.Create(DomainHelper.GetCategoryById(c.Id)))); }
/// <summary> /// Returns unique categories witch have one ore more tags in common with the given categoryId /// </summary> /// <param name="categoryId">The category unique identifier.</param> /// <param name="storeAlias">The store alias.</param> /// <param name="currencyCode"></param> /// <returns></returns> public static IEnumerable <ICategory> MatchingTagCategories(int categoryId, string storeAlias = null, string currencyCode = null) { var currentCategory = DomainHelper.GetCategoryById(categoryId, storeAlias, currencyCode); return(MatchingTagCategories(currentCategory)); }
/// <summary> /// Gets the products variants recursive. /// </summary> /// <param name="categoryId">The category unique identifier.</param> /// <param name="storeAlias">The store alias.</param> /// <param name="currencyCode">The currency code.</param> /// <returns></returns> public static IEnumerable <IProductVariant> GetProductsVariantsRecursive(int categoryId, string storeAlias = null, string currencyCode = null) { var category = DomainHelper.GetCategoryById(categoryId, storeAlias, currencyCode); return(category.ProductsRecursive.SelectMany(p => p.GetAllVariants()).Select(v => new VariantAdaptor(v))); }
/// <summary> /// Gets the products recursive. /// </summary> /// <param name="categoryId">The category unique identifier.</param> /// <param name="storeAlias">The store alias.</param> /// <param name="currencyCode">The currency code.</param> /// <returns></returns> public static IEnumerable <IProduct> GetProductsRecursive(int categoryId, string storeAlias = null, string currencyCode = null) { var category = DomainHelper.GetCategoryById(categoryId, storeAlias, currencyCode); return(category.ProductsRecursive.Select(p => new ProductAdaptor(p))); }
public List <OrderLine> GetApplicableOrderLines(OrderInfo orderinfo, IEnumerable <int> itemIdsToCheck) { var productIds = new List <int>(); var productVariantIds = new List <int>(); var objects = itemIdsToCheck.Select(id => IO.Container.Resolve <ICMSEntityRepository>().GetByGlobalId(id)).Where(o => o != null); if (!objects.Any()) { return(new List <OrderLine>()); } foreach (var node in objects) { var itemId = node.Id; if (Category.IsAlias(node.NodeTypeAlias)) { var category = DomainHelper.GetCategoryById(itemId); if (category == null || category.Disabled) { continue; } productIds.AddRange(category.ProductsRecursive.Select(product => product.Id)); productIds.Add(itemId); } if (Product.IsAlias(node.NodeTypeAlias)) { productIds.Add(node.Id); } if (node.NodeTypeAlias.StartsWith(ProductVariant.NodeAlias)) { productVariantIds.Add(node.Id); } if (node.NodeTypeAlias.StartsWith(PaymentProvider.NodeAlias) && orderinfo.PaymentInfo.Id != node.Id) { return(new List <OrderLine>()); } if (node.NodeTypeAlias == PaymentProviderMethod.NodeAlias && orderinfo.PaymentInfo.MethodId != node.Id.ToString()) { return(new List <OrderLine>()); } if (node.NodeTypeAlias.StartsWith(ShippingProvider.NodeAlias) && orderinfo.ShippingInfo.Id != node.Id) { return(new List <OrderLine>()); } if (node.NodeTypeAlias == ShippingProviderMethod.NodeAlias && orderinfo.ShippingInfo.MethodId != node.Id.ToString()) { return(new List <OrderLine>()); } if (node.NodeTypeAlias.StartsWith(DiscountProduct.NodeAlias) && orderinfo.OrderLines.Any(x => x.ProductInfo.CatalogProduct != null && x.ProductInfo.CatalogProduct.Discount.Id != node.Id)) { return(new List <OrderLine>()); } } //todo:test return(orderinfo.OrderLines.Where(orderLine => !productIds.Any() || productIds.Contains(orderLine.ProductInfo.Id)).Where(orderLine => !productVariantIds.Any() || orderLine.ProductInfo.ProductVariants.Any(x => productVariantIds.Contains(x.Id))).ToList()); }
/// <summary> /// Returns all the products in this category, including any sublevel /// </summary> /// <param name="categoryId">The category unique identifier.</param> /// <param name="storeAlias">The store alias.</param> /// <returns></returns> public static IEnumerable <IProduct> ProductsRecursive(int categoryId, string storeAlias = null) { return(DomainHelper.GetCategoryById(categoryId, storeAlias).ProductsRecursive.ToList()); }
public static List <Product> GetProductsRecursive(int categoryId, string storeAlias = null) { return(DomainHelper.GetCategoryById(categoryId, storeAlias).ProductsRecursive.Cast <Product>().ToList()); }
public static List <Category> GetMatchingTagCategories(int categoryId, string storeAlias = null) { var currentCategory = DomainHelper.GetCategoryById(categoryId, storeAlias); return(GetMatchingTagCategories(currentCategory)); }
/// <summary> /// Gets the category. /// </summary> /// <param name="categoryId">The category unique identifier.</param> /// <param name="storeAlias">The store alias.</param> /// <returns></returns> public static ICategory Category(int categoryId, string storeAlias = null) { var category = DomainHelper.GetCategoryById(categoryId, storeAlias); return(category == null ? null : (category.Disabled ? null : category)); }