Exemplo n.º 1
0
        /// <summary>
        /// Gets a collection of <see cref="IReplaceablePattern"/> for each line item in the <see cref="LineItemCollection"/>
        /// </summary>
        /// <param name="container">
        /// The container.
        /// </param>
        /// <param name="currencySymbol">
        /// The currency Symbol.
        /// </param>
        /// <returns>
        /// A collection of replaceable patterns
        /// </returns>
        internal static IEnumerable <IReplaceablePattern> LineItemReplaceablePatterns(this ILineItemContainer container, string currencySymbol)
        {
            var patterns = new List <IReplaceablePattern>();

            var token = container.GetFormatterIterationIdentifier();

            var iterateItems =
                container.Items.Where(
                    x => x.LineItemType == LineItemType.Product || x.LineItemType == LineItemType.Custom).ToArray();

            // TODO localization needed on pricing and datetime
            for (var i = 0; i < iterateItems.Count(); i++)
            {
                var sku        = new ReplaceablePattern(string.Format("{0}.{1}.{2}", token, "Sku", i), string.Format("{0}Item.Sku.{1}{2}", "{{", i, "}}"), iterateItems[i].LineItemType == LineItemType.Shipping ? string.Empty : iterateItems[i].Sku);
                var unitPrice  = new ReplaceablePattern(string.Format("{0}.{1}.{2}", token, "UnitPrice", i), string.Format("{0}Item.UnitPrice.{1}{2}", "{{", i, "}}"), iterateItems[i].Price.FormatAsPrice(currencySymbol));
                var name       = new ReplaceablePattern(string.Format("{0}.{1}.{2}", token, "Name", i), string.Format("{0}Item.Name.{1}{2}", "{{", i, "}}"), iterateItems[i].Name);
                var qty        = new ReplaceablePattern(string.Format("{0}.{1}.{2}", token, "Quantity", i), string.Format("{0}Item.Quantity.{1}{2}", "{{", i, "}}"), iterateItems[i].Quantity.ToString(CultureInfo.InvariantCulture));
                var totalPrice = new ReplaceablePattern(string.Format("{0}.{1}.{2}", token, "TotalPrice", i), string.Format("{0}Item.TotalPrice.{1}{2}", "{{", i, "}}"), iterateItems[i].TotalPrice.FormatAsPrice(currencySymbol));

                patterns.Add(sku);
                patterns.Add(name);
                patterns.Add(unitPrice);
                patterns.Add(qty);
                patterns.Add(totalPrice);
            }

            //var shippingLineItems = container.ShippingLineItems().ToArray();

            //// TODO - needs work once we expose multiple shipments to do an array if multiple destinations are detected
            //if (shippingLineItems.Any())
            //{
            //    var shipment = shippingLineItems.First().ExtendedData.GetShipment<InvoiceLineItem>();
            //    patterns.Add(ReplaceablePattern.GetConfigurationReplaceablePattern("ShipToName", shipment.ToName));

            //}


            return(patterns.Where(x => x != null));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets a collection of <see cref="IReplaceablePattern"/> for each line item in the <see cref="LineItemCollection"/>
        /// </summary>
        /// <param name="container">
        /// The container.
        /// </param>
        /// <returns>
        /// A collection of replaceable patterns
        /// </returns>
        internal static IEnumerable <IReplaceablePattern> LineItemReplaceablePatterns(this ILineItemContainer container)
        {
            var patterns = new List <IReplaceablePattern>();

            var token = container.GetFormatterIterationIdentifier();

            // TODO localization needed on pricing and datetime
            for (var i = 0; i < container.Items.Count; i++)
            {
                var sku        = new ReplaceablePattern(string.Format("{0}.{1}.{2}", token, "Sku", i), string.Format("{0}Item.Sku.{1}{2}", "{{", i, "}}"), container.Items[i].LineItemType == LineItemType.Shipping ? string.Empty : container.Items[i].Sku);
                var unitPrice  = new ReplaceablePattern(string.Format("{0}.{1}.{2}", token, "UnitPrice", i), string.Format("{0}Item.UnitPrice.{1}{2}", "{{", i, "}}"), container.Items[i].Price.ToString("C"));
                var name       = new ReplaceablePattern(string.Format("{0}.{1}.{2}", token, "Name", i), string.Format("{0}Item.Name.{1}{2}", "{{", i, "}}"), container.Items[i].Name);
                var qty        = new ReplaceablePattern(string.Format("{0}.{1}.{2}", token, "Quantity", i), string.Format("{0}Item.Quantity.{1}{2}", "{{", i, "}}"), container.Items[i].Quantity.ToString(CultureInfo.InvariantCulture));
                var totalPrice = new ReplaceablePattern(string.Format("{0}.{1}.{2}", token, "TotalPrice", i), string.Format("{0}Item.TotalPrice.{1}{2}", "{{", i, "}}"), container.Items[i].TotalPrice.ToString("C"));

                patterns.Add(sku);
                patterns.Add(name);
                patterns.Add(unitPrice);
                patterns.Add(qty);
                patterns.Add(totalPrice);
            }

            return(patterns);
        }