public static VirtoCommerceCartModuleWebModelShoppingCart ToServiceModel(this ShoppingCart webModel) { var serviceModel = new VirtoCommerceCartModuleWebModelShoppingCart(); serviceModel.InjectFrom(webModel); serviceModel.Addresses = webModel.Addresses.Select(a => a.ToCartServiceModel()).ToList(); serviceModel.Coupon = webModel.Coupon != null && webModel.Coupon.AppliedSuccessfully ? webModel.Coupon.Code : null; serviceModel.Currency = webModel.Currency.Code; serviceModel.Discounts = webModel.Discounts.Select(d => d.ToServiceModel()).ToList(); serviceModel.DiscountTotal = (double)webModel.DiscountTotal.Amount; serviceModel.HandlingTotal = (double)webModel.HandlingTotal.Amount; serviceModel.Height = (double)webModel.Height; serviceModel.Items = webModel.Items.Select(i => i.ToServiceModel()).ToList(); serviceModel.Length = (double)webModel.Length; serviceModel.Payments = webModel.Payments.Select(p => p.ToServiceModel()).ToList(); serviceModel.Shipments = webModel.Shipments.Select(s => s.ToServiceModel()).ToList(); serviceModel.ShippingTotal = (double)webModel.ShippingTotal.Amount; serviceModel.SubTotal = (double)webModel.SubTotal.Amount; serviceModel.TaxDetails = webModel.TaxDetails.Select(td => td.ToServiceModel()).ToList(); serviceModel.DynamicProperties = webModel.DynamicProperties.Select(dp => dp.ToServiceModel()).ToList(); serviceModel.TaxTotal = (double)webModel.TaxTotal.Amount; serviceModel.Total = (double)webModel.Total.Amount; serviceModel.VolumetricWeight = (double)webModel.VolumetricWeight; serviceModel.Weight = (double)webModel.Weight; serviceModel.Width = (double)webModel.Width; return(serviceModel); }
public static VirtoCommerceCartModuleWebModelShoppingCart ToServiceModel(this ShoppingCart webModel) { var serviceModel = new VirtoCommerceCartModuleWebModelShoppingCart(); serviceModel.InjectFrom(webModel); serviceModel.Addresses = webModel.Addresses.Select(a => a.ToCartServiceModel()).ToList(); serviceModel.Coupon = webModel.Coupon != null && webModel.Coupon.AppliedSuccessfully ? webModel.Coupon.Code : null; serviceModel.Currency = webModel.Currency.Code; serviceModel.Discounts = webModel.Discounts.Select(d => d.ToServiceModel()).ToList(); serviceModel.DiscountTotal = (double)webModel.DiscountTotal.Amount; serviceModel.HandlingTotal = (double)webModel.HandlingTotal.Amount; serviceModel.Height = (double)webModel.Height; serviceModel.Items = webModel.Items.Select(i => i.ToServiceModel()).ToList(); serviceModel.Length = (double)webModel.Length; serviceModel.Payments = webModel.Payments.Select(p => p.ToServiceModel()).ToList(); serviceModel.Shipments = webModel.Shipments.Select(s => s.ToServiceModel()).ToList(); serviceModel.ShippingTotal = (double)webModel.ShippingTotal.Amount; serviceModel.SubTotal = (double)webModel.SubTotal.Amount; serviceModel.TaxDetails = webModel.TaxDetails.Select(td => td.ToServiceModel()).ToList(); serviceModel.DynamicProperties = webModel.DynamicProperties.Select(dp => dp.ToServiceModel()).ToList(); serviceModel.TaxTotal = (double)webModel.TaxTotal.Amount; serviceModel.Total = (double)webModel.Total.Amount; serviceModel.VolumetricWeight = (double)webModel.VolumetricWeight; serviceModel.Weight = (double)webModel.Weight; serviceModel.Width = (double)webModel.Width; serviceModel.ValidationType = webModel.ValidationType.ToString(); return serviceModel; }
public static ShoppingCart ToWebModel(this VirtoCommerceCartModuleWebModelShoppingCart serviceModel, Currency currency, Language language) { var webModel = new ShoppingCart(currency, language); webModel.InjectFrom(serviceModel); if (!string.IsNullOrEmpty(serviceModel.Coupon)) { webModel.Coupon = new Coupon { AppliedSuccessfully = true, Code = serviceModel.Coupon }; } if (serviceModel.Items != null) { webModel.Items = serviceModel.Items.Select(i => i.ToWebModel(currency, language)).ToList(); webModel.HasPhysicalProducts = webModel.Items.Any(i => string.IsNullOrEmpty(i.ProductType) || !string.IsNullOrEmpty(i.ProductType) && i.ProductType.Equals("Physical", StringComparison.OrdinalIgnoreCase)); } if (serviceModel.Addresses != null) { webModel.Addresses = serviceModel.Addresses.Select(a => a.ToWebModel()).ToList(); var billingAddress = webModel.Addresses.FirstOrDefault(a => a.Type == AddressType.Billing); if (billingAddress == null) { billingAddress = new Address { Type = AddressType.Billing }; } webModel.DefaultBillingAddress = billingAddress; if (webModel.HasPhysicalProducts) { var shippingAddress = webModel.Addresses.FirstOrDefault(a => a.Type == AddressType.Shipping); if (shippingAddress == null) { shippingAddress = new Address { Type = AddressType.Shipping }; } webModel.DefaultShippingAddress = shippingAddress; } } if (serviceModel.Payments != null) { webModel.Payments = serviceModel.Payments.Select(p => p.TowebModel(currency)).ToList(); } if (serviceModel.Shipments != null) { webModel.Shipments = serviceModel.Shipments.Select(s => s.ToWebModel(webModel)).ToList(); } if (serviceModel.DynamicProperties != null) { webModel.DynamicProperties = serviceModel.DynamicProperties.Select(dp => dp.ToWebModel()).ToList(); } if (serviceModel.TaxDetails != null) { webModel.TaxDetails = serviceModel.TaxDetails.Select(td => td.ToWebModel()).ToList(); } webModel.HandlingTotal = new Money(serviceModel.HandlingTotal ?? 0, currency); webModel.Height = (decimal)(serviceModel.Height ?? 0); webModel.IsAnonymous = serviceModel.IsAnonymous == true; webModel.IsRecuring = serviceModel.IsRecuring == true; webModel.Length = (decimal)(serviceModel.Length ?? 0); webModel.TaxIncluded = serviceModel.TaxIncluded == true; webModel.TaxTotal = new Money(serviceModel.TaxTotal ?? 0, currency); webModel.VolumetricWeight = (decimal)(serviceModel.VolumetricWeight ?? 0); webModel.Weight = (decimal)(serviceModel.Weight ?? 0); webModel.Width = (decimal)(serviceModel.Width ?? 0); return(webModel); }
/// <summary> /// Create shopping cart /// </summary> /// <param name="cart">Shopping cart model</param> /// <returns>Task of ApiResponse (VirtoCommerceCartModuleWebModelShoppingCart)</returns> public async System.Threading.Tasks.Task<ApiResponse<VirtoCommerceCartModuleWebModelShoppingCart>> CartModuleCreateAsyncWithHttpInfo (VirtoCommerceCartModuleWebModelShoppingCart cart) { // verify the required parameter 'cart' is set if (cart == null) throw new ApiException(400, "Missing required parameter 'cart' when calling CartModuleCreate"); var path_ = "/api/cart/carts"; var pathParams = new Dictionary<String, String>(); var queryParams = new Dictionary<String, String>(); var headerParams = new Dictionary<String, String>(); var formParams = new Dictionary<String, String>(); var fileParams = new Dictionary<String, FileParameter>(); String postBody = null; // to determine the Accept header String[] http_header_accepts = new String[] { "application/json", "text/json" }; String http_header_accept = Configuration.ApiClient.SelectHeaderAccept(http_header_accepts); if (http_header_accept != null) headerParams.Add("Accept", Configuration.ApiClient.SelectHeaderAccept(http_header_accepts)); // set "format" to json by default // e.g. /pet/{petId}.{format} becomes /pet/{petId}.json pathParams.Add("format", "json"); postBody = Configuration.ApiClient.Serialize(cart); // http body (model) parameter // make the HTTP request IRestResponse response = (IRestResponse) await Configuration.ApiClient.CallApiAsync(path_, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, pathParams); int statusCode = (int) response.StatusCode; if (statusCode >= 400) throw new ApiException (statusCode, "Error calling CartModuleCreate: " + response.Content, response.Content); else if (statusCode == 0) throw new ApiException (statusCode, "Error calling CartModuleCreate: " + response.ErrorMessage, response.ErrorMessage); return new ApiResponse<VirtoCommerceCartModuleWebModelShoppingCart>(statusCode, response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()), (VirtoCommerceCartModuleWebModelShoppingCart) Configuration.ApiClient.Deserialize(response, typeof(VirtoCommerceCartModuleWebModelShoppingCart))); }
/// <summary> /// Create shopping cart /// </summary> /// <param name="cart">Shopping cart model</param> /// <returns>Task of VirtoCommerceCartModuleWebModelShoppingCart</returns> public async System.Threading.Tasks.Task<VirtoCommerceCartModuleWebModelShoppingCart> CartModuleCreateAsync (VirtoCommerceCartModuleWebModelShoppingCart cart) { ApiResponse<VirtoCommerceCartModuleWebModelShoppingCart> response = await CartModuleCreateAsyncWithHttpInfo(cart); return response.Data; }
/// <summary> /// Create shopping cart /// </summary> /// <param name="cart">Shopping cart model</param> /// <returns>VirtoCommerceCartModuleWebModelShoppingCart</returns> public VirtoCommerceCartModuleWebModelShoppingCart CartModuleCreate (VirtoCommerceCartModuleWebModelShoppingCart cart) { ApiResponse<VirtoCommerceCartModuleWebModelShoppingCart> response = CartModuleCreateWithHttpInfo(cart); return response.Data; }
/// <summary> /// Create shopping cart /// </summary> /// <exception cref="VirtoCommerce.Client.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="cart">Shopping cart model</param> /// <returns>Task of ApiResponse (VirtoCommerceCartModuleWebModelShoppingCart)</returns> public async System.Threading.Tasks.Task<ApiResponse<VirtoCommerceCartModuleWebModelShoppingCart>> CartModuleCreateAsyncWithHttpInfo (VirtoCommerceCartModuleWebModelShoppingCart cart) { // verify the required parameter 'cart' is set if (cart == null) throw new ApiException(400, "Missing required parameter 'cart' when calling ShoppingCartModuleApi->CartModuleCreate"); var localVarPath = "/api/cart/carts"; var localVarPathParams = new Dictionary<String, String>(); var localVarQueryParams = new Dictionary<String, String>(); var localVarHeaderParams = new Dictionary<String, String>(Configuration.DefaultHeader); var localVarFormParams = new Dictionary<String, String>(); var localVarFileParams = new Dictionary<String, FileParameter>(); Object localVarPostBody = null; // to determine the Content-Type header String[] localVarHttpContentTypes = new String[] { "application/json", "text/json", "application/xml", "text/xml", "application/x-www-form-urlencoded" }; String localVarHttpContentType = Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes); // to determine the Accept header String[] localVarHttpHeaderAccepts = new String[] { "application/json", "text/json", "application/xml", "text/xml" }; String localVarHttpHeaderAccept = Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts); if (localVarHttpHeaderAccept != null) localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept); // set "format" to json by default // e.g. /pet/{petId}.{format} becomes /pet/{petId}.json localVarPathParams.Add("format", "json"); if (cart.GetType() != typeof(byte[])) { localVarPostBody = Configuration.ApiClient.Serialize(cart); // http body (model) parameter } else { localVarPostBody = cart; // byte array } // make the HTTP request IRestResponse localVarResponse = (IRestResponse) await Configuration.ApiClient.CallApiAsync(localVarPath, Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams, localVarPathParams, localVarHttpContentType); int localVarStatusCode = (int) localVarResponse.StatusCode; if (localVarStatusCode >= 400 && (localVarStatusCode != 404 || Configuration.ThrowExceptionWhenStatusCodeIs404)) throw new ApiException (localVarStatusCode, "Error calling CartModuleCreate: " + localVarResponse.Content, localVarResponse.Content); else if (localVarStatusCode == 0) throw new ApiException (localVarStatusCode, "Error calling CartModuleCreate: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage); return new ApiResponse<VirtoCommerceCartModuleWebModelShoppingCart>(localVarStatusCode, localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()), (VirtoCommerceCartModuleWebModelShoppingCart) Configuration.ApiClient.Deserialize(localVarResponse, typeof(VirtoCommerceCartModuleWebModelShoppingCart))); }
/// <summary> /// Update shopping cart /// </summary> /// <exception cref="VirtoCommerce.Client.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="cart">Shopping cart model</param> /// <returns>VirtoCommerceCartModuleWebModelShoppingCart</returns> public VirtoCommerceCartModuleWebModelShoppingCart CartModuleUpdate (VirtoCommerceCartModuleWebModelShoppingCart cart) { ApiResponse<VirtoCommerceCartModuleWebModelShoppingCart> localVarResponse = CartModuleUpdateWithHttpInfo(cart); return localVarResponse.Data; }