public ShoppingCartRootObject CreateShoppingCart(CreateShoppingCartItem shoppingCartItem) { string shoppingCartItemJson = JsonConvert.SerializeObject(new { shopping_cart_item = shoppingCartItem }); string jsonUrl = $"/api/shopping_cart_items"; object productData = _nopApiClient.Post(jsonUrl, shoppingCartItemJson); var shoppingCart = JsonConvert.DeserializeObject <ShoppingCartRootObject>(productData.ToString()); return(shoppingCart); }
public JsonResult AddToShoppingCart(int productId, int quantity = 1, FormCollection form = null) { var attributesName = form.AllKeys.Where(f => f.Contains("product_attribute")).ToList(); var attributes = attributesName.Select(x => new ShoppingCartProductAttribute() { Id = x.Replace("product_attribute_", ""), Value = form.Get(x) }).ToList(); var shoppingCart = new CreateShoppingCartItem() { CustomerId = _userContext.CustomerId(), ProductId = productId, Quantity = quantity, CartType = "ShoppingCart", Attributes = attributes }; _nopService.CreateShoppingCart(shoppingCart); return(RenderMiniCartViewToString()); }