示例#1
0
 /// <summary>
 /// The product pre tax sale price.
 /// </summary>
 /// <param name="extendedData">
 /// The extended data.
 /// </param>
 /// <returns>
 /// The <see cref="decimal"/>.
 /// </returns>
 public static decimal ProductPreTaxSalePrice(this ExtendedDataCollection extendedData)
 {
     return(!extendedData.TaxIncludedInProductPrice()
                ? extendedData.GetPriceValue()
                : extendedData.ContainsKey(Constants.ExtendedDataKeys.ProductSalePriceNoTax)
                      ? extendedData.GetValue(Constants.ExtendedDataKeys.ProductSalePriceNoTax).AsDecimal()
                      : extendedData.GetPriceValue());
 }
示例#2
0
 /// <summary>
 /// The product tax amount.
 /// </summary>
 /// <param name="extendedData">
 /// The extended data.
 /// </param>
 /// <returns>
 /// The <see cref="decimal"/>.
 /// </returns>
 public static decimal ProductSalePriceTaxAmount(this ExtendedDataCollection extendedData)
 {
     return(!extendedData.TaxIncludedInProductPrice()
                ? 0M
                : extendedData.ContainsKey(Constants.ExtendedDataKeys.ProductSalePriceTaxAmount)
                      ? extendedData.GetValue(Constants.ExtendedDataKeys.ProductSalePriceTaxAmount).AsDecimal()
                      : 0M);
 }
示例#3
0
        /// <summary>
        /// Gets an <see cref="IAddress"/> from the <see cref="ExtendedDataCollection"/>
        /// </summary>
        /// <param name="extendedData">
        /// The extended Data.
        /// </param>
        /// <param name="dictionaryKey">
        /// The dictionary Key.
        /// </param>
        /// <returns>
        /// The <see cref="IAddress"/>.
        /// </returns>
        public static IAddress GetAddress(this ExtendedDataCollection extendedData, string dictionaryKey)
        {
            if (!extendedData.ContainsKey(dictionaryKey)) return null;

            var attempt = SerializationHelper.DeserializeXml<Address>(extendedData.GetValue(dictionaryKey));

            return attempt.Success ? attempt.Result : null;
            ////return JsonConvert.DeserializeObject<IAddress>(extendedData.GetValue(dictionaryKey));
        }
        /// <summary>
        /// Gets an <see cref="IAddress"/> from the <see cref="ExtendedDataCollection"/>
        /// </summary>
        /// <param name="extendedData"></param>
        /// <param name="dictionaryKey"></param>
        /// <returns></returns>
        public static IAddress GetAddress(this ExtendedDataCollection extendedData, string dictionaryKey)
        {
            if (!extendedData.ContainsKey(dictionaryKey))
            {
                return(null);
            }

            var attempt = SerializationHelper.DeserializeXml <Address>(extendedData.GetValue(dictionaryKey));

            return(attempt.Success ? attempt.Result : null);
        }
示例#5
0
        /// <summary>
        /// Gets a list of all keys with a given key prefix.
        /// </summary>
        /// <param name="extendedData">
        /// The extended data.
        /// </param>
        /// <param name="prefix">
        /// The prefix.
        /// </param>
        /// <returns>
        /// The collection of values that match the prefix.
        /// </returns>
        /// <remarks>
        /// Introduced for customer context conversions.
        /// </remarks>
        internal static IEnumerable <KeyValuePair <string, string> > GetItemsByKeyPrefix(this ExtendedDataCollection extendedData, string prefix)
        {
            var values = new List <KeyValuePair <string, string> >();

            foreach (var item in extendedData.Keys)
            {
                if (item.StartsWith(prefix))
                {
                    values.Add(new KeyValuePair <string, string>(item, extendedData.GetValue(item)));
                }
            }

            return(values);
        }
示例#6
0
 /// <summary>
 /// Gets a typed value.
 /// </summary>
 /// <param name="extendedData">
 /// The extended data.
 /// </param>
 /// <param name="key">
 /// The key.
 /// </param>
 /// <typeparam name="T">
 /// The type to be returned.
 /// </typeparam>
 /// <returns>
 /// The typed value.
 /// </returns>
 public static T GetValue <T>(this ExtendedDataCollection extendedData, string key) where T : class, new()
 {
     try
     {
         var value = extendedData.GetValue(key);
         return(!value.IsNullOrWhiteSpace() ?
                JsonConvert.DeserializeObject <T>(value) :
                default(T));
     }
     catch (Exception ex)
     {
         var logData = MultiLogger.GetBaseLoggingData();
         logData.AddCategory("ExtendedData");
         MultiLogHelper.WarnWithException(typeof(ExtendedDataCollectionExtensions), "Failed to deserialize value. Proceding with operation returning default T.", ex, logData);
         return(default(T));
     }
 }
示例#7
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);
        }
 /// <summary>
 /// Returns the "merchDownload" value
 /// </summary>
 /// <param name="extendedData"><see cref="ExtendedDataCollection"/></param>
 /// <returns>bool</returns>
 public static bool GetDownloadValue(this ExtendedDataCollection extendedData)
 {
     return(GetBooleanValue(extendedData.GetValue(Constants.ExtendedDataKeys.Download)));
 }
 /// <summary>
 /// Returns the "merchOutOfStockPurchase" value
 /// </summary>
 /// <param name="extendedData"><see cref="ExtendedDataCollection"/></param>
 /// <returns>bool</returns>
 public static bool GetOutOfStockPurchaseValue(this ExtendedDataCollection extendedData)
 {
     return(GetBooleanValue(extendedData.GetValue(Constants.ExtendedDataKeys.OutOfStockPurchase)));
 }
 /// <summary>
 /// Returns the "merchTrackInventory" value
 /// </summary>
 /// <param name="extendedData"><see cref="ExtendedDataCollection"/></param>
 /// <returns>bool</returns>
 public static bool GetTrackInventoryValue(this ExtendedDataCollection extendedData)
 {
     return(GetBooleanValue(extendedData.GetValue(Constants.ExtendedDataKeys.TrackInventory)));
 }
示例#11
0
 /// <summary>
 /// Returns the VersionKey
 /// </summary>
 /// <param name="extendedData">
 /// The extended Data.
 /// </param>
 /// <returns>
 /// The version key.
 /// </returns>
 public static Guid GetVersionKey(this ExtendedDataCollection extendedData)
 {
     return(!extendedData.ContainsVersionKey() ?
            Guid.Empty :
            extendedData.GetValue(Constants.ExtendedDataKeys.VersionKey).AsGuid());
 }
 /// <summary>
 /// returns the "merchWeight" value
 /// </summary>
 /// <param name="extendedData"><see cref="ExtendedDataCollection"/></param>
 /// <returns>decimal</returns>
 public static string GetBarcodeValue(this ExtendedDataCollection extendedData)
 {
     return(extendedData.GetValue(Constants.ExtendedDataKeys.Barcode));
 }
 /// <summary>
 /// Gets a <see cref="ExtendedDataCollection"/> from the <see cref="ExtendedDataCollection"/>
 /// </summary>
 public static ExtendedDataCollection GetExtendedDataCollection(this ExtendedDataCollection extendedData)
 {
     return(extendedData.ContainsExtendedDataSerialization()
                ? new ExtendedDataCollection(extendedData.GetValue(Constants.ExtendedDataKeys.ExtendedData))
                : null);
 }
 /// <summary>
 /// Returns the "merchSalePrice" value
 /// </summary>
 /// <param name="extendedData"></param>
 /// <returns></returns>
 public static decimal GetSalePriceValue(this ExtendedDataCollection extendedData)
 {
     return(GetDecimalValue(extendedData.GetValue(Constants.ExtendedDataKeys.SalePrice)));
 }
示例#15
0
 /// <summary>
 /// Returns the merchShipmentKey value as a GUID
 /// </summary>
 /// <param name="extendedData">
 /// The extended Data.
 /// </param>
 /// <returns>
 /// The GUID based 'Key' of the <see cref="IShipment"/>
 /// </returns>
 public static Guid GetShipmentKey(this ExtendedDataCollection extendedData)
 {
     return extendedData.GetValue(Constants.ExtendedDataKeys.ShipmentKey).AsGuid();
 }
示例#16
0
 /// <summary>
 /// Return the ProductVariantKey
 /// </summary>
 /// <param name="extendedData">
 /// The extended Data.
 /// </param>
 /// <returns>
 /// The product variant key.
 /// </returns>
 public static Guid GetProductVariantKey(this ExtendedDataCollection extendedData)
 {
     return extendedData.GetValue(Constants.ExtendedDataKeys.ProductVariantKey).AsGuid();
 }
示例#17
0
 /// <summary>
 /// Returns the "merchPrice" value
 /// </summary>
 /// <param name="extendedData">
 /// The extended Data.
 /// </param>
 /// <returns>
 /// The price.
 /// </returns>
 public static decimal GetPriceValue(this ExtendedDataCollection extendedData)
 {
     decimal converted = decimal.TryParse(extendedData.GetValue(Constants.ExtendedDataKeys.Price), System.Globalization.NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out converted) ? converted : 0;
     return converted;
 }
示例#18
0
 /// <summary>
 /// Returns the "merchDownload" value
 /// </summary>
 /// <param name="extendedData">The <see cref="ExtendedDataCollection"/></param>
 /// <returns>A value indicating whether or not the item is downloadable</returns>
 public static bool GetDownloadValue(this ExtendedDataCollection extendedData)
 {
     return extendedData.GetValue(Constants.ExtendedDataKeys.Download).AsBool();
 }
示例#19
0
 /// <summary>
 /// returns the "merchHeight" value
 /// </summary>
 /// <param name="extendedData">The <see cref="ExtendedDataCollection"/></param>
 /// <returns>The height</returns>
 public static decimal GetHeightValue(this ExtendedDataCollection extendedData)
 {
     return(extendedData.GetValue(Constants.ExtendedDataKeys.Height).AsDecimal());
 }
 /// <summary>
 /// Returns the "merchTrackInventory" value
 /// </summary>
 /// <param name="extendedData"><see cref="ExtendedDataCollection"/></param>
 /// <returns>bool</returns>
 public static int GetDownloadMediaIdValue(this ExtendedDataCollection extendedData)
 {
     return(GetIntegerValue(extendedData.GetValue(Constants.ExtendedDataKeys.DownloadMediaId)));
 }
 /// <summary>
 /// Returns the "merchOnSale" value as a boolean
 /// </summary>
 /// <param name="extendedData"></param>
 /// <returns></returns>
 public static bool GetOnSaleValue(this ExtendedDataCollection extendedData)
 {
     return(GetBooleanValue(extendedData.GetValue(Constants.ExtendedDataKeys.OnSale)));
 }
示例#22
0
 /// <summary>
 /// Returns the "merchTaxable" value
 /// </summary>
 /// <param name="extendedData">The <see cref="ExtendedDataCollection"/></param>
 /// <returns>A value indicating whether or not the line item is taxable</returns>
 public static bool GetTaxableValue(this ExtendedDataCollection extendedData)
 {
     return extendedData.GetValue(Constants.ExtendedDataKeys.Taxable).AsBool();
 }
 /// <summary>
 /// Returns the "merchManufacturerModelNumber" value
 /// </summary>
 /// <param name="extendedData"></param>
 /// <returns></returns>
 public static string GetManufacturerModelNumberValue(this ExtendedDataCollection extendedData)
 {
     return(extendedData.GetValue(Constants.ExtendedDataKeys.ManufacturerModelNumber));
 }
 /// <summary>
 /// Returns the merchShipMethodKey value as a Guid
 /// </summary>
 /// <param name="extendedData"></param>
 /// <returns>The Guid based 'Key' of the <see cref="IShipMethod"/></returns>
 public static Guid GetShipMethodKey(this ExtendedDataCollection extendedData)
 {
     return(GetGuidValue(extendedData.GetValue(Constants.ExtendedDataKeys.ShipMethodKey)));
 }
 /// <summary>
 /// returns the "merchLength" value
 /// </summary>
 /// <param name="extendedData"><see cref="ExtendedDataCollection"/></param>
 /// <returns>decimal</returns>
 public static decimal GetLengthValue(this ExtendedDataCollection extendedData)
 {
     return(GetDecimalValue(extendedData.GetValue(Constants.ExtendedDataKeys.Length)));
 }
 /// <summary>
 /// Returns the ProductKey
 /// </summary>
 /// <param name="extendedData"></param>
 /// <returns></returns>
 public static Guid GetProductKey(this ExtendedDataCollection extendedData)
 {
     return(GetGuidValue(extendedData.GetValue(Constants.ExtendedDataKeys.ProductKey)));
 }
示例#27
0
 /// <summary>
 /// returns the "merchWidth" value
 /// </summary>
 /// <param name="extendedData">The <see cref="ExtendedDataCollection"/></param>
 /// <returns>The width</returns>
 public static decimal GetWidthValue(this ExtendedDataCollection extendedData)
 {
     return extendedData.GetValue(Constants.ExtendedDataKeys.Width).AsDecimal();
 }
示例#28
0
 /// <summary>
 /// The tax included in product price.
 /// </summary>
 /// <param name="extendedData">
 /// The extended data.
 /// </param>
 /// <returns>
 /// A value indicating whether or not tax is included in the product price.
 /// </returns>
 public static bool TaxIncludedInProductPrice(this ExtendedDataCollection extendedData)
 {
     return(extendedData.ContainsKey(Constants.ExtendedDataKeys.TaxIncludedInProductPrice) &&
            extendedData.GetValue(Constants.ExtendedDataKeys.TaxIncludedInProductPrice).AsBool());
 }
 /// <summary>
 /// Return the WarehouseCatalogKey
 /// </summary>
 /// <param name="extendedData"></param>
 /// <returns></returns>
 public static Guid GetWarehouseCatalogKey(this ExtendedDataCollection extendedData)
 {
     return(GetGuidValue(extendedData.GetValue(Constants.ExtendedDataKeys.WarehouseCatalogKey)));
 }
示例#30
0
 /// <summary>
 /// Gets a <see cref="IPaymentMethod"/> from the <see cref="ExtendedDataCollection"/>
 /// </summary>
 /// <param name="extendedData">
 /// The extended Data.
 /// </param>
 /// <returns>
 /// The payment method key.
 /// </returns>
 internal static Guid GetPaymentMethodKey(this ExtendedDataCollection extendedData)
 {
     return !extendedData.ContainsKey(Constants.ExtendedDataKeys.PaymentMethod) ? Guid.Empty :
         extendedData.GetValue(Constants.ExtendedDataKeys.PaymentMethod).AsGuid();
 }