Example #1
0
        public CsvProductMap(CsvProductMappingConfiguration mappingCfg)
        {
            //Dynamical map scalar product fields use by manual mapping information
            foreach (var mappingItem in mappingCfg.PropertyMaps.Where(x => !string.IsNullOrEmpty(x.CsvColumnName) || !string.IsNullOrEmpty(x.CustomValue)))
            {
                var propertyInfo = typeof(CsvProduct).GetProperty(mappingItem.EntityColumnName);
                if (propertyInfo != null)
                {
                    var newMap = new CsvPropertyMap(propertyInfo);
                    newMap.TypeConverterOption(CultureInfo.InvariantCulture);
                    newMap.TypeConverterOption(NumberStyles.Any);
                    newMap.TypeConverterOption(true, "yes", "true");
                    newMap.TypeConverterOption(false, "false", "no");
                    if (!string.IsNullOrEmpty(mappingItem.CsvColumnName))
                    {
                        //Map fields if mapping specified
                        newMap.Name(mappingItem.CsvColumnName);
                    }
                    //And default values if it specified
                    if (mappingItem.CustomValue != null)
                    {
                        var typeConverter = TypeDescriptor.GetConverter(propertyInfo.PropertyType);
                        newMap.Default(typeConverter.ConvertFromString(mappingItem.CustomValue));
                    }
                    PropertyMaps.Add(newMap);
                }
            }

            //Map properties
            if (mappingCfg.PropertyCsvColumns != null && mappingCfg.PropertyCsvColumns.Any())
            {
                // Exporting multiple csv fields from the same property (which is a collection)
                foreach (var propertyCsvColumn in mappingCfg.PropertyCsvColumns)
                {
                    // create CsvPropertyMap manually, because this.Map(x =>...) does not allow
                    // to export multiple entries for the same property
                    var csvPropertyMap = new CsvPropertyMap(typeof(CsvProduct).GetProperty("PropertyValues"));
                    csvPropertyMap.Name(propertyCsvColumn);

                    // create custom converter instance which will get the required record from the collection
                    csvPropertyMap.UsingExpression <ICollection <coreModel.PropertyValue> >(null, propValues =>
                    {
                        var propValue = propValues.FirstOrDefault(x => x.PropertyName == propertyCsvColumn);
                        if (propValue != null)
                        {
                            return(propValue.Value != null ? propValue.Value.ToString() : string.Empty);
                        }
                        return(string.Empty);
                    });

                    PropertyMaps.Add(csvPropertyMap);
                }

                var newPropMap = new CsvPropertyMap(typeof(CsvProduct).GetProperty("PropertyValues"));
                newPropMap.UsingExpression <ICollection <coreModel.PropertyValue> >(null, null).ConvertUsing(x => mappingCfg.PropertyCsvColumns.Select(column => new coreModel.PropertyValue {
                    PropertyName = column, Value = x.GetField <string>(column)
                }).ToList());
                PropertyMaps.Add(newPropMap);
            }
        }
		public static CsvProductMappingConfiguration GetDefaultConfiguration()
		{
			var retVal = new CsvProductMappingConfiguration();
			retVal.Delimiter = ";";

			var requiredFields = ReflectionUtility.GetPropertyNames<CsvProduct>(x => x.Name);
			var optionalFields = ReflectionUtility.GetPropertyNames<CsvProduct>(x => x.Id, x => x.Sku, x => x.CategoryPath, x => x.CategoryId, x => x.MainProductId, x=>x.PrimaryImage, x=>x.AltImage, x => x.SeoUrl, x => x.SeoTitle,
																				x => x.SeoDescription, x => x.Review, x => x.IsActive, x => x.IsBuyable, x => x.TrackInventory, 
																				x => x.PriceId, x => x.SalePrice, x => x.ListPrice, x => x.Currency,
																				x => x.ManufacturerPartNumber, x => x.Gtin, x => x.MeasureUnit, x => x.WeightUnit, x => x.Weight,
																				x => x.Height, x => x.Length, x => x.Width, x => x.TaxType, x => x.ProductType, x => x.ShippingType,
																				x => x.Vendor, x => x.DownloadType, x => x.DownloadExpiration, x => x.HasUserAgreement);

			retVal.PropertyMaps = requiredFields.Select(x => new CsvProductPropertyMap { EntityColumnName = x, CsvColumnName = x, IsRequired = true }).ToList();
			retVal.PropertyMaps.AddRange(optionalFields.Select(x => new CsvProductPropertyMap { EntityColumnName = x, CsvColumnName = x, IsRequired = false }));
			return retVal;
		}
Example #3
0
        public static CsvProductMappingConfiguration GetDefaultConfiguration()
        {
            var retVal = new CsvProductMappingConfiguration();

            retVal.Delimiter = ";";

            var requiredFields = ReflectionUtility.GetPropertyNames <CsvProduct>(x => x.Name);
            var optionalFields = ReflectionUtility.GetPropertyNames <CsvProduct>(x => x.Id, x => x.Sku, x => x.CategoryPath, x => x.CategoryId, x => x.MainProductId, x => x.PrimaryImage, x => x.AltImage, x => x.SeoUrl, x => x.SeoTitle,
                                                                                 x => x.SeoDescription, x => x.Review, x => x.IsActive, x => x.IsBuyable, x => x.TrackInventory,
                                                                                 x => x.PriceId, x => x.SalePrice, x => x.ListPrice, x => x.Currency, x => x.Quantity,
                                                                                 x => x.ManufacturerPartNumber, x => x.Gtin, x => x.MeasureUnit, x => x.WeightUnit, x => x.Weight,
                                                                                 x => x.Height, x => x.Length, x => x.Width, x => x.TaxType, x => x.ProductType, x => x.ShippingType,
                                                                                 x => x.Vendor, x => x.DownloadType, x => x.DownloadExpiration, x => x.HasUserAgreement);

            retVal.PropertyMaps = requiredFields.Select(x => new CsvProductPropertyMap {
                EntityColumnName = x, CsvColumnName = x, IsRequired = true
            }).ToList();
            retVal.PropertyMaps.AddRange(optionalFields.Select(x => new CsvProductPropertyMap {
                EntityColumnName = x, CsvColumnName = x, IsRequired = false
            }));
            return(retVal);
        }