protected List <WishListLine> TranslateLines(Cart source, WishList destination) { List <WishListLine> resultWishlist = new List <WishListLine>(); if (source.Lines != null) { foreach (var lineItem in source.Lines) { var wishListLine = new WishListLine { ExternalId = lineItem.Id, Product = new CartProduct() }; if (lineItem.CartLineComponents != null && !string.IsNullOrEmpty(lineItem.ItemId)) { CartProductComponent productComponent = lineItem.CartLineComponents.OfType <CartProductComponent>().FirstOrDefault(); var product = new CommerceCartProduct(); if (productComponent != null) { string[] array = lineItem.ItemId.Split("|".ToCharArray()); product.ProductCatalog = array[0]; product.ProductId = array[1]; product.ProductName = string.IsNullOrEmpty(productComponent.ProductName) ? productComponent.DisplayName : productComponent.ProductName; product.SitecoreProductItemId = GetSitecoreItemId(array[1], array[2]); destination.SetPropertyValue("_product_Images", productComponent.Image == null || string.IsNullOrEmpty(productComponent.Image.SitecoreId) ? string.Empty : productComponent.Image.SitecoreId); product.SetPropertyValue("Image", productComponent.Image == null || string.IsNullOrEmpty(productComponent.Image.SitecoreId) ? string.Empty : productComponent.Image.SitecoreId); product.SetPropertyValue("Color", string.IsNullOrEmpty(productComponent.Color) ? null : productComponent.Color); product.SetPropertyValue("Size", string.IsNullOrEmpty(productComponent.Size) ? null : productComponent.Size); product.SetPropertyValue("Style", string.IsNullOrEmpty(productComponent.Style) ? null : productComponent.Style); //if (!string.IsNullOrEmpty(productComponent.ExternalId) && // ID.TryParse(productComponent.ExternalId, out var result)) //{ // product.SitecoreProductItemId = result.ToGuid(); //} ItemVariationSelectedComponent selectedComponent = lineItem.CartLineComponents.OfType <ItemVariationSelectedComponent>().FirstOrDefault(); if (selectedComponent != null) { product.ProductId = productComponent.Id + "|" + selectedComponent.VariationId; product.ProductVariantId = selectedComponent.VariationId; } } if (lineItem.UnitListPrice != null) { product.Price = new Price(lineItem.UnitListPrice.Amount, lineItem.UnitListPrice.CurrencyCode); } wishListLine.Product = product; wishListLine.Quantity = lineItem.Quantity; } resultWishlist.Add(wishListLine); } } return(resultWishlist); }
internal WishList TranslateCartToWishListEntity(Cart cart, ServiceProviderResult currentResult) { WishList result = new WishList(); Translate(cart, result); return(result); }
//protected override WishList GetTranslateDestination(TranslateCartToEntityRequest request) //{ // return this.EntityFactory.Create<WishList>("Cart"); //} protected virtual void TranslateLines(TranslateCartToEntityRequest request, Sitecore.Commerce.Plugin.Carts.Cart source, WishList destination) { Assert.ArgumentNotNull((object)request, nameof(request)); Assert.ArgumentNotNull((object)source, nameof(source)); Assert.ArgumentNotNull((object)destination, nameof(destination)); List <WishListLine> resultWishlist = new List <WishListLine>(); if (source.Lines != null) { foreach (var lineItem in source.Lines) { var wishListLine = new WishListLine() { ExternalId = lineItem.Id, Product = new CartProduct() }; if (lineItem.CartLineComponents != null && !string.IsNullOrEmpty(lineItem.ItemId)) { CartProductComponent productComponent = lineItem.CartLineComponents.OfType <CartProductComponent>().FirstOrDefault <CartProductComponent>(); var product = new CartProduct(); if (productComponent != null) { // string[] strArray = source.ItemId.Split("|".ToCharArray()); //product.ProductCatalog = strArray[0]; product.ProductId = productComponent.Id; product.ProductName = string.IsNullOrEmpty(productComponent.ProductName) ? productComponent.DisplayName : productComponent.ProductName; destination.SetPropertyValue("_product_Images", productComponent.Image == null || string.IsNullOrEmpty(productComponent.Image.SitecoreId) ? (object)string.Empty : (object)productComponent.Image.SitecoreId); product.SetPropertyValue("Color", string.IsNullOrEmpty(productComponent.Color) ? (object)(string)null : (object)productComponent.Color); product.SetPropertyValue("Size", string.IsNullOrEmpty(productComponent.Size) ? (object)(string)null : (object)productComponent.Size); product.SetPropertyValue("Style", string.IsNullOrEmpty(productComponent.Style) ? (object)(string)null : (object)productComponent.Style); ID result; if (!string.IsNullOrEmpty(productComponent.ExternalId) && ID.TryParse(productComponent.ExternalId, out result)) { product.SitecoreProductItemId = result.ToGuid(); } } ItemVariationSelectedComponent selectedComponent = lineItem.CartLineComponents.OfType <ItemVariationSelectedComponent>().FirstOrDefault <ItemVariationSelectedComponent>(); if (selectedComponent != null) { product.ProductId = productComponent.Id + "|" + selectedComponent.VariationId; } if (lineItem.UnitListPrice != null) { product.Price = new Price(lineItem.UnitListPrice.Amount, lineItem.UnitListPrice.CurrencyCode); } wishListLine.Product = product; wishListLine.Quantity = lineItem.Quantity; } resultWishlist.Add(wishListLine); } } }
protected override void Translate(TranslateCartToEntityRequest request, Sitecore.Commerce.Plugin.Carts.Cart source, CommerceCart destination) { base.Translate(request, source, destination); var customCart = destination as CustomCart; this.TranslateCustomPaymentMethods(source, customCart); this.TranslateAdditionalParties(source, customCart); }
internal WishList TranslateCartToWishListEntity(Sitecore.Commerce.Plugin.Carts.Cart cart, ServiceProviderResult currentResult) { //TranslateCartToEntityRequest cartToEntityRequest = new TranslateCartToEntityRequest(); //cartToEntityRequest.TranslateSource = cart; //TranslateCartToEntityRequest request = cartToEntityRequest; //// TODO: Move the name of pipeline to constants //TranslateCartToWishListEntityResult cartToEntityResult = PipelineUtility.RunConnectPipeline<TranslateCartToEntityRequest, TranslateCartToWishListEntityResult>("translate.cartToWishListEntity", request); //this.MergeResults(currentResult, (ServiceProviderResult)cartToEntityResult); //return cartToEntityResult.TranslatedEntity; WishList result = new WishList(); Translate(cart, result); return(result); }
protected void Translate(Cart source, WishList destination) { destination.ExternalId = source.Id; destination.Name = source.Name; destination.ShopName = source.ShopName; if (source.Components != null && source.Components.Any()) { ContactComponent contactComponent = source.Components.OfType <ContactComponent>().FirstOrDefault(); if (contactComponent != null) { // destination.Email = contactComponent.Email ?? string.Empty; destination.UserId = contactComponent.ShopperId ?? string.Empty; destination.CustomerId = string.IsNullOrEmpty(contactComponent.CustomerId) ? contactComponent.ShopperId ?? string.Empty : contactComponent.CustomerId; } } destination.Lines = TranslateLines(source, destination); }
protected void Translate(TranslateCartToEntityRequest request, Sitecore.Commerce.Plugin.Carts.Cart source, WishList destination) { //base.Translate(request, source, destination); destination.ExternalId = source.Id; destination.Name = source.Name; destination.ShopName = source.ShopName; if (source.Components != null && source.Components.Any <Component>()) { ContactComponent contactComponent = source.Components.OfType <ContactComponent>().FirstOrDefault <ContactComponent>(); if (contactComponent != null) { // destination.Email = contactComponent.Email ?? string.Empty; destination.UserId = contactComponent.ShopperId ?? string.Empty; destination.CustomerId = string.IsNullOrEmpty(contactComponent.CustomerId) ? contactComponent.ShopperId ?? string.Empty : contactComponent.CustomerId; } } this.TranslateLines(request, source, destination); }