Пример #1
0
        /// <summary>
        /// Creates an instance of <see cref="LineItemCollection"/> from a serialized collection in the ExtendedDataCollection
        /// </summary>
        /// <typeparam name="T">The type of the <see cref="ILineItem"/></typeparam>
        /// <param name="extendedData">The extended data collection</param>
        /// <returns><see cref="LineItemCollection"/></returns>
        public static LineItemCollection GetLineItemCollection <T>(this ExtendedDataCollection extendedData) where T : LineItemBase
        {
            if (!extendedData.ContainsKey(Constants.ExtendedDataKeys.LineItemCollection))
            {
                return(null);
            }

            var xdoc = XDocument.Parse(extendedData.GetValue(Constants.ExtendedDataKeys.LineItemCollection));
            var lineItemCollection = new LineItemCollection();

            foreach (var element in xdoc.Descendants(Constants.ExtendedDataKeys.LineItem))
            {
                var dictionary = GetLineItemXmlValues(element.ToString());

                var extendData = new ExtendedDataCollection(dictionary[Constants.ExtendedDataKeys.ExtendedData]);

                var ctrValues = new object[]
                {
                    new Guid(dictionary[Constants.ExtendedDataKeys.LineItemTfKey]),
                    dictionary[Constants.ExtendedDataKeys.Name],
                    dictionary[Constants.ExtendedDataKeys.Sku],
                    int.Parse(dictionary[Constants.ExtendedDataKeys.Quantity]),
                    decimal.Parse(dictionary[Constants.ExtendedDataKeys.Price], NumberStyles.Any, CultureInfo.InvariantCulture),
                    new ExtendedDataCollection(dictionary[Constants.ExtendedDataKeys.ExtendedData])
                };

                var attempt = ActivatorHelper.CreateInstance <LineItemBase>(typeof(T).FullName, ctrValues);

                if (!attempt.Success)
                {
                    LogHelper.Error <LineItemCollection>("Failed to instantiate a LineItemCollection from ExtendedData", attempt.Exception);
                    throw attempt.Exception;
                }

                attempt.Result.ContainerKey = new Guid(dictionary[Constants.ExtendedDataKeys.ContainerKey]);

                lineItemCollection.Add(attempt.Result);
            }

            return(lineItemCollection);
        }
Пример #2
0
        /// <summary>
        /// Clones a shipment
        /// </summary>
        /// <param name="org">
        /// The org.
        /// </param>
        /// <returns>
        /// The <see cref="IShipment"/>.
        /// </returns>
        /// <remarks>
        /// http://issues.merchello.com/youtrack/issue/M-458
        /// </remarks>
        internal static IShipment Clone(this IShipment org)
        {
            var lineItemCollection = new LineItemCollection();

            foreach (var li in org.Items)
            {
                lineItemCollection.Add(li.AsLineItemOf <OrderLineItem>());
            }

            return(new Shipment(org.ShipmentStatus, org.GetOriginAddress(), org.GetDestinationAddress(), lineItemCollection)
            {
                ShipmentNumberPrefix = org.ShipmentNumberPrefix,
                ShipmentNumber = org.ShipmentNumber,
                ShippedDate = org.ShippedDate,
                TrackingCode = org.TrackingCode,
                Carrier = org.Carrier,
                ShipMethodKey = org.ShipMethodKey,
                Phone = org.Phone,
                Email = org.Email
            });
        }