public JsonResult GetShippingMethods(GetShippingMethodsInputModel inputModel) { try { Assert.ArgumentNotNull(inputModel, "inputModel"); var validationResult = new BaseJsonResult(); this.ValidateModel(validationResult); if (validationResult.HasErrors) { return(Json(validationResult, JsonRequestBehavior.AllowGet)); } var response = this.ShippingManager.GetShippingMethods(CurrentStorefront, CurrentVisitorContext, inputModel); var result = new ShippingMethodsJsonResult(response.ServiceProviderResult); if (response.ServiceProviderResult.Success && response.Result != null) { result.Initialize(response.ServiceProviderResult.ShippingMethods, response.ServiceProviderResult.ShippingMethodsPerItem); } return(Json(result, JsonRequestBehavior.AllowGet)); } catch (Exception e) { CommerceLog.Current.Error("GetShippingMethods", this, e); return(Json(new BaseJsonResult("GetShippingMethods", e), JsonRequestBehavior.AllowGet)); } }
public ShippingMethodsBaseJsonResult GetShippingMethods(GetShippingMethodsInputModel inputModel) { var response = this._shippingManager.GetShippingMethods(CurrentStorefront, CurrentVisitorContext, inputModel); var result = new ShippingMethodsJsonResult(response.ServiceProviderResult); if (response.ServiceProviderResult.Success && response.Result != null) { result.Initialize(response.ServiceProviderResult.ShippingMethods, response.ServiceProviderResult.ShippingMethodsPerItem); } return(result); }
protected virtual void CheckIfEditing( IVisitorContext visitorContext, CustomBaseCheckoutDataJsonResult result) { if ((result.Cart == null || result.Cart.Shipments == null ? 0 : (result.Cart.Shipments.Count > 0 ? 1 : 0)) == 0) { return; } foreach (ShippingInfoJsonResult shipment1 in result.Cart.Shipments) { ShippingInfoJsonResult shipment = shipment1; if (shipment.LineIDs != null && shipment.LineIDs.Count > 0) { CartLineJsonResult cartLineJsonResult = result.Cart.Lines.Find((l => l.ExternalCartLineId.Equals(shipment.LineIDs[0], StringComparison.OrdinalIgnoreCase))); if (cartLineJsonResult != null && cartLineJsonResult.ShippingOptions != null && cartLineJsonResult.ShippingOptions.Count <ShippingOptionJsonResult>() > 0) { ShippingOptionJsonResult optionJsonResult = cartLineJsonResult.ShippingOptions.ElementAt <ShippingOptionJsonResult>(0); if (optionJsonResult != null) { shipment.EditModeShippingOptionType = optionJsonResult.ShippingOptionType; if (optionJsonResult.ShippingOptionType == ShippingOptionType.ShipToAddress) { AddressJsonResult addressJsonResult = result.Cart.Parties.Find((Predicate <AddressJsonResult>)(p => p.ExternalId.Equals(shipment.PartyID, StringComparison.OrdinalIgnoreCase))); if (addressJsonResult != null) { GetShippingMethodsInputModel inputModel = new GetShippingMethodsInputModel() { ShippingPreferenceType = ShippingOptionType.ShipToAddress.Value.ToString((IFormatProvider)CultureInfo.InvariantCulture), ShippingAddress = new PartyInputModel() }; inputModel.ShippingAddress.ExternalId = addressJsonResult.ExternalId; inputModel.ShippingAddress.Address1 = addressJsonResult.Address1; inputModel.ShippingAddress.City = addressJsonResult.City; inputModel.ShippingAddress.State = addressJsonResult.State; inputModel.ShippingAddress.ZipPostalCode = addressJsonResult.ZipPostalCode; inputModel.ShippingAddress.Country = addressJsonResult.Country; inputModel.ShippingAddress.IsPrimary = addressJsonResult.IsPrimary; inputModel.Lines = new List <CartLineInputModel>(); ShippingMethodsJsonResult shippingMethods = this.GetShippingMethods(visitorContext, inputModel); if (shippingMethods != null) { shipment.ShipmentEditModel = this.ModelProvider.GetModel <ShipmentEditModeDataJsonResult>(); shipment.ShipmentEditModel.ShippingMethods = shippingMethods.ShippingMethods; } } } } } } } }