/// <summary> /// Processes the specified arguments. /// </summary> /// <param name="args">The arguments.</param> public override void Process(Commerce.Pipelines.ServicePipelineArgs args) { Assert.ArgumentNotNull(args, "args"); Assert.ArgumentCondition(args.Request is GetAvailableRegionsRequest, "args.Request", "args.Request is GetAvailableRegionsRequest"); Assert.ArgumentCondition(args.Result is GetAvailableRegionsResult, "args.Result", "args.Result is GetAvailableRegionsResult"); var request = (GetAvailableRegionsRequest)args.Request; var result = (GetAvailableRegionsResult)args.Result; var regions = new Dictionary <string, string>(); //// The country guid is passed into the coutry code. //// Item countryItem = Sitecore.Context.Database.GetItem(Sitecore.Data.ID.Parse(request.CountryCode)); Item countryAndRegionItem = this.GetCountryAndRegionItem(); string countryAndRegionPath = countryAndRegionItem.Paths.FullPath; string query = string.Format(CultureInfo.InvariantCulture, "fast:{0}//*[@{1} = '{2}']", countryAndRegionPath, CommerceServerStorefrontConstants.KnownFieldNames.CountryCode, request.CountryCode); Item foundCountry = countryAndRegionItem.Database.SelectSingleItem(query); if (foundCountry != null) { foreach (Item region in foundCountry.GetChildren()) { regions.Add(region.ID.ToGuid().ToString(), region[CommerceServerStorefrontConstants.KnownFieldNames.RegionName]); } } result.AvailableRegions = regions; }
/// <summary> /// Processes the specified arguments. /// </summary> /// <param name="args">The arguments.</param> public override void Process(Commerce.Pipelines.ServicePipelineArgs args) { Assert.ArgumentNotNull(args, "args"); Assert.ArgumentCondition(args.Request is GetShippingOptionsRequest, "args.Request", "args.Request is GetShippingOptionsRequest"); Assert.ArgumentCondition(args.Result is GetShippingOptionsResult, "args.Result", "args.Result is GetShippingOptionsResult"); var request = (GetShippingOptionsRequest)args.Request; var result = (GetShippingOptionsResult)args.Result; List <ShippingOption> availableShippingOptionList = new List <ShippingOption>(); List <ShippingOption> allShippingOptionList = new List <ShippingOption>(); foreach (Item shippingOptionItem in this.GetShippingOptionsItem().GetChildren()) { ShippingOption option = this.EntityFactory.Create <ShippingOption>("ShippingOption"); this.TranslateToShippingOption(shippingOptionItem, option); bool add = option.ShippingOptionType == ShippingOptionType.ElectronicDelivery && !CartCanBeEmailed(request.Cart as CommerceCart) ? false : option.ShippingOptionType == ShippingOptionType.DeliverItemsIndividually && request.Cart.Lines.Count <= 1 ? false : true; if (add) { availableShippingOptionList.Add(option); } allShippingOptionList.Add(option); } result.ShippingOptions = new System.Collections.ObjectModel.ReadOnlyCollection <ShippingOption>(availableShippingOptionList); result.LineShippingPreferences = this.GetLineShippingOptions(request.Cart as CommerceCart, allShippingOptionList).AsReadOnly(); }
/// <summary> /// Processes the specified arguments. /// </summary> /// <param name="args">The arguments.</param> public override void Process(Commerce.Pipelines.ServicePipelineArgs args) { Assert.ArgumentNotNull(args, "args"); Assert.ArgumentNotNull(args.Request, "args.request"); Assert.ArgumentCondition(args.Request is RefSFArgs.GetSupportedCurrenciesRequest, "args.Request", "args.Request is RefSFArgs.GetSupportedCurrenciesRequest"); Assert.ArgumentCondition(args.Result is GetSupportedCurrenciesResult, "args.Result", "args.Result is GetSupportedCurrenciesResult"); var request = (RefSFArgs.GetSupportedCurrenciesRequest)args.Request; var result = (GetSupportedCurrenciesResult)args.Result; Assert.ArgumentNotNullOrEmpty(request.CatalogName, "request.CatalogName"); ICatalogRepository catalogRepository = CommerceTypeLoader.CreateInstance <ICatalogRepository>(); var catalog = catalogRepository.GetCatalogReadOnly(request.CatalogName); List <string> currencyList = new List <string>(); currencyList.Add(catalog["Currency"].ToString()); if (this._currenciesToInject.Count > 0) { currencyList.AddRange(this._currenciesToInject); } result.Currencies = new System.Collections.ObjectModel.ReadOnlyCollection <string>(currencyList); }
/// <summary> /// Executes the business logic of the TriggerPageEevent processor. /// </summary> /// <param name="args">The arguments.</param> public override void Process(Commerce.Pipelines.ServicePipelineArgs args) { if (Sitecore.Context.Site.DisplayMode != DisplayMode.Normal) { return; } base.Process(args); }
/// <summary> /// Processes the specified arguments. /// </summary> /// <param name="args">The arguments.</param> public override void Process(Commerce.Pipelines.ServicePipelineArgs args) { Assert.ArgumentNotNull(args, "args"); Assert.ArgumentCondition(args.Request is GetShippingOptionsRequest, "args.Request", "args.Request is GetShippingOptionsRequest"); Assert.ArgumentCondition(args.Result is GetShippingOptionsResult, "args.Result", "args.Result is GetShippingOptionsResult"); var request = (GetShippingOptionsRequest)args.Request; var result = (GetShippingOptionsResult)args.Result; List <ShippingOption> availableShippingOptionList = new List <ShippingOption>(); List <ShippingOption> allShippingOptionList = new List <ShippingOption>(); List <ID> filteredList = null; var fulfillmentConfiguration = StorefrontManager.CurrentStorefront.FulfillmentConfiguration; if (fulfillmentConfiguration != null) { MultilistField multiList = fulfillmentConfiguration.Fields[Sitecore.Commerce.Constants.Templates.FulfillmentConfiguration.Fields.FulfillmentOptions]; filteredList = new List <ID>(multiList.TargetIDs); } foreach (Item shippingOptionItem in this.GetShippingOptionsItem().GetChildren()) { bool add = true; if (filteredList != null) { add = filteredList.Exists(p => p == shippingOptionItem.ID); } if (add) { var fulfillmentTypeId = shippingOptionItem[Sitecore.Commerce.Constants.Templates.FulfillmentOption.Fields.FulfillmentOptionType]; ShippingOption option = this.EntityFactory.Create <ShippingOption>("ShippingOption"); var shippingOptionType = Sitecore.Context.Database.GetItem(fulfillmentTypeId); Assert.IsNotNull(shippingOptionType, string.Format(CultureInfo.InvariantCulture, "The Fulfillment Option Type is undefined in Sitecore. ID: {0}", fulfillmentTypeId)); this.TranslateToShippingOption(shippingOptionItem, shippingOptionType, option); add = option.ShippingOptionType == ShippingOptionType.ElectronicDelivery && !CartCanBeEmailed(request.Cart as CommerceCart) ? false : option.ShippingOptionType == ShippingOptionType.DeliverItemsIndividually && request.Cart.Lines.Count <= 1 ? false : true; if (add) { availableShippingOptionList.Add(option); } allShippingOptionList.Add(option); } } result.ShippingOptions = new System.Collections.ObjectModel.ReadOnlyCollection <ShippingOption>(availableShippingOptionList); result.LineShippingPreferences = this.GetLineShippingOptions(request.Cart as CommerceCart, allShippingOptionList).AsReadOnly(); }
/// <summary> /// Processes the specified arguments. /// </summary> /// <param name="args">The arguments.</param> public override void Process(Commerce.Pipelines.ServicePipelineArgs args) { Assert.ArgumentNotNull(args, "args"); Assert.ArgumentCondition(args.Request is CommerceGetPaymentMethodsRequest, "args.Request", "args.Request is CommerceGetPaymentMethodsRequest"); Assert.ArgumentCondition(args.Result is GetPaymentMethodsResult, "args.Result", "args.Result is GetPaymentMethodsResult"); var request = (CommerceGetPaymentMethodsRequest)args.Request; var result = (GetPaymentMethodsResult)args.Result; if (request.PaymentOption.PaymentOptionType == null) { base.Process(args); return; } Item paymentOptionTypesFolder = this.GetPaymentOptionsTypesFolder(); string query = string.Format(CultureInfo.InvariantCulture, "fast:{0}//*[@{1} = '{2}']", paymentOptionTypesFolder.Paths.FullPath, CommerceServerStorefrontConstants.KnownFieldNames.TypeId, request.PaymentOption.PaymentOptionType.Value); Item foundOptionType = paymentOptionTypesFolder.Database.SelectSingleItem(query); if (foundOptionType != null) { Item paymentOptionsItem = this.GetPaymentOptionsItem(); query = string.Format(CultureInfo.InvariantCulture, "fast:{0}//*[@{1} = '{2}']", paymentOptionsItem.Paths.FullPath, CommerceServerStorefrontConstants.KnownFieldNames.PaymentOptionType, foundOptionType.ID); Item paymentOptionItem = paymentOptionsItem.Database.SelectSingleItem(query); if (paymentOptionItem != null) { // Has methods? if (paymentOptionItem.HasChildren) { List <PaymentMethod> returnList = new List <PaymentMethod>(); foreach (Item paymentMethodItem in paymentOptionItem.GetChildren()) { // Do we have a Commerce Server Method? if (paymentMethodItem.HasChildren) { Item csMethod = paymentMethodItem.GetChildren()[0]; string csMethodId = csMethod[StorefrontConstants.KnownFieldNames.MethodId]; Assert.IsNotNullOrEmpty(csMethodId, string.Format(CultureInfo.InvariantCulture, "The CS Method of the {0} Fulfillment Method is empty.", paymentMethodItem.Name)); PaymentMethod shippingMethod = this.EntityFactory.Create <PaymentMethod>("PaymentMethod"); this.TranslatePaymentMethod(paymentOptionItem, paymentMethodItem, csMethodId, shippingMethod); returnList.Add(shippingMethod); } } result.PaymentMethods = new System.Collections.ObjectModel.ReadOnlyCollection <PaymentMethod>(returnList); } } } }
/// <summary> /// Processes the specified arguments. /// </summary> /// <param name="args">The arguments.</param> public override void Process(Commerce.Pipelines.ServicePipelineArgs args) { Assert.ArgumentNotNull(args, "args"); Assert.ArgumentNotNull(args.Request, "args.request"); Assert.ArgumentCondition(args.Request is GetProductBulkPricesRequest, "args.Request", "args.Request is GetProductBulkPricesRequest"); Assert.ArgumentCondition(args.Result is Sitecore.Commerce.Services.Prices.GetProductBulkPricesResult, "args.Result", "args.Result is GetProductBulkPricesResult"); GetProductBulkPricesRequest request = (GetProductBulkPricesRequest)args.Request; Sitecore.Commerce.Services.Prices.GetProductBulkPricesResult result = (Sitecore.Commerce.Services.Prices.GetProductBulkPricesResult)args.Result; Assert.ArgumentNotNull(request.ProductCatalogName, "request.ProductCatalogName"); Assert.ArgumentNotNull(request.ProductIds, "request.ProductIds"); Assert.ArgumentNotNull(request.PriceType, "request.PriceType"); var uniqueIds = request.ProductIds.ToList().Distinct(); var productSearchItemList = this.GetProductsFromIndex(request.ProductCatalogName, uniqueIds); foreach (var productSearchItem in productSearchItemList) { var foundId = uniqueIds.SingleOrDefault(x => x == productSearchItem.Name); if (foundId == null) { continue; } if (productSearchItem != null) { // SOLR returns 0 and not <null> for missing prices. We set the prices to null when 0 value is encountered. decimal?listPrice = !productSearchItem.OtherFields.ContainsKey("listprice") ? (decimal?)null : (productSearchItem.ListPrice == 0 ? (decimal?)null : (decimal)productSearchItem.ListPrice); decimal?adjustedPrice = !productSearchItem.OtherFields.ContainsKey("adjustedprice") ? (decimal?)null : (productSearchItem.AdjustedPrice == 0 ? (decimal?)null : (decimal)productSearchItem.AdjustedPrice); ExtendedCommercePrice extendedPrice = this.EntityFactory.Create <ExtendedCommercePrice>("Price"); if (adjustedPrice.HasValue) { extendedPrice.ListPrice = adjustedPrice.Value; } else { // No base price is defined, the List price is set to the actual ListPrice define in the catalog extendedPrice.ListPrice = (listPrice.HasValue) ? listPrice.Value : 0M; } // The product list price is the Connect "Adjusted" price. if (listPrice.HasValue) { extendedPrice.Amount = listPrice.Value; } result.Prices.Add(foundId, extendedPrice); } } }
/// <summary> /// Gets the page event text. /// </summary> /// <param name="args">The arguments.</param> /// <returns> /// The page event text. /// </returns> protected override string GetPageEventText(Commerce.Pipelines.ServicePipelineArgs args) { var request = args.Request as SearchInitiatedRequest; if (request != null) { return(string.Format(CultureInfo.InvariantCulture, "{0} ({1} results)", request.SearchTerm, request.NumberOfHits)); } else { return(base.GetPageEventText(args)); } }
/// <summary> /// Processes the specified arguments. /// </summary> /// <param name="args">The arguments.</param> public override void Process(Commerce.Pipelines.ServicePipelineArgs args) { base.Process(args); var cartContext = CartPipelineContext.Get(args.Request.RequestContext); Assert.IsNotNullOrEmpty(cartContext.UserId, "cartContext.UserId"); Assert.IsNotNullOrEmpty(cartContext.ShopName, "cartContext.ShopName"); if (cartContext.HasBasketErrors && !args.Result.Success) { args.Result.Success = true; } }
/// <summary> /// Processes the specified arguments. /// </summary> /// <param name="args">The arguments.</param> public override void Process(Commerce.Pipelines.ServicePipelineArgs args) { Assert.ArgumentNotNull(args, "args"); Assert.ArgumentCondition(args.Request is CommerceGetPaymentMethodsRequest, "args.Request", "args.Request is CommerceGetPaymentMethodsRequest"); Assert.ArgumentCondition(args.Result is GetPaymentMethodsResult, "args.Result", "args.Result is GetPaymentMethodsResult"); var request = (CommerceGetPaymentMethodsRequest)args.Request; var result = (GetPaymentMethodsResult)args.Result; if (request.PaymentOption.PaymentOptionType == null) { base.Process(args); return; } Item paymentOptionsItem = this.GetPaymentOptionsItem(); string query = string.Format(CultureInfo.InvariantCulture, "fast:{0}//*[@{1} = '{2}']", paymentOptionsItem.Paths.FullPath, CommerceServerStorefrontConstants.KnownFieldNames.PaymentOptionValue, request.PaymentOption.PaymentOptionType.Value); Item foundOption = paymentOptionsItem.Database.SelectSingleItem(query); if (foundOption != null) { string paymentMethodsIds = foundOption[CommerceServerStorefrontConstants.KnownFieldNames.CommerceServerPaymentMethods]; if (!string.IsNullOrWhiteSpace(paymentMethodsIds)) { base.Process(args); if (result.Success) { List <PaymentMethod> currentList = new List <PaymentMethod>(result.PaymentMethods); List <PaymentMethod> returnList = new List <PaymentMethod>(); string[] ids = paymentMethodsIds.Split('|'); foreach (string id in ids) { string trimmedId = id.Trim(); var found2 = currentList.Find(o => o.ExternalId.Equals(trimmedId, StringComparison.OrdinalIgnoreCase)); PaymentMethod found = currentList.Find(o => o.ExternalId.Equals(trimmedId, StringComparison.OrdinalIgnoreCase)); if (found != null) { returnList.Add(found); } } result.PaymentMethods = new System.Collections.ObjectModel.ReadOnlyCollection <PaymentMethod>(returnList); } } } }
/// <summary> /// Processes the specified arguments. /// </summary> /// <param name="args">The arguments.</param> public override void Process(Commerce.Pipelines.ServicePipelineArgs args) { Assert.ArgumentNotNull(args, "args"); Assert.ArgumentNotNull(args.Request, "args.Request"); Assert.ArgumentCondition(args.Request is RemovePaymentInfoRequest, "args.Request", "args.Request is RemovePaymentInfoRequest"); Assert.ArgumentCondition(args.Result is RemovePaymentInfoResult, "args.Result", "args.Result is RemovePaymentInfoResult"); var request = (RemovePaymentInfoRequest)args.Request; var result = (RemovePaymentInfoResult)args.Result; Assert.ArgumentNotNull(request.Cart, "request.Cart"); Assert.ArgumentNotNullOrEmpty(request.Cart.ExternalId, "request.Cart.ExternalId"); Assert.ArgumentNotNull(request.Payments, "request.Payments"); result.Cart = request.Cart; result.Payments = request.Payments; var paymentMethod = request.Payments.FirstOrDefault(); if (paymentMethod != null) { var paymentInfoModel = new PaymentInfoModel { MethodName = paymentMethod.PaymentMethodID, SystemName = paymentMethod.PaymentProviderID }; using (var client = this.GetClient()) { var response = client.RemovePaymentInfo(new Guid(request.Cart.ExternalId), paymentInfoModel, request.Cart.ShopName); result.Success = response.Success; if (response.Success) { result.Payments = new List <PaymentInfo>(0); result.Cart.Payment = new List <PaymentInfo>(0).AsReadOnly(); } if (!string.IsNullOrEmpty(response.Message)) { result.SystemMessages.Add(new SystemMessage { Message = response.Message }); } } } }
/// <summary> /// Processes the specified arguments. /// </summary> /// <param name="args">The arguments.</param> public override void Process(Commerce.Pipelines.ServicePipelineArgs args) { Assert.ArgumentNotNull(args, "args"); Assert.ArgumentCondition(args.Request is AddPartiesRequest, "args.Request", "args.Request is AddPartiesRequest"); Assert.ArgumentCondition(args.Result is AddPartiesResult, "args.Result", "args.Result is AddPartiesResult"); var request = (AddPartiesRequest)args.Request; var result = (AddPartiesResult)args.Result; Assert.ArgumentNotNull(request.Parties, "request.Parties"); Assert.ArgumentNotNull(request.CommerceCustomer, "request.CommerceCustomer"); Profile customerProfile = null; var response = this.GetCommerceUserProfile(request.CommerceCustomer.ExternalId, ref customerProfile); if (!response.Success) { result.Success = false; response.SystemMessages.ToList().ForEach(m => result.SystemMessages.Add(m)); return; } List <Party> partiesAdded = new List <Party>(); foreach (Party party in request.Parties) { if (party == null) { continue; } Party newParty = null; if (party is CommerceParty) { newParty = this.ProcessCommerceParty(result, customerProfile, party as CommerceParty); } else { newParty = this.ProcessCustomParty(result, customerProfile, party); } if (newParty != null) { partiesAdded.Add(newParty); } } }
/// <summary> /// Gets the page event data. /// </summary> /// <param name="args">The arguments.</param> /// <returns> /// The page event data. /// </returns> protected override Dictionary <string, object> GetPageEventData(Commerce.Pipelines.ServicePipelineArgs args) { Assert.ArgumentNotNull(args, "args"); var data = base.GetPageEventData(args) ?? new Dictionary <string, object>(); var request = args.Request as SearchInitiatedRequest; if (request != null) { data.Add(StorefrontConstants.PageEventDataNames.ShopName, request.ShopName); data.Add(StorefrontConstants.PageEventDataNames.SearchTerm, request.SearchTerm ?? string.Empty); data.Add(StorefrontConstants.PageEventDataNames.NumberOfHits, request.NumberOfHits); } return(data); }
/// <summary> /// Processes the specified arguments. /// </summary> /// <param name="args">The arguments.</param> public override void Process(Commerce.Pipelines.ServicePipelineArgs args) { Assert.ArgumentNotNull(args, "args"); Assert.ArgumentCondition(args.Request is GetAvailableCountriesRequest, "args.Request", "args.Request is GetAvailableCountriesRequest"); Assert.ArgumentCondition(args.Result is GetAvailableCountriesResult, "args.Result", "args.Result is GetAvailableCountriesResult"); var request = (GetAvailableCountriesRequest)args.Request; var result = (GetAvailableCountriesResult)args.Result; var countryDictionary = new Dictionary <string, string>(); foreach (Item country in this.GetCountryAndRegionItem().GetChildren()) { countryDictionary.Add(country[Sitecore.Commerce.Constants.Templates.CountryRegion.Fields.CountryCode], country[Sitecore.Commerce.Constants.Templates.CountryRegion.Fields.Name]); } result.AvailableCountries = countryDictionary; }
/// <summary> /// Processes the specified arguments. /// </summary> /// <param name="args">The arguments.</param> public override void Process(Commerce.Pipelines.ServicePipelineArgs args) { base.Process(args); GetUserRequest request = (GetUserRequest)args.Request; GetUserResult result = (GetUserResult)args.Result; if (result.CommerceUser == null) { return; } // if we found a user, add some addition info var userProfile = GetUserProfile(result.CommerceUser.UserName); Assert.IsNotNull(userProfile, "profile"); UpdateCustomer(result.CommerceUser, userProfile); }
/// <summary> /// Processes the specified arguments. /// </summary> /// <param name="args">The arguments.</param> public override void Process(Commerce.Pipelines.ServicePipelineArgs args) { Assert.ArgumentNotNull(args, "args"); Assert.ArgumentNotNull(args.Request, "args.request"); Assert.ArgumentNotNull(args.Result, "args.result"); Assert.ArgumentCondition(args.Request is TranslateEntityToCommerceAddressProfileRequest, "args.Request ", "args.Request is TranslateEntityToCommerceAddressProfileRequest"); var request = (TranslateEntityToCommerceAddressProfileRequest)args.Request; Assert.ArgumentNotNull(request.SourceParty, "request.SourceParty"); Assert.ArgumentNotNull(request.DestinationProfile, "request.DestinationProfile"); if (request.SourceParty is CommerceParty) { this.TranslateCommerceCustomerParty(request.SourceParty as CommerceParty, request.DestinationProfile); } else { this.TranslateCustomParty(request.SourceParty, request.DestinationProfile); } }
/// <summary> /// Processes the specified arguments. /// </summary> /// <param name="args">The arguments.</param> public override void Process(Commerce.Pipelines.ServicePipelineArgs args) { Assert.ArgumentNotNull(args, "args"); Assert.ArgumentCondition(args.Request is GetPaymentOptionsRequest, "args.Request", "args.Request is GetPaymentOptionsRequest"); Assert.ArgumentCondition(args.Result is GetPaymentOptionsResult, "args.Result", "args.Result is GetPaymentOptionsResult"); var request = (GetPaymentOptionsRequest)args.Request; var result = (GetPaymentOptionsResult)args.Result; List <ID> filteredList = null; var paymentConfiguration = StorefrontManager.CurrentStorefront.PaymentConfiguration; if (paymentConfiguration != null) { MultilistField multiList = paymentConfiguration.Fields[Sitecore.Commerce.Constants.Templates.PaymentConfiguration.Fields.PaymentOptions]; filteredList = new List <ID>(multiList.TargetIDs); } List <PaymentOption> paymentOptionList = new List <PaymentOption>(); foreach (Item paymentOptionItem in this.GetPaymentOptionsItem().GetChildren()) { bool add = true; if (filteredList != null) { add = filteredList.Exists(p => p == paymentOptionItem.ID); } if (add) { PaymentOption option = this.EntityFactory.Create <PaymentOption>("PaymentOption"); this.TranslateToPaymentOption(paymentOptionItem, option, result); paymentOptionList.Add(option); } } result.PaymentOptions = new System.Collections.ObjectModel.ReadOnlyCollection <PaymentOption>(paymentOptionList); }
/// <summary> /// Processes the specified arguments. /// </summary> /// <param name="args">The arguments.</param> public override void Process(Commerce.Pipelines.ServicePipelineArgs args) { Assert.ArgumentNotNull(args, "args"); Assert.ArgumentCondition(args.Request is GetPaymentOptionsRequest, "args.Request", "args.Request is GetPaymentOptionsRequest"); Assert.ArgumentCondition(args.Result is GetPaymentOptionsResult, "args.Result", "args.Result is GetPaymentOptionsResult"); var request = (GetPaymentOptionsRequest)args.Request; var result = (GetPaymentOptionsResult)args.Result; List <PaymentOption> paymentOptionList = new List <PaymentOption>(); foreach (Item paymentOptionItem in this.GetPaymentOptionsItem().GetChildren()) { PaymentOption option = this.EntityFactory.Create <PaymentOption>("PaymentOption"); this.TranslateToPaymentOption(paymentOptionItem, option, result); paymentOptionList.Add(option); } result.PaymentOptions = new System.Collections.ObjectModel.ReadOnlyCollection <PaymentOption>(paymentOptionList); }
/// <summary> /// Processes the specified arguments. /// </summary> /// <param name="args">The arguments.</param> public override void Process(Commerce.Pipelines.ServicePipelineArgs args) { Assert.ArgumentNotNull(args, "args"); Assert.ArgumentCondition(args.Request is GetPartiesRequest, "args.Request", "args.Request is GetPartiesRequest"); Assert.ArgumentCondition(args.Result is GetPartiesResult, "args.Result", "args.Result is GetPartiesResult"); var request = (GetPartiesRequest)args.Request; var result = (GetPartiesResult)args.Result; Assert.ArgumentNotNull(request.CommerceCustomer, "request.CommerceCustomer"); List <Party> partyList = new List <Party>(); Profile customerProfile = null; var response = this.GetCommerceUserProfile(request.CommerceCustomer.ExternalId, ref customerProfile); if (!response.Success) { result.Success = false; response.SystemMessages.ToList().ForEach(m => result.SystemMessages.Add(m)); return; } string preferredAddress = customerProfile["GeneralInfo.preferred_address"].Value as string; var profileValue = customerProfile["GeneralInfo.address_list"].Value as object[]; if (profileValue != null) { var e = profileValue.Select(i => i.ToString()); ProfilePropertyListCollection <string> addresIdsList = new ProfilePropertyListCollection <string>(e); if (addresIdsList != null) { foreach (string addressId in addresIdsList) { Profile commerceAddress = null; response = this.GetCommerceAddressProfile(addressId, ref commerceAddress); if (!response.Success) { result.Success = false; response.SystemMessages.ToList().ForEach(m => result.SystemMessages.Add(m)); return; } var newParty = this.EntityFactory.Create <CommerceParty>("Party"); var requestTorequestToEntity = new TranslateCommerceAddressProfileToEntityRequest(commerceAddress, newParty); PipelineUtility.RunCommerceConnectPipeline <TranslateCommerceAddressProfileToEntityRequest, CommerceResult>(CommerceServerStorefrontConstants.PipelineNames.TranslateCommerceAddressProfileToEntity, requestTorequestToEntity); if (!string.IsNullOrWhiteSpace(preferredAddress) && preferredAddress.Equals(newParty.ExternalId, System.StringComparison.OrdinalIgnoreCase)) { newParty.IsPrimary = true; } var address = requestTorequestToEntity.DestinationParty; partyList.Add(address); } } } result.Parties = partyList.AsReadOnly(); }
/// <summary> /// Processes the specified arguments. /// </summary> /// <param name="args">The arguments.</param> public override void Process(Commerce.Pipelines.ServicePipelineArgs args) { Assert.ArgumentNotNull(args, "args"); Assert.ArgumentCondition(args.Request is UpdatePartiesRequest, "args.Request", "args.Request is UpdatePartiesRequest"); Assert.ArgumentCondition(args.Result is CustomerResult, "args.Result", "args.Result is CustomerResult"); var request = (UpdatePartiesRequest)args.Request; var result = (CustomerResult)args.Result; Profile customerProfile = null; var response = this.GetCommerceUserProfile(request.CommerceCustomer.ExternalId, ref customerProfile); if (!response.Success) { result.Success = false; response.SystemMessages.ToList().ForEach(m => result.SystemMessages.Add(m)); return; } string preferredAddress = customerProfile["GeneralInfo.preferred_address"].Value as string; var profileValue = customerProfile["GeneralInfo.address_list"].Value as object[]; if (profileValue != null) { var e = profileValue.Select(i => i.ToString()); var addressList = new ProfilePropertyListCollection <string>(e); foreach (var partyToUpdate in request.Parties) { Assert.IsTrue(partyToUpdate is CommerceParty, "partyToUpdate is CommerceParty"); var foundId = addressList.Where(x => x.Equals(partyToUpdate.ExternalId, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); if (foundId != null) { Profile commerceAddress = null; response = this.GetCommerceAddressProfile(foundId, ref commerceAddress); if (!response.Success) { result.Success = false; response.SystemMessages.ToList().ForEach(m => result.SystemMessages.Add(m)); return; } // Check if the IsPrimary address flag has been flipped. if (((CommerceParty)partyToUpdate).IsPrimary) { customerProfile["GeneralInfo.preferred_address"].Value = partyToUpdate.ExternalId; customerProfile.Update(); } else if (!string.IsNullOrWhiteSpace(preferredAddress) && preferredAddress.Equals(partyToUpdate.ExternalId, StringComparison.OrdinalIgnoreCase)) { customerProfile["GeneralInfo.preferred_address"].Value = System.DBNull.Value; customerProfile.Update(); } var translateToEntityRequest = new TranslateEntityToCommerceAddressProfileRequest((CommerceParty)partyToUpdate, commerceAddress); PipelineUtility.RunCommerceConnectPipeline <TranslateEntityToCommerceAddressProfileRequest, CommerceResult>(CommerceServerStorefrontConstants.PipelineNames.TranslateEntityToCommerceAddressProfile, translateToEntityRequest); commerceAddress.Update(); } } } }
/// <summary> /// Processes the specified arguments. /// </summary> /// <param name="args">The arguments.</param> public override void Process(Commerce.Pipelines.ServicePipelineArgs args) { Assert.ArgumentNotNull(args, "args"); Assert.ArgumentNotNull(args.Request, "args.request"); Assert.ArgumentCondition(args.Request is GetProductPricesRequest, "args.Request", "args.Request is GetProductPricesRequest"); Assert.ArgumentCondition(args.Result is Sitecore.Commerce.Services.Prices.GetProductPricesResult, "args.Result", "args.Result is GetProductPricesResult"); GetProductPricesRequest request = (GetProductPricesRequest)args.Request; Sitecore.Commerce.Services.Prices.GetProductPricesResult result = (Sitecore.Commerce.Services.Prices.GetProductPricesResult)args.Result; Assert.ArgumentNotNull(request.ProductCatalogName, "request.ProductCatalogName"); Assert.ArgumentNotNull(request.ProductId, "request.ProductId"); Assert.ArgumentNotNull(request.PriceTypeIds, "request.PriceTypeIds"); ICatalogRepository catalogRepository = ContextTypeLoader.CreateInstance <ICatalogRepository>(); bool isList = request.PriceTypeIds.FirstOrDefault(x => x.Equals(PriceTypes.List, StringComparison.OrdinalIgnoreCase)) != null; bool isAdjusted = request.PriceTypeIds.FirstOrDefault(x => x.Equals(PriceTypes.Adjusted, StringComparison.OrdinalIgnoreCase)) != null; try { var product = catalogRepository.GetProductReadOnly(request.ProductCatalogName, request.ProductId); ExtendedCommercePrice extendedPrice = this.EntityFactory.Create <ExtendedCommercePrice>("Price"); // BasePrice is a List price and ListPrice is Adjusted price if (isList) { if (product.HasProperty("BasePrice") && product["BasePrice"] != null) { extendedPrice.Amount = (product["BasePrice"] as decimal?).Value; } else { // No base price is defined, the List price is set to the actual ListPrice define in the catalog extendedPrice.Amount = product.ListPrice; } } if (isAdjusted && !product.IsListPriceNull()) { extendedPrice.ListPrice = product.ListPrice; } result.Prices.Add(request.ProductId, extendedPrice); if (request.IncludeVariantPrices && product is ProductFamily) { foreach (Variant variant in ((ProductFamily)product).Variants) { ExtendedCommercePrice variantExtendedPrice = this.EntityFactory.Create <ExtendedCommercePrice>("Price"); bool hasBasePrice = product.HasProperty("BasePrice"); if (hasBasePrice && variant["BasePriceVariant"] != null) { variantExtendedPrice.Amount = (variant["BasePriceVariant"] as decimal?).Value; } if (!variant.IsListPriceNull()) { variantExtendedPrice.ListPrice = variant.ListPrice; if (!hasBasePrice) { variantExtendedPrice.Amount = variant.ListPrice; } } result.Prices.Add(variant.VariantId.Trim(), variantExtendedPrice); } } } catch (EntityDoesNotExistException e) { result.Success = false; result.SystemMessages.Add(new SystemMessage { Message = e.Message }); } }
/// <summary> /// Processes the specified arguments. /// </summary> /// <param name="args">The arguments.</param> public override void Process(Commerce.Pipelines.ServicePipelineArgs args) { Assert.ArgumentNotNull(args, "args"); Assert.ArgumentNotNull(args.Request, "args.request"); Assert.ArgumentCondition(args.Request is GetProductPricesRequest, "args.Request", "args.Request is GetProductPricesRequest"); Assert.ArgumentCondition(args.Result is GetProductPricesResult, "args.Result", "args.Result is GetProductPricesResult"); GetProductPricesRequest request = (GetProductPricesRequest)args.Request; GetProductPricesResult result = (GetProductPricesResult)args.Result; Assert.ArgumentNotNull(request.ProductCatalogName, "request.ProductCatalogName"); Assert.ArgumentNotNull(request.ProductId, "request.ProductId"); Assert.ArgumentNotNull(request.PriceTypeIds, "request.PriceTypeIds"); ICatalogRepository catalogRepository = CommerceTypeLoader.CreateInstance <ICatalogRepository>(); bool isList = Array.FindIndex(request.PriceTypeIds as string[], t => t.IndexOf("List", StringComparison.OrdinalIgnoreCase) >= 0) > -1; bool isAdjusted = Array.FindIndex(request.PriceTypeIds as string[], t => t.IndexOf("Adjusted", StringComparison.OrdinalIgnoreCase) >= 0) > -1; try { var product = catalogRepository.GetProductReadOnly(request.ProductCatalogName, request.ProductId); Dictionary <string, Price> prices = new Dictionary <string, Price>(); // BasePrice is a List price and ListPrice is Adjusted price if (isList) { if (product.HasProperty("BasePrice") && product["BasePrice"] != null) { prices.Add("List", new Price { PriceType = "List", Amount = (product["BasePrice"] as decimal?).Value }); } else { // No base price is defined, the List price is set to the actual ListPrice define in the catalog prices.Add("List", new Price { PriceType = "List", Amount = product.ListPrice }); } } if (isAdjusted && !product.IsListPriceNull()) { prices.Add("Adjusted", new Price { PriceType = "Adjusted", Amount = product.ListPrice }); } result.Prices.Add(request.ProductId, prices); if (request.IncludeVariantPrices && product is ProductFamily) { foreach (Variant variant in ((ProductFamily)product).Variants) { Dictionary <string, Price> variantPrices = new Dictionary <string, Price>(); if (isList && product.HasProperty("BasePrice") && variant["BasePriceVariant"] != null) { variantPrices.Add("List", new Price { PriceType = "List", Amount = (variant["BasePriceVariant"] as decimal?).Value }); } if (isAdjusted && !variant.IsListPriceNull()) { variantPrices.Add("Adjusted", new Price { PriceType = "Adjusted", Amount = variant.ListPrice }); } result.Prices.Add(variant.VariantId, variantPrices); } } } catch (CommerceServer.Core.EntityDoesNotExistException e) { result.Success = false; result.SystemMessages.Add(new SystemMessage { Message = e.Message }); } }
/// <summary> /// Processes the specified arguments. /// </summary> /// <param name="args">The arguments.</param> public override void Process(Commerce.Pipelines.ServicePipelineArgs args) { Assert.ArgumentNotNull(args, "args"); Assert.ArgumentCondition(args.Request is RemovePartiesRequest, "args.Request", "args.Request is RemovePartiesRequest"); Assert.ArgumentCondition(args.Result is CustomerResult, "args.Result", "args.Result is CustomerResult"); var request = (RemovePartiesRequest)args.Request; var result = (CustomerResult)args.Result; Profile customerProfile = null; var response = this.GetCommerceUserProfile(request.CommerceCustomer.ExternalId, ref customerProfile); if (!response.Success) { result.Success = false; response.SystemMessages.ToList().ForEach(m => result.SystemMessages.Add(m)); return; } string preferredAddress = customerProfile["GeneralInfo.preferred_address"].Value as string; var profileValue = customerProfile["GeneralInfo.address_list"].Value as object[]; if (profileValue != null) { var e = profileValue.Select(i => i.ToString()); var addressList = new ProfilePropertyListCollection <string>(e); foreach (var partyToRemove in request.Parties) { var foundId = addressList.Where(x => x.Equals(partyToRemove.ExternalId, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); if (foundId != null) { response = this.DeleteAddressCommerceProfile(foundId); if (!response.Success) { result.Success = false; response.SystemMessages.ToList().ForEach(m => result.SystemMessages.Add(m)); return; } addressList.Remove(foundId); if (addressList.Count() == 0) { customerProfile["GeneralInfo.address_list"].Value = System.DBNull.Value; } else { customerProfile["GeneralInfo.address_list"].Value = addressList.Cast <object>().ToArray(); } // Preffered address check. If the address being deleted was the preferred address we must clear it from the customer profile. if (!string.IsNullOrWhiteSpace(preferredAddress) && preferredAddress.Equals(partyToRemove.ExternalId, StringComparison.OrdinalIgnoreCase)) { customerProfile["GeneralInfo.preferred_address"].Value = System.DBNull.Value; } customerProfile.Update(); } } } }
/// <summary> /// Processes the specified arguments. /// </summary> /// <param name="args">The arguments.</param> public override void Process(Commerce.Pipelines.ServicePipelineArgs args) { Assert.ArgumentNotNull(args, "args"); Assert.ArgumentNotNull(args.Request, "args.request"); Assert.ArgumentCondition(args.Request is GetProductBulkPricesRequest, "args.Request", "args.Request is GetProductBulkPricesRequest"); Assert.ArgumentCondition(args.Result is Sitecore.Commerce.Services.Prices.GetProductBulkPricesResult, "args.Result", "args.Result is GetProductBulkPricesResult"); GetProductBulkPricesRequest request = (GetProductBulkPricesRequest)args.Request; Sitecore.Commerce.Services.Prices.GetProductBulkPricesResult result = (Sitecore.Commerce.Services.Prices.GetProductBulkPricesResult)args.Result; Assert.ArgumentNotNull(request.ProductCatalogName, "request.ProductCatalogName"); Assert.ArgumentNotNull(request.ProductIds, "request.ProductIds"); Assert.ArgumentNotNull(request.PriceType, "request.PriceType"); ICatalogRepository catalogRepository = ContextTypeLoader.CreateInstance <ICatalogRepository>(); bool isList = request.PriceTypeIds.FirstOrDefault(x => x.Equals(PriceTypes.List, StringComparison.OrdinalIgnoreCase)) != null; bool isAdjusted = request.PriceTypeIds.FirstOrDefault(x => x.Equals(PriceTypes.Adjusted, StringComparison.OrdinalIgnoreCase)) != null; bool isLowestPriceVariantSpecified = request.PriceTypeIds.FirstOrDefault(x => x.Equals(PriceTypes.LowestPricedVariant, StringComparison.OrdinalIgnoreCase)) != null; bool isLowestPriceVariantListPriceSpecified = request.PriceTypeIds.FirstOrDefault(x => x.Equals(PriceTypes.LowestPricedVariantListPrice, StringComparison.OrdinalIgnoreCase)) != null; bool isHighestPriceVariantSpecified = request.PriceTypeIds.FirstOrDefault(x => x.Equals(PriceTypes.HighestPricedVariant, StringComparison.OrdinalIgnoreCase)) != null; var uniqueIds = request.ProductIds.ToList().Distinct(); foreach (var requestedProductId in uniqueIds) { try { var product = catalogRepository.GetProductReadOnly(request.ProductCatalogName, requestedProductId); ExtendedCommercePrice extendedPrice = this.EntityFactory.Create <ExtendedCommercePrice>("Price"); // BasePrice is a List price and ListPrice is Adjusted price if (isList) { if (product.HasProperty("BasePrice") && product["BasePrice"] != null) { extendedPrice.Amount = (product["BasePrice"] as decimal?).Value; } else { // No base price is defined, the List price is set to the actual ListPrice define in the catalog extendedPrice.Amount = product.ListPrice; } } if (isAdjusted && !product.IsListPriceNull()) { extendedPrice.ListPrice = product.ListPrice; } if ((isLowestPriceVariantSpecified || isLowestPriceVariantListPriceSpecified || isHighestPriceVariantSpecified) && product is ProductFamily) { this.SetVariantPrices(product as ProductFamily, extendedPrice, isLowestPriceVariantSpecified, isLowestPriceVariantListPriceSpecified, isHighestPriceVariantSpecified); } result.Prices.Add(requestedProductId, extendedPrice); } catch (EntityDoesNotExistException e) { result.Success = false; result.SystemMessages.Add(new SystemMessage { Message = e.Message }); continue; } } }
/// <summary> /// Processes the specified arguments. /// </summary> /// <param name="args">The arguments.</param> public override void Process(Commerce.Pipelines.ServicePipelineArgs args) { Assert.ArgumentNotNull(args, "args"); Assert.ArgumentNotNull(args.Request, "args.request"); Assert.ArgumentCondition(args.Request is GetProductBulkPricesRequest, "args.Request", "args.Request is GetProductBulkPricesRequest"); Assert.ArgumentCondition(args.Result is Sitecore.Commerce.Services.Prices.GetProductBulkPricesResult, "args.Result", "args.Result is GetProductBulkPricesResult"); GetProductBulkPricesRequest request = (GetProductBulkPricesRequest)args.Request; Sitecore.Commerce.Services.Prices.GetProductBulkPricesResult result = (Sitecore.Commerce.Services.Prices.GetProductBulkPricesResult)args.Result; Assert.ArgumentNotNull(request.ProductCatalogName, "request.ProductCatalogName"); Assert.ArgumentNotNull(request.ProductIds, "request.ProductIds"); Assert.ArgumentNotNull(request.PriceType, "request.PriceType"); bool isList = request.PriceTypeIds.FirstOrDefault(x => x.Equals(PriceTypes.List, StringComparison.OrdinalIgnoreCase)) != null; bool isAdjusted = request.PriceTypeIds.FirstOrDefault(x => x.Equals(PriceTypes.Adjusted, StringComparison.OrdinalIgnoreCase)) != null; bool isLowestPriceVariantSpecified = request.PriceTypeIds.FirstOrDefault(x => x.Equals(PriceTypes.LowestPricedVariant, StringComparison.OrdinalIgnoreCase)) != null; bool isLowestPriceVariantListPriceSpecified = request.PriceTypeIds.FirstOrDefault(x => x.Equals(PriceTypes.LowestPricedVariantListPrice, StringComparison.OrdinalIgnoreCase)) != null; bool isHighestPriceVariantSpecified = request.PriceTypeIds.FirstOrDefault(x => x.Equals(PriceTypes.HighestPricedVariant, StringComparison.OrdinalIgnoreCase)) != null; var uniqueIds = request.ProductIds.ToList().Distinct(); var productSearchItemList = this.GetProductsFromIndex(request.ProductCatalogName, uniqueIds); foreach (var productSearchItem in productSearchItemList) { var foundId = uniqueIds.SingleOrDefault(x => x == productSearchItem.Name); if (foundId == null) { continue; } if (productSearchItem != null) { // SOLR returns 0 and not <null> for missing prices. We set the prices to null when 0 value is encountered. decimal?listPrice = !productSearchItem.OtherFields.ContainsKey("listprice") ? (decimal?)null : ((decimal)productSearchItem.ListPrice == 0M ? (decimal?)null : (decimal)productSearchItem.ListPrice); decimal?basePrice = !productSearchItem.OtherFields.ContainsKey("baseprice") ? (decimal?)null : ((decimal)productSearchItem.BasePrice == 0M ? (decimal?)null : (decimal)productSearchItem.BasePrice); ExtendedCommercePrice extendedPrice = this.EntityFactory.Create <ExtendedCommercePrice>("Price"); // The product base price is the Connect "List" price. if (isList) { if (basePrice.HasValue) { extendedPrice.Amount = basePrice.Value; } else { // No base price is defined, the List price is set to the actual ListPrice define in the catalog extendedPrice.Amount = (listPrice.HasValue) ? listPrice.Value : 0M; } } // The product list price is the Connect "Adjusted" price. if (isAdjusted && listPrice.HasValue) { extendedPrice.ListPrice = listPrice.Value; } var variantInfoString = productSearchItem.VariantInfo; if ((isLowestPriceVariantSpecified || isLowestPriceVariantListPriceSpecified || isHighestPriceVariantSpecified) && !string.IsNullOrWhiteSpace(variantInfoString)) { List <VariantIndexInfo> variantIndexInfoList = JsonConvert.DeserializeObject <List <VariantIndexInfo> >(variantInfoString); this.SetVariantPricesFromProductVariants(productSearchItem, variantIndexInfoList, extendedPrice, isLowestPriceVariantSpecified, isLowestPriceVariantListPriceSpecified, isHighestPriceVariantSpecified); } result.Prices.Add(foundId, extendedPrice); } } }
/// <summary> /// Processes the specified args. /// </summary> /// <param name="args">The args.</param> public override void Process([NotNull] Commerce.Pipelines.ServicePipelineArgs args) { Assert.ArgumentNotNull(args, "args"); var request = (GetShippingMethodsRequest)args.Request; var result = (GetShippingMethodsResult)args.Result; using (var client = this.GetClient()) { try { AddressModel addressModel = null; if (request.Party != null) { addressModel = new AddressModel { Id = request.Party.ExternalId, FirstName = request.Party.FirstName, LastName = request.Party.LastName, Email = request.Party.Email, Address1 = request.Party.Address1, Address2 = request.Party.Address2, City = request.Party.City, Company = request.Party.Company, CountryThreeLetterIsoCode = request.Party.Country, //TODO: make sure it is threee letter code CountryTwoLetterIsoCode = string.Empty, FaxNumber = string.Empty, PhoneNumber = request.Party.PhoneNumber, StateProvinceAbbreviation = request.Party.State, ZipPostalCode = request.Party.ZipPostalCode }; } var cart = (Cart)request.Properties["cart"]; //TODO: Change 'new ShoppingCartModel()'. Map request.Cart to ShoppingCartModel var response = client.GetShippingMethods(new ShoppingCartModel { CustomerGuid = new Guid(cart.ExternalId) }, request.ShippingOption.ShopName, addressModel); result.Success = response.Success; var shippinMethods = new List <ShippingMethod>(0); foreach (var shippingMethodModel in response.Result) { if (this.MappingCollectin.Contains(Tuple.Create(request.ShippingOption.ShippingOptionType.Value, shippingMethodModel.SystemName, shippingMethodModel.Name))) { shippinMethods.Add(new ShippingMethod() { Name = shippingMethodModel.Name, Description = shippingMethodModel.Description, ExternalId = shippingMethodModel.SystemName }); } } result.ShippingMethods = shippinMethods.AsReadOnly(); if (!string.IsNullOrEmpty(response.Message)) { result.SystemMessages.Add(new SystemMessage() { Message = response.Message }); } } catch (Exception e) { result.Success = false; result.SystemMessages.Add(new SystemMessage() { Message = e.Message }); } } }
/// <summary> /// Processes the specified arguments. /// </summary> /// <param name="args">The arguments.</param> public override void Process(Commerce.Pipelines.ServicePipelineArgs args) { Assert.ArgumentNotNull(args, "args"); Assert.ArgumentCondition(args.Request is CommerceGetShippingMethodsRequest, "args.Request", "args.Request is CommerceGetShippingMethodsRequest"); Assert.ArgumentCondition(args.Result is GetShippingMethodsResult, "args.Result", "args.Result is GetShippingMethodsResult"); var request = (CommerceGetShippingMethodsRequest)args.Request; var result = (GetShippingMethodsResult)args.Result; Assert.ArgumentNotNullOrEmpty(request.Language, "request.Language"); if (request.ShippingOption.ShippingOptionType == null) { base.Process(args); return; } Item shippingOptionsItem = this.GetShippingOptionsItem(); string query = string.Format(CultureInfo.InvariantCulture, "fast:{0}//*[@{1} = '{2}']", shippingOptionsItem.Paths.FullPath, CommerceServerStorefrontConstants.KnownFieldNames.ShippingOptionValue, request.ShippingOption.ShippingOptionType.Value); Item foundOption = shippingOptionsItem.Database.SelectSingleItem(query); if (foundOption != null) { string shippingMethodsIds = foundOption[CommerceServerStorefrontConstants.KnownFieldNames.CommerceServerShippingMethods]; if (!string.IsNullOrWhiteSpace(shippingMethodsIds)) { base.Process(args); if (result.Success) { List <ShippingMethod> currentList = new List <ShippingMethod>(result.ShippingMethods); List <ShippingMethod> returnList = new List <ShippingMethod>(); string[] ids = shippingMethodsIds.Split('|'); foreach (string id in ids) { string trimmedId = id.Trim(); var found2 = currentList.Find(o => o.ExternalId.Equals(trimmedId, StringComparison.OrdinalIgnoreCase)); ShippingMethod found = currentList.Find(o => o.ExternalId.Equals(trimmedId, StringComparison.OrdinalIgnoreCase)) as ShippingMethod; if (found != null) { returnList.Add(found); } } result.ShippingMethods = new System.Collections.ObjectModel.ReadOnlyCollection <ShippingMethod>(returnList); } } // We need to do this type casting for now until the base OBEC classes support the additional properties. Setting the shipping // methods calls this pipeline processor for validation purposes (call is made by CS integration) and we must allow to be called using // the original CS integration classes. if (request is Sitecore.Foundation.CommerceServer.Helpers.GetShippingMethodsRequest && result is GetShippingMethodsResult) { var obecRequest = (Sitecore.Foundation.CommerceServer.Helpers.GetShippingMethodsRequest)request; var obecResult = (GetShippingMethodsResult)result; if (obecRequest.Lines != null && obecRequest.Lines.Any()) { var shippingMethodPerItemList = new List <ShippingMethodPerItem>(); foreach (var line in obecRequest.Lines) { var shippingMethodPerItem = new ShippingMethodPerItem(); shippingMethodPerItem.LineId = line.ExternalCartLineId; shippingMethodPerItem.ShippingMethods = result.ShippingMethods; shippingMethodPerItemList.Add(shippingMethodPerItem); } obecResult.ShippingMethodsPerItem = new System.Collections.ObjectModel.ReadOnlyCollection <ShippingMethodPerItem>(shippingMethodPerItemList); } } } }
/// <summary> /// Processes the specified arguments. /// </summary> /// <param name="args">The arguments.</param> public override void Process(Commerce.Pipelines.ServicePipelineArgs args) { Assert.ArgumentNotNull(args, "args"); Assert.ArgumentCondition(args.Request is CommerceGetShippingMethodsRequest, "args.Request", "args.Request is CommerceGetShippingMethodsRequest"); Assert.ArgumentCondition(args.Result is GetShippingMethodsResult, "args.Result", "args.Result is GetShippingMethodsResult"); var request = (CommerceGetShippingMethodsRequest)args.Request; var result = (GetShippingMethodsResult)args.Result; Assert.ArgumentNotNullOrEmpty(request.Language, "request.Language"); if (request.ShippingOption.ShippingOptionType == null) { base.Process(args); return; } Item shippingOptionTypesFolder = this.GetShippingOptionsTypeFolder(); string query = string.Format(CultureInfo.InvariantCulture, "fast:{0}//*[@{1} = '{2}']", shippingOptionTypesFolder.Paths.FullPath, CommerceServerStorefrontConstants.KnownFieldNames.TypeId, request.ShippingOption.ShippingOptionType.Value); Item foundOptionType = shippingOptionTypesFolder.Database.SelectSingleItem(query); if (foundOptionType != null) { Item shippingOptionsItem = this.GetShippingOptionsItem(); query = string.Format(CultureInfo.InvariantCulture, "fast:{0}//*[@{1} = '{2}']", shippingOptionsItem.Paths.FullPath, CommerceServerStorefrontConstants.KnownFieldNames.FulfillmentOptionType, foundOptionType.ID); Item fulfillmentOptionItem = shippingOptionsItem.Database.SelectSingleItem(query); if (fulfillmentOptionItem != null) { // Has methods? if (fulfillmentOptionItem.HasChildren) { List <ShippingMethod> returnList = new List <ShippingMethod>(); foreach (Item fulfillmentMethodItem in fulfillmentOptionItem.GetChildren()) { // Do we have a Commerce Server Method? if (fulfillmentMethodItem.HasChildren) { Item csMethod = fulfillmentMethodItem.GetChildren()[0]; string csMethodId = csMethod[StorefrontConstants.KnownFieldNames.MethodId]; Assert.IsNotNullOrEmpty(csMethodId, string.Format(CultureInfo.InvariantCulture, "The CS Method of the {0} Fulfillment Method is empty.", fulfillmentMethodItem.Name)); ShippingMethod shippingMethod = this.EntityFactory.Create <ShippingMethod>("ShippingMethod"); this.TranslateShippingMethod(fulfillmentOptionItem, fulfillmentMethodItem, csMethodId, shippingMethod); returnList.Add(shippingMethod); } } result.ShippingMethods = new System.Collections.ObjectModel.ReadOnlyCollection <ShippingMethod>(returnList); // We need to do this type casting for now until the base OBEC classes support the additional properties. Setting the shipping // methods calls this pipeline processor for validation purposes (call is made by CS integration) and we must allow to be called using // the original CS integration classes. if (request is Services.Orders.GetShippingMethodsRequest && result is GetShippingMethodsResult) { var obecRequest = (Services.Orders.GetShippingMethodsRequest)request; var obecResult = (GetShippingMethodsResult)result; if (obecRequest.Lines != null && obecRequest.Lines.Any()) { var shippingMethodPerItemList = new List <ShippingMethodPerItem>(); foreach (var line in obecRequest.Lines) { var shippingMethodPerItem = new ShippingMethodPerItem(); shippingMethodPerItem.LineId = line.ExternalCartLineId; shippingMethodPerItem.ShippingMethods = result.ShippingMethods; shippingMethodPerItemList.Add(shippingMethodPerItem); } obecResult.ShippingMethodsPerItem = new System.Collections.ObjectModel.ReadOnlyCollection <ShippingMethodPerItem>(shippingMethodPerItemList); } } } } } }