Exemple #1
0
        public CatalogProduct GetById(string itemId, ItemResponseGroup respGroup, string catalogId = null)
        {
            var cacheKey = GetCacheKey("ItemService.GetById", itemId, respGroup.ToString(), catalogId);
            var retVal   = _cacheManager.Get(cacheKey, RegionName, () => _itemService.GetById(itemId, respGroup, catalogId));

            return(retVal);
        }
Exemple #2
0
        /// <summary>
        /// Reduce product details according to response group
        /// </summary>
        /// <param name="product"></param>
        /// <param name="respGroup"></param>
        protected virtual void ReduceDetails(CatalogProduct product, ItemResponseGroup respGroup)
        {
            if (product == null)
            {
                throw new ArgumentNullException(nameof(product));
            }

            product.ReduceDetails(respGroup.ToString());
        }
Exemple #3
0
        protected virtual async Task <Product[]> GetProductsAsync(IList <string> ids, ItemResponseGroup responseGroup, WorkContext workContext)
        {
            var cacheKey = CacheKey.With(GetType(), "GetProductsAsync", string.Join("-", ids.OrderBy(x => x)), responseGroup.ToString());
            var result   = await _memoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) =>
            {
                cacheEntry.AddExpirationToken(CatalogCacheRegion.CreateChangeToken());
                cacheEntry.AddExpirationToken(_apiChangesWatcher.CreateChangeToken());

                return(await _productsApi.GetProductByPlentyIdsAsync(ids, ((int)responseGroup).ToString()));
            });

            return(result.Select(x => x.ToProduct(workContext.CurrentLanguage, workContext.CurrentCurrency, workContext.CurrentStore)).ToArray());
        }
        public CatalogProduct[] GetByIds(string[] itemIds, ItemResponseGroup respGroup, string catalogId = null)
        {
            var retVal      = _productService.GetByIds(itemIds, respGroup, catalogId).ToList();
            var extCatalogs = GetExternalCatalogs();

            foreach (var extCatalog in extCatalogs)
            {
                var apiUrl    = extCatalog.PropertyValues.FirstOrDefault(x => x.PropertyName.EqualsInvariant("apiUrl")).Value.ToString();
                var chunkSize = 30;
                for (int i = 0; i < itemIds.Count(); i += chunkSize)
                {
                    var externalProducts = _vcCatalogClientFactory(apiUrl).CatalogModuleProducts.GetProductByIds(itemIds.Skip(i).Take(chunkSize).ToArray(), respGroup.ToString());
                    foreach (var externalProduct in externalProducts)
                    {
                        var product      = ConvertToProduct(externalProduct);
                        var existProduct = retVal.FirstOrDefault(x => x.Id.EqualsInvariant(externalProduct.Id));
                        if (existProduct != null)
                        {
                            retVal.Remove(existProduct);
                            product.Properties     = existProduct.Properties;
                            product.PropertyValues = existProduct.PropertyValues;
                            product.Links          = existProduct.Links;
                            if (product.Outlines.IsNullOrEmpty())
                            {
                                product.Outlines = existProduct.Outlines;
                            }
                            else if (!existProduct.Outlines.IsNullOrEmpty())
                            {
                                product.Outlines.AddRange(existProduct.Outlines);
                            }
                        }
                        retVal.Add(product);
                    }
                }
            }

            foreach (var product in retVal.Where(x => x.CategoryId != null))
            {
                var dataCategory = base.AllCachedCategories.FirstOrDefault(x => x.Id == product.CategoryId);
                if (dataCategory != null)
                {
                    foreach (var catPropValue in dataCategory.CategoryPropertyValues)
                    {
                        var propValue = catPropValue.ToCoreModel();
                        propValue.Id = null;
                        product.PropertyValues.Add(propValue);
                    }
                }
                if (!product.PropertyValues.Any(x => x.PropertyName.EqualsInvariant("usergroups")))
                {
                    product.PropertyValues.Add(new PropertyValue
                    {
                        PropertyName = "usergroups",
                        Value        = "__NULL__",
                        ValueType    = PropertyValueType.ShortText
                    });
                }
            }

            return(retVal.ToArray());
        }