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);
        }
        protected override void TranslateProduct(TranslateCartLineToEntityRequest request, CartLineComponent source, CommerceCartLine destination, bool isSubLine = false)
        {
            Assert.ArgumentNotNull((object)request, nameof(request));
            Assert.ArgumentNotNull((object)source, nameof(source));
            Assert.ArgumentNotNull((object)destination, nameof(destination));
            CommerceCartProduct commerceCartProduct = this.EntityFactory.Create <CommerceCartProduct>("CartProduct");

            if (source.CartLineComponents != null && !string.IsNullOrEmpty(source.ItemId))
            {
                CartProductComponent productComponent = source.CartLineComponents.OfType <CartProductComponent>().FirstOrDefault <CartProductComponent>();
                if (productComponent != null)
                {
                    string[] strArray = source.ItemId.Split("|".ToCharArray());
                    commerceCartProduct.ProductCatalog        = strArray[0];
                    commerceCartProduct.ProductId             = productComponent.Id;
                    commerceCartProduct.DisplayName           = productComponent.DisplayName;
                    commerceCartProduct.ProductName           = string.IsNullOrEmpty(productComponent.ProductName) ? productComponent.DisplayName : productComponent.ProductName;
                    commerceCartProduct.SitecoreProductItemId = this.GetSitecoreItemId(strArray[1], strArray[2]);
                    destination.SetPropertyValue("_product_Images", productComponent.Image == null || string.IsNullOrEmpty(productComponent.Image.SitecoreId) ? (object)string.Empty : (object)productComponent.Image.SitecoreId);
                    commerceCartProduct.SetPropertyValue("Color", string.IsNullOrEmpty(productComponent.Color) ? (object)(string)null : (object)productComponent.Color);
                    commerceCartProduct.SetPropertyValue("Size", string.IsNullOrEmpty(productComponent.Size) ? (object)(string)null : (object)productComponent.Size);
                    commerceCartProduct.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))
                    {
                        commerceCartProduct.SitecoreProductItemId = result.ToGuid();
                    }
                }
                ItemVariationSelectedComponent selectedComponent = source.CartLineComponents.OfType <ItemVariationSelectedComponent>().FirstOrDefault <ItemVariationSelectedComponent>();
                if (selectedComponent != null)
                {
                    commerceCartProduct.ProductVariantId = selectedComponent.VariationId;
                }

                //Set an additional property to determine the Promotion Awarding Blocks [Promotion Plugin Issue#2 described in Known Issues with Promotion plugin blog post]
                if (source.Adjustments != null && source.Adjustments.Any())
                {
                    destination.SetPropertyValue(CartAdjustmentTypePropertyName, string.Join("|", source.Adjustments.Select(x => x.AwardingBlock)));
                }
            }
            CommercePrice commercePrice = this.EntityFactory.Create <CommercePrice>("Price");

            if (source.UnitListPrice != null)
            {
                PurchaseOptionMoneyPolicy optionMoneyPolicy = source.Policies.OfType <PurchaseOptionMoneyPolicy>().FirstOrDefault <PurchaseOptionMoneyPolicy>();
                if (optionMoneyPolicy != null && source.UnitListPrice.Amount != optionMoneyPolicy.SellPrice.Amount)
                {
                    commercePrice.CurrencyCode = optionMoneyPolicy.SellPrice.CurrencyCode;
                    commercePrice.ListPrice    = optionMoneyPolicy.SellPrice.Amount;
                }
                else
                {
                    commercePrice.CurrencyCode = source.UnitListPrice.CurrencyCode;
                    commercePrice.ListPrice    = source.UnitListPrice.Amount;
                }
                commercePrice.Amount = commercePrice.ListPrice;
            }
            commerceCartProduct.Price = (Price)commercePrice;
            destination.Product       = (CartProduct)commerceCartProduct;
        }