示例#1
0
        private void TransformListPrice(CommerceContext commerceContext, ImportSellableItemsPolicy importPolicy, string[] rawFields, SellableItem item)
        {
            var listPrices = rawFields[ListPriceIndex].Split(new string[] { importPolicy.FileRecordSeparator }, StringSplitOptions.RemoveEmptyEntries);

            if (listPrices == null || listPrices.Count() == 0)
            {
                commerceContext.Logger.LogWarning($"Warning, Product with id '{item.ProductId}' does not contain a list price. Has value '{rawFields[ListPriceIndex]}'");
                return;
            }

            var priceList = new List <Money>();

            foreach (var listPrice in listPrices)
            {
                var priceData = listPrice.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries);
                if (priceData.Count() != 2)
                {
                    commerceContext.Logger.LogWarning($"Warning, Product with id '{item.ProductId}' does not contain a list price. Has value '{rawFields[ListPriceIndex]}'");
                    continue;
                }
                priceList.Add(new Money
                {
                    CurrencyCode = priceData[ListPriceCurrencyCodeIndex],
                    Amount       = decimal.Parse(priceData[ListPriceAmountIndex])
                });
            }

            if (!priceList.Any())
            {
                return;
            }

            item.Policies.Add(new ListPricingPolicy(priceList));
        }
示例#2
0
        private void LogInitialization(CommercePipelineExecutionContext context, ImportSellableItemsPolicy policy)
        {
            var log = new StringBuilder();

            log.AppendLine($"{System.Environment.NewLine}");
            log.AppendLine($"{GetType().Name} - Starting");
            log.AppendLine($"Settings:");
            log.AppendLine($"\t {nameof(policy.ItemsPerBatch)} = {policy.ItemsPerBatch}");
            log.AppendLine($"\t {nameof(policy.SleepBetweenBatches)} = {policy.SleepBetweenBatches}");
            log.AppendLine($"\t {nameof(policy.FileFolderPath)}  = {policy.FileFolderPath}");
            log.AppendLine($"\t {nameof(policy.FileArchiveFolderPath)}  = {policy.FileArchiveFolderPath}");
            log.AppendLine($"\t {nameof(policy.FilePrefix)}  = {policy.FilePrefix}");
            log.AppendLine($"\t {nameof(policy.FileExtention)}  = {policy.FileExtention}");
            log.AppendLine($"\t {nameof(policy.FileRecordSeparator)}  = {policy.FileRecordSeparator}");

            context.Logger.LogInformation(log.ToString());
        }
示例#3
0
        private void TransformTransientData(ImportSellableItemsPolicy importPolicy, string[] rawFields, SellableItem item, List <TransientImportSellableItemDataPolicy> transientDataList)
        {
            var data = new TransientImportSellableItemDataPolicy
            {
                ImageNameList = rawFields[ImagesIndex].Split(new string[] { importPolicy.FileRecordSeparator }, StringSplitOptions.None)
            };

            var catalogRecord = rawFields[CatalogNameIndex].Split(new string[] { importPolicy.FileRecordSeparator }, StringSplitOptions.None).ToList();

            foreach (var catalogUnit in catalogRecord)
            {
                data.CatalogAssociationList.Add(new CatalogAssociationModel {
                    Name = catalogUnit
                });
            }

            var catalogCategoryRecord = rawFields[CategoryNameIndex].Split(new string[] { importPolicy.FileRecordSeparator }, StringSplitOptions.RemoveEmptyEntries).ToList();

            foreach (var catalogCategoryUnit in catalogCategoryRecord)
            {
                var units = catalogCategoryUnit.Split(new string[] { importPolicy.FileUnitSeparator }, StringSplitOptions.RemoveEmptyEntries);
                if (units == null || units.Count() != 2)
                {
                    throw new Exception("Error, unexpected value in CategoryNameIndex");
                }
                data.CategoryAssociationList.Add(new CategoryAssociationModel {
                    CatalogName = units[0], CategoryName = units[1]
                });
            }

            // Determine if sellable-item should be associated to catalog directly
            foreach (var catalogAssoication in data.CatalogAssociationList)
            {
                if (!data.CategoryAssociationList.Any(c => c.CatalogName.Equals(catalogAssoication.Name)))
                {
                    catalogAssoication.IsParent = true;
                }
            }

            item.Policies.Add(data);
            transientDataList.Add(data);
        }