Example #1
0
 public GetProductsToUpdateInventoryBlock(IFindEntityPipeline findEntityPipeline, IGetEnvironmentCachePipeline cachePipeline, IFindEntitiesInListPipeline findEntitiesPipeline)
     : base((string)null)
 {
     this._cachePipeline = cachePipeline;
     this._findEntitiesInListPipeline = findEntitiesPipeline;
     this._findEntityPipeline         = findEntityPipeline;
 }
Example #2
0
        /// <summary>
        /// The execute.
        /// </summary>
        /// <param name="arg">
        /// The pipeline argument.
        /// </param>
        /// <param name="context">
        /// The context.
        /// </param>
        /// <returns>
        /// The <see cref="PipelineArgument"/>.
        /// </returns>
        public async override Task <LocalizedTerm> Run(LocalizedTerm arg, CommercePipelineExecutionContext context)
        {
            if (arg == null)
            {
                return(null);
            }

            var argument = context.CommerceContext.GetObject <LocalizedProductFeaturesConfigurationArgument>();

            if (string.IsNullOrEmpty(argument?.LocalizationKey))
            {
                return(arg);
            }

            KeyValuePair <string, bool> keyValuePair = context.CommerceContext.GetObject <KeyValuePair <string, bool> >((Func <KeyValuePair <string, bool>, bool>)(k => k.Key.Equals("IsFromCache", StringComparison.OrdinalIgnoreCase)));

            string currentLanguage = context.CommerceContext.CurrentLanguage();
            var    cachePolicy     = context.GetPolicy <ProductFeaturesCachePolicy>();

            if (cachePolicy.AllowCaching && !keyValuePair.Value)
            {
                string cacheKey = argument.LocalizationKey + "|" + currentLanguage;
                IGetEnvironmentCachePipeline cachePipeline            = this.Commander.Pipeline <IGetEnvironmentCachePipeline>();
                EnvironmentCacheArgument     environmentCacheArgument = new EnvironmentCacheArgument();
                environmentCacheArgument.CacheName = cachePolicy.CacheName;
                await(await cachePipeline.Run(environmentCacheArgument, context)).Set(cacheKey, (ICachable) new Cachable <LocalizedTerm>(arg, 1L), cachePolicy.GetCacheEntryOptions());
                cacheKey = (string)null;
            }

            return(arg);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="GetProfileDefinitionBlock"/> class.
 /// </summary>
 /// <param name="cachePipeline">The cache pipeline.</param>
 public GetProfileDefinitionBlock(IGetEnvironmentCachePipeline cachePipeline)
 {
     this._cachePipeline = cachePipeline;
 }
Example #4
0
 public ResolvePriceBookNameFromCommerceShopBlock(IGetEnvironmentCachePipeline cachePipeline, IGetItemByPathPipeline getItemByPathPipeline)
 {
     _cachePipeline         = cachePipeline;
     _getItemByPathPipeline = getItemByPathPipeline;
 }
Example #5
0
        public override async Task <List <string> > Run(string catalogName, CommercePipelineExecutionContext context)
        {
            List <InventorySet> inventorySets = new List <InventorySet>();

            GetProductsToUpdateInventoryBlock getProductsToUpdateInventoryBlock = this;

            // get the sitecoreid from catalog based on catalogname
            var catalogSitecoreId = "";
            FindEntitiesInListArgument entitiesInListArgumentCatalog = await getProductsToUpdateInventoryBlock._findEntitiesInListPipeline.Run(new FindEntitiesInListArgument(typeof(Catalog), string.Format("{0}", (object)CommerceEntity.ListName <Catalog>()), 0, int.MaxValue), context);

            foreach (CommerceEntity commerceEntity in (await getProductsToUpdateInventoryBlock._findEntitiesInListPipeline.Run(entitiesInListArgumentCatalog, (IPipelineExecutionContextOptions)context.ContextOptions)).List.Items)
            {
                var item = commerceEntity as Catalog;

                if (item.Name == catalogName)
                {
                    catalogSitecoreId = item.SitecoreId;
                    break;
                }
            }


            if (string.IsNullOrEmpty(catalogSitecoreId))
            {
                return(null);
            }

            List <string> productIds = new List <string>();


            string              cacheKey      = string.Format("{0}|{1}|{2}", context.CommerceContext.Environment.Name, context.CommerceContext.CurrentLanguage(), context.CommerceContext.CurrentShopName() ?? "");
            CatalogCachePolicy  cachePolicy   = context.GetPolicy <CatalogCachePolicy>();
            ICache              cache         = null;
            List <SellableItem> sellableItems = null;

            if (cachePolicy.AllowCaching)
            {
                IGetEnvironmentCachePipeline cachePipeline            = getProductsToUpdateInventoryBlock._cachePipeline;
                EnvironmentCacheArgument     environmentCacheArgument = new EnvironmentCacheArgument();
                environmentCacheArgument.CacheName = cachePolicy.CatalogsCacheName;
                CommercePipelineExecutionContext context1 = context;
                cache = await cachePipeline.Run(environmentCacheArgument, context1).ConfigureAwait(false);

                sellableItems = await cache.Get(cacheKey).ConfigureAwait(false) as List <SellableItem>;

                if (sellableItems != null)
                {
                    foreach (var item in sellableItems)
                    {
                        await GetProductId(context, getProductsToUpdateInventoryBlock, catalogSitecoreId, productIds, item);
                    }
                }
            }
            else
            {
                sellableItems = new List <SellableItem>();
                FindEntitiesInListArgument entitiesInListArgument = new FindEntitiesInListArgument(typeof(SellableItem), string.Format("{0}", (object)CommerceEntity.ListName <SellableItem>()), 0, int.MaxValue);
                foreach (CommerceEntity commerceEntity in (await getProductsToUpdateInventoryBlock._findEntitiesInListPipeline.Run(entitiesInListArgument, context.ContextOptions).ConfigureAwait(false)).List.Items)
                {
                    await GetProductId(context, getProductsToUpdateInventoryBlock, catalogSitecoreId, productIds, commerceEntity as SellableItem).ConfigureAwait(false);
                }

                if (cachePolicy.AllowCaching)
                {
                    if (cache != null)
                    {
                        await cache.Set(cacheKey, new Cachable <List <SellableItem> >(sellableItems, 1L), cachePolicy.GetCacheEntryOptions()).ConfigureAwait(false);
                    }
                }
            }

            return(productIds);
        }
Example #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GetFulfillmentFeeBookCommand"/> class.
 /// </summary>
 /// <param name="findEntityPipeline">The find entity pipeline.</param>
 /// <param name="serviceProvider">The service provider.</param>
 /// <param name="cachePipeline">The cache pipeline.</param>
 public GetFulfillmentFeeBookCommand(IFindEntityPipeline findEntityPipeline, IServiceProvider serviceProvider, IGetEnvironmentCachePipeline cachePipeline)
     : base(findEntityPipeline, serviceProvider)
 {
     this._cachePipeline = cachePipeline;
 }
 public FixRemoveEntityFromMemoryCacheBlock(IGetEnvironmentCachePipeline cachePipeline)
 {
     _cachePipeline = cachePipeline;
 }