public static T GetCatalogQuery <T>(this IResolveFieldContext context) where T : ICatalogQuery
        {
            var result = AbstractTypeFactory <T> .TryCreateInstance();

            result.StoreId      = context.GetArgumentOrValue <string>("storeId");
            result.UserId       = context.GetArgumentOrValue <string>("userId") ?? context.GetCurrentUserId();
            result.CurrencyCode = context.GetArgumentOrValue <string>("currencyCode");
            result.CultureName  = context.GetArgumentOrValue <string>("cultureName");

            return(result);
        }
Example #2
0
        private static bool TryGetCategoryParentId(IResolveFieldContext <ExpCategory> context, out string parentId)
        {
            parentId = null;
            var outlines = context.Source.Category.Outlines;

            if (outlines.IsNullOrEmpty())
            {
                return(false);
            }

            var store = context.GetArgumentOrValue <Store>("store");

            foreach (var outline in outlines.Where(outline => outline.Items.Any(x => x.Id.Equals(store.Catalog))))
            {
                parentId = outline.Items.Take(outline.Items.Count - 1).Select(x => x.Id).LastOrDefault();

                //parentId should be a category id, not a catalog id
                if (parentId != null && parentId != store.Catalog)
                {
                    return(true);
                }
            }
            return(false);
        }