public HttpResponseMessage AddItemCacheItem(AddToItemCacheInstruction instruction) { var itemCache = GetCustomerItemCache(instruction); if (itemCache == null) { return Request.CreateResponse(HttpStatusCode.NotFound); } var variants = new List<ProductVariantDisplay>(); foreach (var addItem in instruction.Items.ToArray()) { if (addItem.IsProductVariant) { var variant = _merchello.Query.Product.GetProductVariantByKey(addItem.Key); if (variant != null) variants.Add(variant); } else { var product = _merchello.Query.Product.GetByKey(addItem.Key); if (product != null && !product.ProductVariants.Any()) variants.Add(product.AsMasterVariantDisplay()); } } foreach (var v in variants.ToArray()) itemCache.AddItem(v); itemCache.Save(); return Request.CreateResponse(HttpStatusCode.OK); }
public HttpResponseMessage AddItemCacheItem(AddToItemCacheInstruction instruction) { var itemCache = GetCustomerItemCache(instruction); if (itemCache == null) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } var variants = new List <ProductVariantDisplay>(); foreach (var addItem in instruction.Items.ToArray()) { if (addItem.IsProductVariant) { var variant = _merchello.Query.Product.GetProductVariantByKey(addItem.Key); if (variant != null) { variants.Add(variant); } } else { var product = _merchello.Query.Product.GetByKey(addItem.Key); if (product != null && !product.ProductVariants.Any()) { variants.Add(product.AsMasterVariantDisplay()); } } } foreach (var v in variants.ToArray()) { itemCache.AddItem(v); } itemCache.Save(); return(Request.CreateResponse(HttpStatusCode.OK)); }