Пример #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CachedProductQuery"/> class.
 /// </summary>
 /// <param name="service">
 /// The service.
 /// </param>
 /// <param name="indexProvider">
 /// The index provider.
 /// </param>
 /// <param name="searchProvider">
 /// The search provider.
 /// </param>
 /// <param name="enableDataModifiers">
 /// The enable data modifiers.
 /// </param>
 /// <param name="conversionType">
 /// The is for back office editors.
 /// </param>
 internal CachedProductQuery(IPageCachedService <IProduct> service, BaseIndexProvider indexProvider, BaseSearchProvider searchProvider, bool enableDataModifiers, DetachedValuesConversionType conversionType)
     : base(service, indexProvider, searchProvider, enableDataModifiers)
 {
     _productService      = (ProductService)service;
     this._conversionType = conversionType;
     this.Initialize();
 }
        /// <summary>
        /// Maps a <see cref="IProduct"/> to <see cref="ProductDisplay"/>.
        /// </summary>
        /// <param name="product">
        /// The product.
        /// </param>
        /// <param name="conversionType">
        /// The detached value conversion type.
        /// </param>
        /// <returns>
        /// The <see cref="ProductDisplay"/>.
        /// </returns>
        public static ProductDisplay ToProductDisplay(this IProduct product, DetachedValuesConversionType conversionType = DetachedValuesConversionType.Db)
        {
            var productDisplay = AutoMapper.Mapper.Map <ProductDisplay>(product);

            productDisplay.EnsureValueConversion(conversionType);
            return(productDisplay);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="CachedQueryProvider"/> class.
 /// </summary>
 /// <param name="merchelloContext">
 /// The merchelloContext context.
 /// </param>
 /// <param name="enableDataModifiers">
 /// The enable data modifiers.
 /// </param>
 /// <param name="conversionType">
 /// The conversion type.
 /// </param>
 internal CachedQueryProvider(IMerchelloContext merchelloContext, bool enableDataModifiers, DetachedValuesConversionType conversionType)
 {
     Mandate.ParameterNotNull(merchelloContext, "MerchelloContext is not initialized");
     this.DataModifiersEnabled = enableDataModifiers;
     _conversionType           = conversionType;
     InitializeProvider(merchelloContext);
 }
Пример #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CachedQueryProvider"/> class.
 /// </summary>
 /// <param name="serviceContext">
 /// The service context.
 /// </param>
 /// <param name="enableDataModifiers">
 /// The enable data modifiers.
 /// </param>
 /// <param name="conversionType">
 /// The conversion type.
 /// </param>
 internal CachedQueryProvider(IServiceContext serviceContext, bool enableDataModifiers, DetachedValuesConversionType conversionType)
 {
     Mandate.ParameterNotNull(serviceContext, "ServiceContext is not initialized");
     _enableDataModifiers = enableDataModifiers;
     _conversionType      = conversionType;
     InitializeProvider(serviceContext);
 }
Пример #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CachedProductQuery"/> class.
 /// </summary>
 /// <param name="merchelloContext">
 /// The <see cref="IMerchelloContext"/>.
 /// </param>
 /// <param name="indexProvider">
 /// The index provider.
 /// </param>
 /// <param name="searchProvider">
 /// The search provider.
 /// </param>
 /// <param name="enableDataModifiers">
 /// The enable data modifiers.
 /// </param>
 /// <param name="conversionType">
 /// The is for back office editors.
 /// </param>
 internal CachedProductQuery(IMerchelloContext merchelloContext, BaseIndexProvider indexProvider, BaseSearchProvider searchProvider, bool enableDataModifiers, DetachedValuesConversionType conversionType)
     : base(merchelloContext.Cache, merchelloContext.Services.ProductService, indexProvider, searchProvider, enableDataModifiers)
 {
     _productService        = (ProductService)merchelloContext.Services.ProductService;
     this._conversionType   = conversionType;
     _productContentFactory = new Lazy <ProductContentFactory>(() => new ProductContentFactory());
     _cache = new VirtualProductContentCache(merchelloContext.Cache, this.GetProductContent, enableDataModifiers);
     this.Initialize();
 }
 /// <summary>
 /// Utility for setting the IsForBackOfficeEditor property.
 /// </summary>
 /// <param name="display">
 /// The display.
 /// </param>
 /// <param name="conversionType">
 /// The value conversion type.
 /// </param>
 internal static void EnsureValueConversion(this ProductDisplay display, DetachedValuesConversionType conversionType = DetachedValuesConversionType.Db)
 {
     ((ProductDisplayBase)display).EnsureValueConversion(conversionType);
     if (display.ProductVariants.Any())
     {
         foreach (var variant in display.ProductVariants)
         {
             variant.EnsureValueConversion(conversionType);
         }
     }
 }
 /// <summary>
 /// Utility for setting the IsForBackOfficeEditor property.
 /// </summary>
 /// <param name="display">
 /// The display.
 /// </param>
 /// <param name="conversionType">
 /// The value conversion type.
 /// </param>
 internal static void EnsureValueConversion(this ProductDisplayBase display, DetachedValuesConversionType conversionType = DetachedValuesConversionType.Db)
 {
     if (display.DetachedContents.Any())
     {
         foreach (var dc in display.DetachedContents)
         {
             var contentType = DetachedValuesConverter.Current.GetContentTypeByKey(dc.DetachedContentType.UmbContentType.Key);
             if (dc.ValueConversion != conversionType && contentType != null)
             {
                 dc.DetachedDataValues = DetachedValuesConverter.Current.Convert(contentType, dc.DetachedDataValues, conversionType);
                 dc.ValueConversion    = conversionType;
             }
         }
     }
 }
Пример #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MerchelloHelper"/> class.
        /// </summary>
        /// <param name="merchelloContext">
        /// The merchello context.
        /// </param>
        /// <param name="enableDataModifiers">
        /// The enable data modifiers.
        /// </param>
        /// <param name="conversionType">
        /// The conversion type.
        /// </param>
        /// <param name="queryManager">
        /// The proxy service resolver.
        /// </param>
        /// <param name="collectionProviderResolver">
        /// The <see cref="IEntityCollectionProviderResolver"/>
        /// </param>
        internal MerchelloHelper(
            IMerchelloContext merchelloContext,
            bool enableDataModifiers,
            DetachedValuesConversionType conversionType,
            IProxyQueryManager queryManager,
            IEntityCollectionProviderResolver collectionProviderResolver)
        {
            Ensure.ParameterNotNull(merchelloContext, "ServiceContext cannot be null");
            Ensure.ParameterNotNull(queryManager, "The query manager was null");
            Ensure.ParameterNotNull(collectionProviderResolver, "The IEntityCollectionProviderResolver was null");
            _enableDataModifiers = enableDataModifiers;
            _queryProvider       = new Lazy <ICachedQueryProvider>(() => new CachedQueryProvider(merchelloContext, _enableDataModifiers, conversionType));
            _validationHelper    = new Lazy <IValidationHelper>(() => new ValidationHelper());

            this.Initialize(merchelloContext, queryManager, collectionProviderResolver);
        }
Пример #9
0
        public static void EnsureValueConversion(this ProductOptionDisplay display, DetachedValuesConversionType conversionType = DetachedValuesConversionType.Db)
        {
            if (display.DetachedContentTypeKey.Equals(Guid.Empty))
            {
                return;
            }

            var contentType = new Lazy <IContentType>(() => DetachedValuesConverter.Current.GetContentTypeByKey(display.DetachedContentTypeKey));

            foreach (var choice in display.Choices.Where(x => x.ValueConversion != conversionType))
            {
                if (contentType.Value != null)
                {
                    choice.EnsureValueConversion(contentType.Value, conversionType);
                }
            }
        }
Пример #10
0
        /// <summary>
        /// Utility for setting the IsForBackOfficeEditor property.
        /// </summary>
        /// <param name="display">
        /// The display.
        /// </param>
        /// <param name="conversionType">
        /// The value conversion type.
        /// </param>
        public static void EnsureValueConversion(this ProductDisplayBase display, DetachedValuesConversionType conversionType = DetachedValuesConversionType.Db)
        {
            if (display == null)
            {
                return;
            }
            var dtC = display.DetachedContents.ToList();

            if (dtC.Any())
            {
                foreach (var dc in dtC)
                {
                    var contentType = DetachedValuesConverter.Current.GetContentTypeByKey(dc.DetachedContentType.UmbContentType.Key);
                    if (dc.ValueConversion != conversionType && contentType != null)
                    {
                        dc.DetachedDataValues = DetachedValuesConverter.Current.Convert(contentType, dc.DetachedDataValues.ToList(), conversionType);
                        dc.ValueConversion    = conversionType;
                    }
                }
            }
        }
Пример #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CachedQueryProvider"/> class.
 /// </summary>
 /// <param name="serviceContext">
 /// The service context.
 /// </param>
 /// <param name="enableDataModifiers">
 /// The enable data modifiers.
 /// </param>
 /// <param name="conversionType">
 /// The conversion type.
 /// </param>
 internal CachedQueryProvider(IServiceContext serviceContext, bool enableDataModifiers, DetachedValuesConversionType conversionType)
 {
     Mandate.ParameterNotNull(serviceContext, "ServiceContext is not initialized");
     _enableDataModifiers = enableDataModifiers;
     _conversionType = conversionType;
     InitializeProvider(serviceContext);
 }
Пример #12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MerchelloHelper"/> class.
        /// </summary>
        /// <param name="serviceContext">
        /// The service context.
        /// </param>
        /// <param name="enableDataModifiers">
        /// The enable data modifiers.
        /// </param>
        /// <param name="conversionType">
        /// The conversion type for detached values.
        /// </param>
        internal MerchelloHelper(IServiceContext serviceContext, bool enableDataModifiers, DetachedValuesConversionType conversionType)
        {
            Mandate.ParameterNotNull(serviceContext, "ServiceContext cannot be null");

            _enableDataModifiers = enableDataModifiers;
            _queryProvider       = new Lazy <ICachedQueryProvider>(() => new CachedQueryProvider(serviceContext, _enableDataModifiers));
            _validationHelper    = new Lazy <IValidationHelper>(() => new ValidationHelper());
        }
 internal static ProductVariantDisplay ToProductVariantDisplay(this IProductVariant productVariant, DetachedValuesConversionType conversionType = DetachedValuesConversionType.Db)
 {
     var display = AutoMapper.Mapper.Map<ProductVariantDisplay>(productVariant);
     display.EnsureValueConversion(conversionType);
     return display;
 }
Пример #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MerchelloHelper"/> class.
 /// </summary>
 /// <param name="merchelloContext">
 /// The <see cref="IMerchelloContext"/>.
 /// </param>
 /// <param name="enableDataModifiers">
 /// The enable data modifiers.
 /// </param>
 /// <param name="conversionType">
 /// The conversion type for detached values.
 /// </param>
 internal MerchelloHelper(IMerchelloContext merchelloContext, bool enableDataModifiers, DetachedValuesConversionType conversionType)
     : this(merchelloContext, enableDataModifiers, conversionType, ProxyQueryManager.Current, EntityCollectionProviderResolver.Current)
 {
 }
 /// <summary>
 /// Utility for setting the IsForBackOfficeEditor property.
 /// </summary>
 /// <param name="display">
 /// The display.
 /// </param>
 /// <param name="conversionType">
 /// The value conversion type.
 /// </param>
 internal static void EnsureValueConversion(this ProductDisplay display, DetachedValuesConversionType conversionType = DetachedValuesConversionType.Db)
 {
     ((ProductDisplayBase)display).EnsureValueConversion(conversionType);
     if (display.ProductVariants.Any())
     {
         foreach (var variant in display.ProductVariants)
         {
             variant.EnsureValueConversion(conversionType);
         }
     }
 }
        /// <summary>
        /// Converts the detached values collection to property values for various usages depending on type passed.
        /// </summary>
        /// <param name="contentType">
        /// The content type.
        /// </param>
        /// <param name="detachedContentValues">
        /// The detached content values.
        /// </param>
        /// <param name="conversionType">
        /// The conversion type.
        /// </param>
        /// <param name="additionalData">
        /// A dictionary of additional data (only used with DetachedValuesConversionType database).
        /// </param>
        /// <returns>
        /// The converted values.
        /// </returns>
        public IEnumerable <KeyValuePair <string, string> > Convert(IContentType contentType, IEnumerable <KeyValuePair <string, string> > detachedContentValues, DetachedValuesConversionType conversionType = DetachedValuesConversionType.Db, Dictionary <string, object> additionalData = null)
        {
            switch (conversionType)
            {
            case DetachedValuesConversionType.Editor:
                return(ConvertDbToEditor(contentType, detachedContentValues));

            case DetachedValuesConversionType.Db:
                return(ConvertEditorToDb(contentType, detachedContentValues, additionalData));

            default:
                return(ConvertEditorToDb(contentType, detachedContentValues));
            }
        }
        /// <summary>
        /// The to product option display.
        /// </summary>
        /// <param name="productOption">
        /// The product option.
        /// </param>
        /// <param name="conversionType">
        /// The property editor conversion type.
        /// </param>
        /// <returns>
        /// The <see cref="ProductOptionDisplay"/>.
        /// </returns>
        internal static ProductOptionDisplay ToProductOptionDisplay(this IProductOption productOption, DetachedValuesConversionType conversionType = DetachedValuesConversionType.Db)
        {
            var display = AutoMapper.Mapper.Map <ProductOptionDisplay>(productOption);

            display.EnsureValueConversion(conversionType);
            display.Choices = display.Choices.OrderBy(x => x.SortOrder);
            return(display);
        }
Пример #18
0
        /// <summary>
        /// Maps a <see cref="IProduct"/> to <see cref="ProductDisplay"/>.
        /// </summary>
        /// <param name="product">
        /// The product.
        /// </param>
        /// <param name="conversionType">
        /// The detached value conversion type.
        /// </param>
        /// <returns>
        /// The <see cref="ProductDisplay"/>.
        /// </returns>
        public static ProductDisplay ToProductListingDisplay(this IProduct product, DetachedValuesConversionType conversionType = DetachedValuesConversionType.Db)
        {
            var productDisplay = AutoMapper.Mapper.Map <ProductDisplay>(product);

            if (productDisplay.ProductVariants.Any())
            {
                // List of variants to assign
                var variants = new List <ProductVariantDisplay>();

                // Get all productVariants ordered by price
                var priceList = productDisplay.ProductVariants.OrderBy(x => x.Price).ToArray(); // Lowest to highest

                // Get all product variants ordered by sale price
                var salePriceList = productDisplay.ProductVariants.Where(x => x.OnSale).OrderBy(x => x.SalePrice).ToArray(); // Lowest to highest

                // Get the standard pricing first price
                var firstPrice = priceList.First();
                variants.Add(firstPrice);

                // Get the last price
                var lastPrice = priceList.Last();

                // (Haven't already got this variant)
                if (lastPrice.Key != firstPrice.Key)
                {
                    variants.Add(lastPrice);
                }

                // Check for sale pricing
                if (salePriceList.Any())
                {
                    // Get the sale pricing
                    var lowSalePriceVar = salePriceList.First();

                    // Abandon if null
                    if (lowSalePriceVar != null)
                    {
                        // Sanity checks (Haven't already got this variant)
                        if (firstPrice.Key != lowSalePriceVar.Key && lastPrice.Key != lowSalePriceVar.Key)
                        {
                            variants.Add(lowSalePriceVar);
                        }

                        // Check we are not adding the same one
                        var highSalePriceVar = salePriceList.Last();

                        if (lowSalePriceVar.Key != highSalePriceVar.Key && firstPrice.Key != highSalePriceVar.Key && lastPrice.Key != highSalePriceVar.Key)
                        {
                            variants.Add(highSalePriceVar);
                        }
                    }
                }

                // Assign new variants
                productDisplay.ProductVariants = variants;
            }

            productDisplay.EnsureValueConversion(conversionType);

            return(productDisplay);
        }
Пример #19
0
        /// <summary>
        /// Converts the detached values collection to property values for various usages depending on type passed.
        /// </summary>
        /// <param name="contentType">
        /// The content type.
        /// </param>
        /// <param name="detachedContentValues">
        /// The detached content values.
        /// </param>
        /// <param name="conversionType">
        /// The conversion type.
        /// </param>
        /// <param name="additionalData">
        /// A dictionary of additional data (only used with DetachedValuesConversionType database).
        /// </param>
        /// <returns>
        /// The converted values.
        /// </returns>
        public IEnumerable<KeyValuePair<string, string>> Convert(IContentType contentType, IEnumerable<KeyValuePair<string, string>> detachedContentValues, DetachedValuesConversionType conversionType = DetachedValuesConversionType.Db, Dictionary<string, object> additionalData = null)
        {
            switch (conversionType)
            {
                case DetachedValuesConversionType.Editor:
                    return ConvertDbToEditor(contentType, detachedContentValues);

                case DetachedValuesConversionType.Db:
                    return ConvertEditorToDb(contentType, detachedContentValues, additionalData);

                default:
                    return ConvertEditorToDb(contentType, detachedContentValues);
            }
        }
Пример #20
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MerchelloHelper"/> class.
        /// </summary>
        /// <param name="merchelloContext">
        /// The <see cref="IMerchelloContext"/>.
        /// </param>
        /// <param name="enableDataModifiers">
        /// The enable data modifiers.
        /// </param>
        /// <param name="conversionType">
        /// The conversion type for detached values.
        /// </param>
        internal MerchelloHelper(IMerchelloContext merchelloContext, bool enableDataModifiers, DetachedValuesConversionType conversionType)
        {
            Mandate.ParameterNotNull(merchelloContext, "ServiceContext cannot be null");

            _enableDataModifiers = enableDataModifiers;
            _queryProvider = new Lazy<ICachedQueryProvider>(() => new CachedQueryProvider(merchelloContext, _enableDataModifiers, conversionType));
            _validationHelper = new Lazy<IValidationHelper>(() => new ValidationHelper());
            _productContentFactory = new Lazy<ProductContentFactory>(() => new ProductContentFactory());
        }
        internal static void EnsureValueConversion(this ProductAttributeDisplay display, IContentType contentType, DetachedValuesConversionType conversionType = DetachedValuesConversionType.Db)
        {
            if (display.ValueConversion == conversionType) return;

            display.ValueConversion = conversionType;
            display.DetachedDataValues = DetachedValuesConverter.Current.Convert(contentType, display.DetachedDataValues, conversionType);
        }
        internal static void EnsureValueConversion(this ProductOptionDisplay display, DetachedValuesConversionType conversionType = DetachedValuesConversionType.Db)
        {
            if (display.DetachedContentTypeKey.Equals(Guid.Empty)) return;

            var contentType = new Lazy<IContentType>(() => DetachedValuesConverter.Current.GetContentTypeByKey(display.DetachedContentTypeKey));
            foreach (var choice in display.Choices.Where(x => x.ValueConversion != conversionType))
            {
                if (contentType.Value != null)
                {
                    choice.EnsureValueConversion(contentType.Value, conversionType);
                }

            }
        }
 /// <summary>
 /// Utility for setting the IsForBackOfficeEditor property.
 /// </summary>
 /// <param name="display">
 /// The display.
 /// </param>
 /// <param name="conversionType">
 /// The value conversion type.
 /// </param>
 internal static void EnsureValueConversion(this ProductDisplayBase display, DetachedValuesConversionType conversionType = DetachedValuesConversionType.Db)
 {
     if (display.DetachedContents.Any())
     {
         foreach (var dc in display.DetachedContents)
         {
             var contentType = DetachedValuesConverter.Current.GetContentTypeByKey(dc.DetachedContentType.UmbContentType.Key);
             if (dc.ValueConversion != conversionType && contentType != null)
             {
                     dc.DetachedDataValues = DetachedValuesConverter.Current.Convert(contentType, dc.DetachedDataValues, conversionType);
                     dc.ValueConversion = conversionType;
             }
         }
     }
 }
Пример #24
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MerchelloHelper"/> class.
        /// </summary>
        /// <param name="merchelloContext">
        /// The merchello context.
        /// </param>
        /// <param name="enableDataModifiers">
        /// The enable data modifiers.
        /// </param>
        /// <param name="conversionType">
        /// The conversion type.
        /// </param>
        /// <param name="queryManager">
        /// The proxy service resolver.
        /// </param>
        /// <param name="collectionProviderResolver">
        /// The <see cref="IEntityCollectionProviderResolver"/>
        /// </param>
        internal MerchelloHelper(
            IMerchelloContext merchelloContext,
            bool enableDataModifiers,
            DetachedValuesConversionType conversionType,
            IProxyQueryManager queryManager,
            IEntityCollectionProviderResolver collectionProviderResolver)
        {
            Ensure.ParameterNotNull(merchelloContext, "ServiceContext cannot be null");
            Ensure.ParameterNotNull(queryManager, "The query manager was null");
            Ensure.ParameterNotNull(collectionProviderResolver, "The IEntityCollectionProviderResolver was null");
            _enableDataModifiers = enableDataModifiers;
            _queryProvider = new Lazy<ICachedQueryProvider>(() => new CachedQueryProvider(merchelloContext, _enableDataModifiers, conversionType));
            _validationHelper = new Lazy<IValidationHelper>(() => new ValidationHelper());

            this.Initialize(merchelloContext, queryManager, collectionProviderResolver);
        }
Пример #25
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CachedProductQuery"/> class.
 /// </summary>
 /// <param name="merchelloContext">
 /// The <see cref="IMerchelloContext"/>.
 /// </param>
 /// <param name="enableDataModifiers">
 /// The enable data modifiers.
 /// </param>
 /// <param name="conversionType">
 /// The detached value conversion type.
 /// </param>
 internal CachedProductQuery(IMerchelloContext merchelloContext, bool enableDataModifiers, DetachedValuesConversionType conversionType)
     : this(
         merchelloContext,
         ExamineManager.Instance.IndexProviderCollection["MerchelloProductIndexer"],
         ExamineManager.Instance.SearchProviderCollection["MerchelloProductSearcher"],
         enableDataModifiers,
         conversionType)
 {
 }
        internal static void EnsureValueConversion(this ProductAttributeDisplay display, IContentType contentType, DetachedValuesConversionType conversionType = DetachedValuesConversionType.Db)
        {
            if (display.ValueConversion == conversionType)
            {
                return;
            }

            display.ValueConversion    = conversionType;
            display.DetachedDataValues = DetachedValuesConverter.Current.Convert(contentType, display.DetachedDataValues, conversionType);
        }
        /// <summary>
        /// Converts the detached value collection to property values for various usages depending on type passed.
        /// </summary>
        /// <param name="contentType">
        /// The content type.
        /// </param>
        /// <param name="dcv">
        /// The detached content value.
        /// </param>
        /// <param name="conversionType">
        /// The conversion type.
        /// </param>
        /// <param name="additionalData">
        /// A dictionary of additional data (only used with DetachedValuesConversionType database).
        /// </param>
        /// <returns>
        /// The converted values.
        /// </returns>
        public KeyValuePair <string, string> Convert(IContentType contentType, KeyValuePair <string, string> dcv, DetachedValuesConversionType conversionType = DetachedValuesConversionType.Db, Dictionary <string, object> additionalData = null)
        {
            switch (conversionType)
            {
            case DetachedValuesConversionType.Editor:
                return(ConvertDbToEditor(contentType, dcv));

            case DetachedValuesConversionType.Db:
                return(ConvertEditorToDb(contentType, dcv, additionalData));

            default:
                return(ConvertEditorToDb(contentType, dcv, additionalData));
            }
        }
Пример #28
0
        /// <summary>
        /// Converts the detached value collection to property values for various usages depending on type passed.
        /// </summary>
        /// <param name="contentType">
        /// The content type.
        /// </param>
        /// <param name="dcv">
        /// The detached content value.
        /// </param>
        /// <param name="conversionType">
        /// The conversion type.
        /// </param>
        /// <param name="additionalData">
        /// A dictionary of additional data (only used with DetachedValuesConversionType database).
        /// </param>
        /// <returns>
        /// The converted values.
        /// </returns>
        public KeyValuePair<string, string> Convert(IContentType contentType, KeyValuePair<string, string> dcv, DetachedValuesConversionType conversionType = DetachedValuesConversionType.Db, Dictionary<string, object> additionalData = null)
        {
            switch (conversionType)
            {

                case DetachedValuesConversionType.Editor:
                    return ConvertDbToEditor(contentType, dcv);

                case DetachedValuesConversionType.Db:
                    return ConvertEditorToDb(contentType, dcv, additionalData);

                default:
                    return ConvertEditorToDb(contentType, dcv, additionalData);
            }
        }
Пример #29
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MerchelloHelper"/> class.
        /// </summary>
        /// <param name="serviceContext">
        /// The service context.
        /// </param>
        /// <param name="enableDataModifiers">
        /// The enable data modifiers.
        /// </param>
        /// <param name="conversionType">
        /// The conversion type for detached values.
        /// </param>
        internal MerchelloHelper(IServiceContext serviceContext, bool enableDataModifiers, DetachedValuesConversionType conversionType)
        {
            Mandate.ParameterNotNull(serviceContext, "ServiceContext cannot be null");

            _enableDataModifiers = enableDataModifiers;
            _queryProvider = new Lazy<ICachedQueryProvider>(() => new CachedQueryProvider(serviceContext, _enableDataModifiers));
            _validationHelper = new Lazy<IValidationHelper>(() => new ValidationHelper());
        }
Пример #30
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MerchelloHelper"/> class.
 /// </summary>
 /// <param name="merchelloContext">
 /// The <see cref="IMerchelloContext"/>.
 /// </param>
 /// <param name="enableDataModifiers">
 /// The enable data modifiers.
 /// </param>
 /// <param name="conversionType">
 /// The conversion type for detached values.
 /// </param>
 internal MerchelloHelper(IMerchelloContext merchelloContext, bool enableDataModifiers, DetachedValuesConversionType conversionType)
     : this(merchelloContext, enableDataModifiers, conversionType, ProxyQueryManager.Current, EntityCollectionProviderResolver.Current)
 {
 }
        internal static ProductAttributeDisplay ToProductAttributeDisplay(this IProductAttribute productAttribute, IContentType contentType, DetachedValuesConversionType conversionType = DetachedValuesConversionType.Db)
        {
            var display = AutoMapper.Mapper.Map <ProductAttributeDisplay>(productAttribute);

            if (contentType == null)
            {
                return(display);
            }
            display.EnsureValueConversion(contentType, conversionType);
            return(display);
        }
Пример #32
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CachedQueryProvider"/> class.
 /// </summary>
 /// <param name="merchelloContext">
 /// The merchelloContext context.
 /// </param>
 /// <param name="enableDataModifiers">
 /// The enable data modifiers.
 /// </param>
 /// <param name="conversionType">
 /// The conversion type.
 /// </param>
 internal CachedQueryProvider(IMerchelloContext merchelloContext, bool enableDataModifiers, DetachedValuesConversionType conversionType)
 {
     Mandate.ParameterNotNull(merchelloContext, "MerchelloContext is not initialized");
     this.DataModifiersEnabled = enableDataModifiers;
     _conversionType = conversionType;
     InitializeProvider(merchelloContext);
 }
        internal static ProductVariantDisplay ToProductVariantDisplay(this IProductVariant productVariant, DetachedValuesConversionType conversionType = DetachedValuesConversionType.Db)
        {
            var display = AutoMapper.Mapper.Map <ProductVariantDisplay>(productVariant);

            display.EnsureValueConversion(conversionType);
            return(display);
        }
 /// <summary>
 /// Maps a <see cref="IProduct"/> to <see cref="ProductDisplay"/>.
 /// </summary>
 /// <param name="product">
 /// The product.
 /// </param>
 /// <param name="conversionType">
 /// The detached value conversion type.
 /// </param>
 /// <returns>
 /// The <see cref="ProductDisplay"/>.
 /// </returns>
 public static ProductDisplay ToProductDisplay(this IProduct product, DetachedValuesConversionType conversionType = DetachedValuesConversionType.Db)
 {
     var productDisplay = AutoMapper.Mapper.Map<ProductDisplay>(product);
     productDisplay.EnsureValueConversion(conversionType);
     return productDisplay;
 }
 internal static ProductAttributeDisplay ToProductAttributeDisplay(this IProductAttribute productAttribute, IContentType contentType, DetachedValuesConversionType conversionType = DetachedValuesConversionType.Db)
 {
     var display = AutoMapper.Mapper.Map<ProductAttributeDisplay>(productAttribute);
     if (contentType == null) return display;
     display.EnsureValueConversion(contentType, conversionType);
     return display;
 }
 /// <summary>
 /// The to product option display.
 /// </summary>
 /// <param name="productOption">
 /// The product option.
 /// </param>
 /// <param name="conversionType">
 /// The property editor conversion type.
 /// </param>
 /// <returns>
 /// The <see cref="ProductOptionDisplay"/>.
 /// </returns>
 internal static ProductOptionDisplay ToProductOptionDisplay(this IProductOption productOption, DetachedValuesConversionType conversionType = DetachedValuesConversionType.Db)
 {
     var display = AutoMapper.Mapper.Map<ProductOptionDisplay>(productOption);
     display.EnsureValueConversion(conversionType);
     display.Choices = display.Choices.OrderBy(x => x.SortOrder);
     return display;
 }
Пример #37
0
        /// <summary>
        /// The to product display.
        /// </summary>
        /// <param name="result">
        /// The result.
        /// </param>
        /// <param name="getProductVariants">
        /// The get Product Variants.
        /// </param>
        /// <param name="conversionType">
        /// The conversion Type.
        /// </param>
        /// <returns>
        /// The <see cref="ProductDisplay"/>.
        /// </returns>
        internal static ProductDisplay ToProductDisplay(this SearchResult result, Func <Guid, IEnumerable <ProductVariantDisplay> > getProductVariants, DetachedValuesConversionType conversionType = DetachedValuesConversionType.Db)
        {
            // this should be the master variant
            var productDisplay = new ProductDisplay(result.ToProductVariantDisplay());

            productDisplay.ProductVariants = getProductVariants(productDisplay.Key);
            productDisplay.ProductOptions  = RawJsonFieldAsCollection <ProductOptionDisplay>(result, "productOptions");
            productDisplay.EnsureValueConversion(conversionType);
            return(productDisplay);
        }
Пример #38
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MerchelloHelper"/> class.
        /// </summary>
        /// <param name="merchelloContext">
        /// The <see cref="IMerchelloContext"/>.
        /// </param>
        /// <param name="enableDataModifiers">
        /// The enable data modifiers.
        /// </param>
        /// <param name="conversionType">
        /// The conversion type for detached values.
        /// </param>
        internal MerchelloHelper(IMerchelloContext merchelloContext, bool enableDataModifiers, DetachedValuesConversionType conversionType)
        {
            Mandate.ParameterNotNull(merchelloContext, "ServiceContext cannot be null");

            _enableDataModifiers   = enableDataModifiers;
            _queryProvider         = new Lazy <ICachedQueryProvider>(() => new CachedQueryProvider(merchelloContext, _enableDataModifiers, conversionType));
            _validationHelper      = new Lazy <IValidationHelper>(() => new ValidationHelper());
            _productContentFactory = new Lazy <ProductContentFactory>(() => new ProductContentFactory());
        }