/// <summary>
 /// Adds a <see cref="IShipment"/> to the extended data collection
 /// </summary>
 /// <param name="extendedData"></param>
 /// <param name="shipment"></param>
 public static void AddShipment(this ExtendedDataCollection extendedData, IShipment shipment)
 {
     extendedData.AddAddress(shipment.GetOriginAddress(), Constants.ExtendedDataKeys.ShippingOriginAddress);
     extendedData.AddAddress(shipment.GetDestinationAddress(), Constants.ExtendedDataKeys.ShippingDestinationAddress);
     extendedData.SetValue(Constants.ExtendedDataKeys.ShipMethodKey, shipment.ShipMethodKey.ToString());
     extendedData.AddLineItemCollection(shipment.Items);
 }
        /// <summary>
        /// Adds a <see cref="LineItemCollection"/> to the <see cref="ExtendedDataCollection"/>
        /// </summary>
        /// <param name="extendedData"></param>
        /// <param name="lineItemCollection"></param>
        public static void AddLineItemCollection(this ExtendedDataCollection extendedData, LineItemCollection lineItemCollection)
        {
            using (var sw = new StringWriter())
            {
                var settings = new XmlWriterSettings()
                {
                    OmitXmlDeclaration = true
                };

                using (var writer = XmlWriter.Create(sw, settings))
                {
                    writer.WriteStartDocument();
                    writer.WriteStartElement(Constants.ExtendedDataKeys.LineItemCollection);

                    foreach (var lineItem in lineItemCollection)
                    {
                        //writer.WriteStartElement(Constants);
                        writer.WriteRaw(((LineItemBase)lineItem).SerializeToXml());
                    }

                    writer.WriteEndElement(); // ExtendedData
                    writer.WriteEndDocument();
                }
                extendedData.SetValue(Constants.ExtendedDataKeys.LineItemCollection, sw.ToString());
            }
        }
Beispiel #3
0
        /// <summary>
        /// Adds an <see cref="IAddress"/> to extended data.  This is intended for shipment addresses
        /// </summary>
        /// <param name="extendedData">
        /// The extended Data.
        /// </param>
        /// <param name="address">
        /// The <see cref="IAddress"/> to be added to extended data
        /// </param>
        /// <param name="dictionaryKey">
        /// The dictionary key used to reference the serialized <see cref="IAddress"/>
        /// </param>
        public static void AddAddress(this ExtendedDataCollection extendedData, IAddress address, string dictionaryKey)
        {
            var addressXml = SerializationHelper.SerializeToXml(address as Address);

            ////var addressJson = JsonConvert.SerializeObject(address);

            extendedData.SetValue(dictionaryKey, addressXml);
        }
Beispiel #4
0
        /// <summary>
        /// The as extended data collection.
        /// </summary>
        /// <param name="source">
        /// The source.
        /// </param>
        /// <returns>
        /// The <see cref="ExtendedDataCollection"/>.
        /// </returns>
        internal static ExtendedDataCollection AsExtendedDataCollection(this IEnumerable<KeyValuePair<string, string>> source)
        {
            var ed = new ExtendedDataCollection();
            foreach (var item in source.ToArray())
            {
                ed.SetValue(item.Key, item.Value);
            }

            return ed;
        }
Beispiel #5
0
 /// <summary>
 /// Merges the modifier extend data(s) into the extended data
 /// </summary>
 /// <param name="extendedData">
 /// The extended data.
 /// </param>
 /// <param name="modifier">
 /// The modifier.
 /// </param>
 public static void MergeDataModifierLogs(this ExtendedDataCollection extendedData, IDataModifierData modifier)
 {
     if (modifier.ModifiedDataLogs == null)
     {
         return;
     }
     foreach (var log in modifier.ModifiedDataLogs)
     {
         foreach (var item in log.ExtendedData)
         {
             extendedData.SetValue(item.Key, item.Value);
         }
     }
 }
Beispiel #6
0
 /// <summary>
 /// Sets an object value into an extended data collection
 /// </summary>
 /// <param name="extendedData">
 /// The extended data.
 /// </param>
 /// <param name="key">
 /// The key.
 /// </param>
 /// <param name="model">
 /// The model.
 /// </param>
 /// <typeparam name="T">
 /// The type of object to be serialized
 /// </typeparam>
 public static void SetValue <T>(this ExtendedDataCollection extendedData, string key, T model) where T : class, new()
 {
     try
     {
         var value = JsonConvert.SerializeObject(model);
         extendedData.SetValue(key, value);
     }
     catch (Exception ex)
     {
         var logData = MultiLogger.GetBaseLoggingData();
         logData.AddCategory("ExtendedData");
         MultiLogHelper.WarnWithException(typeof(ExtendedDataCollectionExtensions), "Failed to serialize value. Proceding with operation.", ex, logData);
     }
 }
 public static void AddExtendedDataCollection(this ExtendedDataCollection extendedData, ExtendedDataCollection extendedDataToSerialize)
 {
     extendedData.SetValue(Constants.ExtendedDataKeys.ExtendedData, extendedDataToSerialize.SerializeToXml());
 }
 public static void AddProductVariantValues(this ExtendedDataCollection extendedData, IProductVariant productVariant)
 {
     extendedData.SetValue(Constants.ExtendedDataKeys.ProductKey, productVariant.ProductKey.ToString());
     extendedData.SetValue(Constants.ExtendedDataKeys.ProductVariantKey, productVariant.Key.ToString());
     extendedData.SetValue(Constants.ExtendedDataKeys.CostOfGoods, productVariant.CostOfGoods.ToString());
     extendedData.SetValue(Constants.ExtendedDataKeys.Weight, productVariant.Weight.ToString());
     extendedData.SetValue(Constants.ExtendedDataKeys.Width, productVariant.Width.ToString());
     extendedData.SetValue(Constants.ExtendedDataKeys.Height, productVariant.Height.ToString());
     extendedData.SetValue(Constants.ExtendedDataKeys.Length, productVariant.Length.ToString());
     extendedData.SetValue(Constants.ExtendedDataKeys.Barcode, productVariant.Barcode);
     extendedData.SetValue(Constants.ExtendedDataKeys.Price, productVariant.Price.ToString(CultureInfo.InvariantCulture));
     extendedData.SetValue(Constants.ExtendedDataKeys.OnSale, productVariant.OnSale.ToString());
     extendedData.SetValue(Constants.ExtendedDataKeys.Manufacturer, productVariant.Manufacturer);
     extendedData.SetValue(Constants.ExtendedDataKeys.ManufacturerModelNumber, productVariant.ManufacturerModelNumber);
     extendedData.SetValue(Constants.ExtendedDataKeys.SalePrice, productVariant.SalePrice == null ? 0.ToString(CultureInfo.InvariantCulture) : productVariant.SalePrice.ToString());
     extendedData.SetValue(Constants.ExtendedDataKeys.TrackInventory, productVariant.TrackInventory.ToString());
     extendedData.SetValue(Constants.ExtendedDataKeys.OutOfStockPurchase, productVariant.OutOfStockPurchase.ToString());
     extendedData.SetValue(Constants.ExtendedDataKeys.Taxable, productVariant.Taxable.ToString());
     extendedData.SetValue(Constants.ExtendedDataKeys.Shippable, productVariant.Shippable.ToString());
     extendedData.SetValue(Constants.ExtendedDataKeys.Download, productVariant.Download.ToString());
     extendedData.SetValue(Constants.ExtendedDataKeys.DownloadMediaId, productVariant.DownloadMediaId.ToString());
 }
Beispiel #9
0
 /// <summary>
 /// Saves a <see cref="IPaymentMethod"/> to an extended data collection
 /// </summary>
 /// <param name="extendedData">
 /// The extended Data.
 /// </param>
 /// <param name="paymentMethod">
 /// The payment Method.
 /// </param>
 internal static void AddPaymentMethod(this ExtendedDataCollection extendedData, IPaymentMethod paymentMethod)
 {
     extendedData.SetValue(Constants.ExtendedDataKeys.PaymentMethod, paymentMethod.Key.ToString());
 }