/// <summary>
        /// Gets a display object from the Examine cache or falls back the the database if not found
        /// </summary>
        /// <param name="key">
        /// The key.
        /// </param>
        /// <returns>
        /// The <see cref="ProductDisplay"/>.
        /// </returns>
        protected override ProductDisplay GetDisplayObject(Guid key)
        {
            var criteria = SearchProvider.CreateSearchCriteria();

            criteria.Field(KeyFieldInIndex, key.ToString()).And().Field("master", "True");

            var display = SearchProvider.Search(criteria).Select(PerformMapSearchResultToDisplayObject).FirstOrDefault();

            if (display != null)
            {
                display.EnsureValueConversion(this._conversionType);
                return(display);
            }

            var entity = Service.GetByKey(key);

            if (entity == null)
            {
                return(null);
            }

            ReindexEntity(entity);

            return(this.ModifyData(entity.ToProductDisplay(this._conversionType)));
        }
示例#2
0
        /// <summary>
        /// Gets a <see cref="ProductVariantDisplay"/> by it's key
        /// </summary>
        /// <param name="key">
        /// The key.
        /// </param>
        /// <returns>
        /// The <see cref="ProductVariantDisplay"/>.
        /// </returns>
        public ProductVariantDisplay GetProductVariantByKey(Guid key)
        {
            var criteria = SearchProvider.CreateSearchCriteria();

            criteria.Field("productVariantKey", key.ToString());

            return(CachedSearch(criteria, ExamineDisplayExtensions.ToProductVariantDisplay).FirstOrDefault());
        }
示例#3
0
        /// <summary>
        /// Gets the <see cref="ProductVariantDisplay"/> for a product
        /// </summary>
        /// <param name="productKey">
        /// The product key.
        /// </param>
        /// <returns>
        /// The <see cref="IEnumerable{ProductVariantDisplay}"/>.
        /// </returns>
        public IEnumerable <ProductVariantDisplay> GetVariantsByProduct(Guid productKey)
        {
            var criteria = SearchProvider.CreateSearchCriteria();

            criteria.Field(KeyFieldInIndex, productKey.ToString()).Not().Field("master", "True");

            var results = SearchProvider.Search(criteria);

            return(results.Select(x => this.ModifyData(x.ToProductVariantDisplay())));
        }
示例#4
0
        /// <summary>
        /// Gets a product by it's slug.
        /// </summary>
        /// <param name="slug">
        /// The slug.
        /// </param>
        /// <returns>
        /// The <see cref="ProductDisplay"/>.
        /// </returns>
        public ProductDisplay GetBySlug(string slug)
        {
            var criteria = SearchProvider.CreateSearchCriteria();

            criteria.Field("slugs", slug).And().Field("master", "True");

            var display = SearchProvider.Search(criteria).Select(PerformMapSearchResultToDisplayObject).FirstOrDefault();

            // Don't modifiy the data here as it would have been modified in the PerformMapSearchResultToDisplayObject
            if (display != null)
            {
                return(display);
            }

            var key = _productService.GetKeyForSlug(slug);

            return(Guid.Empty.Equals(key) ? null : this.GetByKey(key));
        }
示例#5
0
        /// <summary>
        /// Gets a <see cref="ProductVariantDisplay"/> by it's unique SKU
        /// </summary>
        /// <param name="sku">
        /// The SKU.
        /// </param>
        /// <returns>
        /// The <see cref="ProductVariantDisplay"/>.
        /// </returns>
        public ProductVariantDisplay GetProductVariantBySku(string sku)
        {
            var criteria = SearchProvider.CreateSearchCriteria();

            criteria.Field("sku", sku).Not().Field("master", "True");

            var result = CachedSearch(criteria, ExamineDisplayExtensions.ToProductVariantDisplay).FirstOrDefault();

            if (result != null)
            {
                return(this.ModifyData(result));
            }

            var variant = _productService.GetProductVariantBySku(sku);

            if (variant != null)
            {
                this.ReindexEntity(variant);
            }

            return(this.ModifyData(variant.ToProductVariantDisplay()));
        }
示例#6
0
        /// <summary>
        /// Gets a <see cref="ProductVariantDisplay"/> by it's key
        /// </summary>
        /// <param name="key">
        /// The key.
        /// </param>
        /// <returns>
        /// The <see cref="ProductVariantDisplay"/>.
        /// </returns>
        public ProductVariantDisplay GetProductVariantByKey(Guid key)
        {
            var criteria = SearchProvider.CreateSearchCriteria();

            criteria.Field("productVariantKey", key.ToString());

            var result = CachedSearch(criteria, ExamineDisplayExtensions.ToProductVariantDisplay).FirstOrDefault();

            if (result != null)
            {
                return(this.ModifyData(result));
            }

            var variant = _productService.GetProductVariantByKey(key);

            if (variant != null)
            {
                this.ReindexEntity(variant);
            }

            return(this.ModifyData(variant.ToProductVariantDisplay()));
        }
示例#7
0
        /// <summary>
        /// Gets a <see cref="ProductDisplay"/> by it's SKU.
        /// </summary>
        /// <param name="sku">
        /// The SKU.
        /// </param>
        /// <returns>
        /// The <see cref="ProductDisplay"/>.
        /// </returns>
        public ProductDisplay GetBySku(string sku)
        {
            var criteria = SearchProvider.CreateSearchCriteria();

            criteria.Field("sku", sku).And().Field("master", "True");

            var display = SearchProvider.Search(criteria).Select(PerformMapSearchResultToDisplayObject).FirstOrDefault();

            if (display != null)
            {
                return(this.ModifyData(display));
            }

            var entity = _productService.GetBySku(sku);

            if (entity == null)
            {
                return(null);
            }

            ReindexEntity(entity);

            return(this.ModifyData(AutoMapper.Mapper.Map <ProductDisplay>(entity)));
        }