/// <summary>
        /// Method used to add an item to a (new) cart (async method)
        /// </summary>
        /// <param name="request">Request parameters</param>
        /// <returns>Cart reference</returns>
        public async Task <PushToCartResponse> PushToCartAsync(PushToCartRequest request)
        {
            CheckConfiguration();
            var requestMessage = new PushToCartRequestWrapper
            {
                ApiKey            = _configuration.ApiKey,
                PushToCartRequest = request
            };

            return(await Post <PushToCartResponse>("OpenApi/json/PushToCart", requestMessage));
        }
示例#2
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Cdiscount.OpenApi.ProxyClient.Config.ProxyClientConfig config = new Cdiscount.OpenApi.ProxyClient.Config.ProxyClientConfig {
                ApiKey = "e62a3122-2d61-462a-bef4-7403a408b5eb"
            };
            Cdiscount.OpenApi.ProxyClient.OpenApiClient client = new Cdiscount.OpenApi.ProxyClient.OpenApiClient(config);

            PushToCartRequest request = new PushToCartRequest();

            request.ProductId = _products.First().Id;

            client.PushToCart(request);
            //Frame.Navigate()
        }
        /// <summary>
        /// Helper method to add a product to a cart
        /// </summary>
        /// <param name="cartGuid">Guid of the cart if existing. Null if creating a new cart</param>
        /// <param name="product">Product to add to the cart</param>
        /// <param name="offer">Product specific offer to add to the cart</param>
        /// <param name="size">Specific size of the product to use (if applicable)</param>
        /// <param name="quantity">Quantity of the product to add</param>
        /// <returns>Cart reference</returns>
        public Task <PushToCartResponse> PushToCartAsync(Guid?cartGuid, Product product, ProductOffer offer, ProductSize size, int quantity)
        {
            if (product == null)
            {
                throw new ArgumentNullException(nameof(product), "The product must not be null");
            }

            if (quantity < 1 || quantity > 12)
            {
                throw new ArgumentOutOfRangeException(nameof(quantity), "The quantity must be an integer between 1 and 12");
            }

            PushToCartRequest pushToCartRequest = new PushToCartRequest()
            {
                ProductId = product.Id,
                Quantity  = quantity
            };

            if (cartGuid != Guid.Empty)
            {
                pushToCartRequest.CartGuid = cartGuid;
            }

            if (offer != null)
            {
                pushToCartRequest.OfferId = offer.Id;

                if (offer.Seller != null)
                {
                    pushToCartRequest.SellerId = offer.Seller.Id;
                }
            }

            if (size != null)
            {
                pushToCartRequest.SizeId = size.Id;
            }

            return(PushToCartAsync(pushToCartRequest));
        }
 public PushToCartResponse PushToCart(PushToCartRequest request)
 {
     CheckConfiguration();
     return(PushToCartAsync(request).Result);
 }