コード例 #1
0
        protected override void Process()
        {
            _monitoring.Notify(Name, 0);

            var vendorOverridesSetting = GetConfiguration().AppSettings.Settings["VendorIDOverrides"].Try(c => c.Value, string.Empty);

            if (!string.IsNullOrEmpty(vendorOverridesSetting))
            {
                _vendorIDs = (from p in vendorOverridesSetting.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
                              select Convert.ToInt32(p)).ToList();
            }

            var cultureInfoAmerican = CultureInfo.InvariantCulture;
            List <ProductAttributeMetaData> attributes = new List <ProductAttributeMetaData>();

            string connectionString      = string.Empty;
            string stockConnectionString = string.Empty;
            var    pluginConfig          = GetConfiguration();
            var    currentYear           = DateTime.Now.Year;

            using (var unit = GetUnitOfWork())
            {
                connectionString = VendorHelper.GetConnectionStringForPFA(1); //todo: fix vendorid

                CoolcatPFARepository repository = new CoolcatPFARepository(connectionString, stockConnectionString, log);
                AssortmentHelper     helper     = new AssortmentHelper();

                try
                {
                    SetupAttributes(unit, CCAttributeHelper.Attributes, out attributes);
                }
                catch (Exception e)
                {
                    log.Debug(e.InnerException);
                }

                var shopWeekLookup  = repository.GetShopWeekLookup();
                var sizeCodeLookup  = repository.GetSizeCodeLookup();
                var validArtCodes   = repository.GetValidItemNumbers();
                var colorNameLookup = repository.GetColorLookup();
                Dictionary <string, string> colorCodesDict = new Dictionary <string, string>();

                foreach (var vendorID in _vendorIDs)
                {
                    try
                    {
                        _monitoring.Notify(Name, vendorID);
#if DEBUG
                        if (vendorID != 15)
                        {
                            continue;
                        }
#endif

                        Dictionary <string, int> justArrivedCounters = new Dictionary <string, int>();
                        var vendor = unit.Scope.Repository <Vendor>().GetSingle(c => c.VendorID == vendorID);
                        var shouldNotCheckForSolden        = vendor.VendorSettings.GetValueByKey <bool>("NonSoldenVendor", false);
                        var vendorDoesNotImportDescription = vendor.VendorSettings.GetValueByKey <bool>("VendorDoesNotImportDescriptions", false);
                        var countryCode = VendorHelper.GetCountryCode(vendorID);
                        log.Info("Starting import for vendor " + vendor.Name);

                        var connectorID = vendor.ContentProducts.Select(x => x.ConnectorID).FirstOrDefault();

                        bool isSolden;

                        if (shouldNotCheckForSolden)
                        {
                            isSolden = true;
                        }
                        else if (connectorID == null || !GetSoldenPeriod(connectorID, out isSolden))
                        {
                            throw new Exception("Solden period values are corrupt.");
                        }

                        var parentVendorID = vendor.ParentVendorID.HasValue ? vendor.ParentVendorID.Value : vendor.VendorID;

                        var currencyCode = vendor.VendorSettings.FirstOrDefault(c => c.SettingKey == "PFACurrencyCode").Try(c => c.Value, string.Empty);
                        currencyCode.ThrowIfNullOrEmpty(new InvalidOperationException("Missing PFA currency code"));


                        List <Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorAssortmentItem> items          = new List <Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorAssortmentItem>();
                        List <Concentrator.Objects.Vendors.Bulk.VendorBarcodeBulk.VendorImportBarcode>     vendorBarcodes = new List <VendorBarcodeBulk.VendorImportBarcode>();

                        log.Info("Found products in total: " + validArtCodes.Count());

                        int counter = 0;

                        foreach (var itemNumber in validArtCodes)
                        {
                            var productInfo = repository.GetGeneralProductInformation(itemNumber, countryCode);
                            //productInfo.TaxRate = productInfo.TaxRate.Replace("%", string.Empty);
                            var rate = helper.GetCurrentBTWRate(productInfo.TaxRatePercentage, productInfo.TaxRateDates, 21, productInfo.TaxCode);

                            counter++;
                            if (counter % 100 == 0)
                            {
                                log.Info("Found " + counter);
                            }

                            if (!justArrivedCounters.ContainsKey(productInfo.GroupName1))
                            {
                                justArrivedCounters.Add(productInfo.GroupName1, 0);
                            }

                            var priceRules = repository.GetProductPriceRules(itemNumber, currencyCode);

                            if (!string.IsNullOrEmpty(productInfo.override_tax_code))
                            {
                                rate = helper.GetCurrentBTWRate(productInfo.override_tax_rates, productInfo.override_tax_dates, 21, productInfo.override_tax_code);
                            }


                            DateTime?weekShop = null;

                            shopWeekLookup.TryGetValue(itemNumber, out weekShop);

                            Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorAssortmentItem itemToAdd = null;
                            if (itemNumber != PfaCoolcatConfiguration.Current.ShipmentCostsProduct && itemNumber != PfaCoolcatConfiguration.Current.ReturnCostsProduct &&
                                itemNumber != PfaCoolcatConfiguration.Current.KialaShipmentCostsProduct && itemNumber != PfaCoolcatConfiguration.Current.KialaReturnCostsProduct)
                            {
                                itemToAdd = new Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorAssortmentItem
                                {
                                    BrandVendors = new List <VendorAssortmentBulk.VendorImportBrand>()
                                    {
                                        GetVendorBrand(vendorID)
                                    },
                                    VendorProduct               = GetVendorProduct(itemNumber, productInfo.ShortDescription, productInfo.Material, vendorID, parentVendorID, true, productInfo.GroupCode1, productInfo.GroupName1, productInfo.GroupCode2, productInfo.GroupName2, productInfo.GroupCode3, productInfo.GroupName3),
                                    VendorProductDescriptions   = vendorDoesNotImportDescription ? new List <Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorProductDescription>() : GetProductDescriptions(itemNumber, vendorID, parentVendorID, productInfo, _languageIDs),
                                    VendorImportAttributeValues = GetAttributesOnConfigurableLevel(productInfo, itemNumber, attributes, CONCENTRATOR_VENDOR_ID, vendorID),
                                    RelatedProducts             = new List <VendorAssortmentBulk.VendorImportRelatedProduct>(),
                                    VendorImportPrices          = new List <Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorImportPrice>()
                                    {
                                        GetVendorPrice(vendorID, parentVendorID, itemNumber, "0", rate.ToString(cultureInfoAmerican), "0", LEVEL_NOT_EXPORTABLE_STATUS)
                                    },
                                    VendorImportStocks = new List <Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorImportStock>()
                                };
                                items.Add(itemToAdd);
                            }
                            int?shopWeekNumber = null;
                            if (weekShop.HasValue)
                            {
                                Calendar cal = new CultureInfo("nl-NL").Calendar;
                                shopWeekNumber = cal.GetWeekOfYear(weekShop.Value, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Sunday);
                            }

                            if (itemToAdd != null && shopWeekNumber.HasValue)
                            {
                                itemToAdd.VendorImportAttributeValues.Add(new Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorImportAttributeValue()
                                {
                                    AttributeCode    = SHOP_WEEK_ATTRIBUTE_CODE,
                                    Value            = weekShop.Value.Year.ToString() + shopWeekNumber.ToString().PadLeft(2, '0'),
                                    AttributeID      = attributes.FirstOrDefault(c => c.AttributeCode == SHOP_WEEK_ATTRIBUTE_CODE).AttributeID,
                                    CustomItemNumber = itemNumber,
                                    DefaultVendorID  = vendorID,
                                    LanguageID       = null,
                                    VendorID         = CONCENTRATOR_VENDOR_ID
                                });
                            }

                            var skus     = repository.GetValidSkus(itemNumber);
                            var skuSpecs = repository.GetSkuSpecifications(itemNumber);

                            //process color level
                            foreach (var colorLevel in skus.GroupBy(c => c.ColorCode))
                            {
                                var colorItemNumber = string.Format("{0} {1}", itemNumber, colorLevel.Key).Trim();

                                Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorAssortmentItem colorLevelProduct = null;

                                if (itemNumber != PfaCoolcatConfiguration.Current.ShipmentCostsProduct && itemNumber != PfaCoolcatConfiguration.Current.ReturnCostsProduct &&
                                    itemNumber != PfaCoolcatConfiguration.Current.KialaShipmentCostsProduct && itemNumber != PfaCoolcatConfiguration.Current.KialaReturnCostsProduct)
                                {
                                    colorLevelProduct = new Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorAssortmentItem()
                                    {
                                        BrandVendors = new List <VendorAssortmentBulk.VendorImportBrand>()
                                        {
                                            GetVendorBrand(vendorID)
                                        },
                                        VendorProduct               = GetVendorProduct(colorItemNumber, productInfo.ShortDescription, productInfo.Material, vendorID, parentVendorID, true, productInfo.GroupCode1, productInfo.GroupName1, productInfo.GroupCode2, productInfo.GroupName2, productInfo.GroupCode3, productInfo.GroupName3, parentCustomItemNumber: itemNumber),
                                        VendorProductDescriptions   = vendorDoesNotImportDescription ? new List <Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorProductDescription>() : GetProductDescriptions(colorItemNumber, vendorID, parentVendorID, productInfo, _languageIDs),
                                        VendorImportAttributeValues = GetAttributesOnConfigurableLevel(productInfo, colorItemNumber, attributes, CONCENTRATOR_VENDOR_ID, vendorID),
                                        RelatedProducts             = new List <VendorAssortmentBulk.VendorImportRelatedProduct>(
                                            (from rp in skus.GroupBy(c => c.ColorCode)
                                             where rp.Key != colorLevel.Key
                                             select new Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorImportRelatedProduct()
                                        {
                                            CustomItemNumber = colorItemNumber,
                                            DefaultVendorID = vendorID,
                                            VendorID = vendorID,
                                            IsConfigured = 0,
                                            RelatedCustomItemNumber = string.Format("{0} {1}", itemNumber, rp.Key).Trim(),
                                            RelatedProductType = "Related Color Level"
                                        }).ToList()
                                            ),
                                        VendorImportPrices = new List <Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorImportPrice>()
                                        {
                                            GetVendorPrice(vendorID, parentVendorID, colorItemNumber, "0", rate.ToString(cultureInfoAmerican), "0")
                                        },
                                        VendorImportStocks = new List <Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorImportStock>()
                                    };

                                    if (colorLevelProduct != null && shopWeekNumber.HasValue)
                                    {
                                        colorLevelProduct.VendorImportAttributeValues.Add(new Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorImportAttributeValue()
                                        {
                                            AttributeCode    = SHOP_WEEK_ATTRIBUTE_CODE,
                                            Value            = weekShop.Value.Year.ToString() + shopWeekNumber.ToString().PadLeft(2, '0'),
                                            AttributeID      = attributes.FirstOrDefault(c => c.AttributeCode == SHOP_WEEK_ATTRIBUTE_CODE).AttributeID,
                                            CustomItemNumber = colorItemNumber,
                                            DefaultVendorID  = vendorID,
                                            LanguageID       = null,
                                            VendorID         = CONCENTRATOR_VENDOR_ID
                                        });
                                    }

                                    items.Add(colorLevelProduct);

                                    if (itemToAdd != null)
                                    {
                                        itemToAdd.RelatedProducts.Add(new VendorAssortmentBulk.VendorImportRelatedProduct()
                                        {
                                            CustomItemNumber        = itemNumber,
                                            RelatedCustomItemNumber = colorItemNumber,
                                            IsConfigured            = 0,
                                            DefaultVendorID         = parentVendorID,
                                            VendorID           = vendorID,
                                            RelatedProductType = "Style"
                                        });
                                    }
                                }

                                if (justArrivedCounters[productInfo.GroupName1] < 60)
                                {
                                    if (weekShop.HasValue)
                                    {
                                        var daysInRange = (DateTime.Now - weekShop.Value).Days;
                                        if (daysInRange >= 0 && daysInRange <= 14)
                                        {
                                            if (colorLevelProduct != null)
                                            {
                                                colorLevelProduct.VendorProduct.VendorProductGroupCode4 = "Just arrived";

                                                colorLevelProduct.VendorProduct.VendorProductGroupCodeName4 = "Just arrived";
                                                justArrivedCounters[productInfo.GroupName1]++;
                                            }
                                        }
                                    }
                                }

                                foreach (var sku in colorLevel)
                                {
                                    var skuBarcode = CompleteBarcode(sku.Barcode);

                                    int webshopStock  = 0;
                                    int ceyenneStock  = 0;
                                    int transferStock = 0;
                                    int wmsStock      = 0;

                                    string sizeCodePfa = sku.SizeCode;

                                    foreach (var lookupT in new List <string>()
                                    {
                                        productInfo.MtbCode1, productInfo.MtbCode2, productInfo.MtbCode3, productInfo.MtbCode4
                                    })
                                    {
                                        var lookup = sizeCodeLookup.FirstOrDefault(c => c.SizeCode.ToLower() == sku.SizeCode.ToLower() && c.MtbCode.ToLower() == lookupT.ToLower());
                                        if (lookup != null)
                                        {
                                            sizeCodePfa = lookup.PfaCode;
                                            break;
                                        }
                                    }

                                    var product = new Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorAssortmentItem();

                                    string skuNew = string.Empty;
                                    if (itemNumber == PfaCoolcatConfiguration.Current.ShipmentCostsProduct || itemNumber == PfaCoolcatConfiguration.Current.ReturnCostsProduct ||
                                        itemNumber == PfaCoolcatConfiguration.Current.KialaShipmentCostsProduct || itemNumber == PfaCoolcatConfiguration.Current.KialaReturnCostsProduct)
                                    {
                                        skuNew = itemNumber;
                                    }
                                    else
                                    {
                                        skuNew = string.Format("{0} {1} {2}", itemNumber, sku.ColorCode, sku.SizeCode);
                                    }

                                    Concentrator.Objects.Vendors.Bulk.VendorBarcodeBulk.VendorImportBarcode bc = new VendorBarcodeBulk.VendorImportBarcode()
                                    {
                                        CustomItemNumber = skuNew,
                                        Barcode          = sizeCodePfa,
                                        Type             = 4,
                                        VendorID         = 1
                                    };

                                    vendorBarcodes.Add(bc);

                                    var price    = helper.GetPrice(itemNumber, sku.ColorCode, sku.SizeCode, priceRules);
                                    var discount = helper.GetDiscount(itemNumber, sku.ColorCode, sku.SizeCode, priceRules);

                                    if (!isSolden)
                                    {
                                        if (discount.HasValue)
                                        {
                                            price    = discount.Value;
                                            discount = null;
                                        }
                                    }

                                    var item = items.Where(c => c.VendorProduct.CustomItemNumber == itemNumber);
                                    if (item == null)
                                    {
                                        continue;
                                    }


                                    product = new Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorAssortmentItem()
                                    {
                                        VendorProduct             = GetVendorProduct(skuNew, productInfo.ShortDescription, productInfo.LongDescription, vendorID, parentVendorID, false, productInfo.GroupCode1, productInfo.GroupName1, productInfo.GroupCode2, productInfo.GroupName2, productInfo.GroupCode3, productInfo.GroupName3, parentCustomItemNumber: colorItemNumber, barcode: skuBarcode),
                                        VendorProductDescriptions = vendorDoesNotImportDescription ? new List <Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorProductDescription>() : GetProductDescriptions(skuNew, vendorID, parentVendorID, productInfo, _languageIDs),
                                        BrandVendors = new List <VendorAssortmentBulk.VendorImportBrand>()
                                        {
                                            GetVendorBrand(vendorID)
                                        },
                                        VendorImportAttributeValues = (from m in CCAttributeHelper.Attributes
                                                                       where m.Configurable
                                                                       let aM = attributes.FirstOrDefault(c => c.AttributeCode.ToLower() == m.Code.ToLower())
                                                                                select new Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorImportAttributeValue
                                        {
                                            AttributeCode = aM.AttributeCode,
                                            AttributeID = aM.AttributeID,
                                            CustomItemNumber = skuNew,
                                            DefaultVendorID = vendorID,
                                            LanguageID = null,
                                            VendorID = CONCENTRATOR_VENDOR_ID,
                                            Value = (m.Code.ToLower() == "color" ? sku.ColorCode : sku.SizeCode)
                                        }).ToList(),

                                        RelatedProducts    = new List <VendorAssortmentBulk.VendorImportRelatedProduct>(),
                                        VendorImportPrices = new List <Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorImportPrice>()
                                        {
                                            GetVendorPrice(vendorID, parentVendorID, skuNew, price.ToString(cultureInfoAmerican), rate.ToString(cultureInfoAmerican), (discount.HasValue && discount.Value < price)? discount.Value.ToString(cultureInfoAmerican) :null)
                                        },

                                        VendorImportStocks = new List <Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorImportStock>()
                                    };


                                    if ((discount.HasValue && discount.Value > 0) && (price != discount))
                                    {
                                        if (itemToAdd != null)
                                        {
                                            //That is because code4 might be filled with just arrived
                                            if (string.IsNullOrEmpty(colorLevelProduct.VendorProduct.VendorProductGroupCode4))
                                            {
                                                colorLevelProduct.VendorProduct.VendorProductGroupCode4     = "SALE";
                                                colorLevelProduct.VendorProduct.VendorProductGroupCodeName4 = "SALE";
                                            }
                                            else
                                            {
                                                colorLevelProduct.VendorProduct.VendorProductGroupCode5     = "SALE";
                                                colorLevelProduct.VendorProduct.VendorProductGroupCodeName5 = "SALE";
                                            }

                                            if (string.IsNullOrEmpty(itemToAdd.VendorProduct.VendorProductGroupCode4))
                                            {
                                                itemToAdd.VendorProduct.VendorProductGroupCode4     = "SALE";
                                                itemToAdd.VendorProduct.VendorProductGroupCodeName4 = "SALE";
                                            }
                                            else
                                            {
                                                itemToAdd.VendorProduct.VendorProductGroupCode5     = "SALE";
                                                itemToAdd.VendorProduct.VendorProductGroupCodeName5 = "SALE";
                                            }

                                            if (string.IsNullOrEmpty(product.VendorProduct.VendorProductGroupCode4))
                                            {
                                                product.VendorProduct.VendorProductGroupCode4     = "SALE";
                                                product.VendorProduct.VendorProductGroupCodeName4 = "SALE";
                                            }
                                            else
                                            {
                                                product.VendorProduct.VendorProductGroupCode5     = "SALE";
                                                product.VendorProduct.VendorProductGroupCodeName5 = "SALE";
                                            }
                                        }
                                    }

                                    var attributeColorRows = skuSpecs.Where(c => c.ColorCode == sku.ColorCode).ToList();

                                    var mentality  = GetAttributeValue(attributeColorRows, "Mentality");
                                    var input      = GetAttributeValue(attributeColorRows, "Input");
                                    var Style      = GetAttributeValue(attributeColorRows, "Style");
                                    var Usermoment = GetAttributeValue(attributeColorRows, "Usermoment");
                                    var Module     = GetAttributeValue(attributeColorRows, "Module");

                                    AddAttributeValue(itemToAdd, "Mentality", mentality, attributes, itemNumber, CONCENTRATOR_VENDOR_ID, vendorID);
                                    AddAttributeValue(itemToAdd, "Style", Style, attributes, itemNumber, CONCENTRATOR_VENDOR_ID, vendorID);
                                    AddAttributeValue(itemToAdd, "Usermoment", Usermoment, attributes, itemNumber, CONCENTRATOR_VENDOR_ID, vendorID);
                                    AddAttributeValue(product, "Module", Module, attributes, skuNew, CONCENTRATOR_VENDOR_ID, vendorID);
                                    AddAttributeValue(itemToAdd, "InputCode", input, attributes, itemNumber, CONCENTRATOR_VENDOR_ID, vendorID);
                                    AddAttributeValue(itemToAdd, "Gender", DetermineGenderByVendorItemNumber(itemNumber), attributes, itemNumber, CONCENTRATOR_VENDOR_ID, vendorID);

                                    items.Add(product);
                                    if (colorLevelProduct != null)
                                    {
                                        //relate to main product
                                        if (colorLevelProduct.RelatedProducts.Where(c => c.CustomItemNumber == colorItemNumber && c.RelatedCustomItemNumber == skuNew).FirstOrDefault() == null)
                                        {
                                            colorLevelProduct.RelatedProducts.Add(new VendorAssortmentBulk.VendorImportRelatedProduct()
                                            {
                                                CustomItemNumber        = colorItemNumber,
                                                DefaultVendorID         = parentVendorID,
                                                IsConfigured            = 1,
                                                RelatedCustomItemNumber = skuNew,
                                                RelatedProductType      = "Configured product",
                                                VendorID = vendorID
                                            });
                                        }
                                    }
                                }
                            }
                        }

                        var bulkConfig = new VendorAssortmentBulkConfiguration();
                        using (var vendorAssortmentBulk = new VendorAssortmentBulk(items, vendorID, parentVendorID, bulkConfig))
                        {
                            vendorAssortmentBulk.Init(unit.Context);
                            vendorAssortmentBulk.Sync(unit.Context);
                        }

                        using (var barcodeBulk = new VendorBarcodeBulk(vendorBarcodes, vendorID, 4))
                        {
                            barcodeBulk.Init(unit.Context);
                            barcodeBulk.Sync(unit.Context);
                        }
                    }
                    catch (Exception e)
                    {
                        log.AuditCritical("Import failed for vendor " + vendorID, e);
                        _monitoring.Notify(Name, -vendorID);
                    }
                }
                AddValueLabels(unit, colorCodesDict);
                ConfigureProductAttributes(_vendorIDs, unit);
            }
            _monitoring.Notify(Name, 1);
        }
コード例 #2
0
        protected override List <VendorStockCollectionModel> GetStock()
        {
            List <Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorImportStock> result = new List <Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorImportStock>();
            var pluginConfig = GetConfiguration();

            var connectionString      = VendorHelper.GetConnectionStringForPFA(1);//todo vendorid
            var stockConnectionString = PFAConnectionHelper.GetCoolcatPFAVrdsConnection(pluginConfig);

            CoolcatPFARepository repository         = new CoolcatPFARepository(connectionString, stockConnectionString, log);
            AssortmentHelper     helper             = new AssortmentHelper();
            XDocument            seasonCodeRulesDoc = null;
            DateTime?            datcolTimeStamp    = null;

            bool datcolSuccessful = true;

            //if the vrds was not process, exit
            if (!IsVrdsValid(repository))
            {
                return(null);
            }

            using (var unit = GetUnitOfWork())
            {
                seasonCodeRulesDoc = GetCategoryStockBlacklist(unit);
                datcolSuccessful   = WasDatcolRunSuccessful(unit);


                var currentStockDate = helper.GetCurrentStockDate();
                var stockCM          = repository.GetCMStock(currentStockDate);
                var stockTransfer    = repository.GetTransferStock(currentStockDate);
                var stockWms         = repository.GetWmsStock(currentStockDate);
                var validArtCodes    = repository.GetValidItemNumbers();
                var stockWehkamp     = repository.GetWehkampStock(currentStockDate);
                var countryCode      = VendorHelper.GetCountryCode(1);
                log.Info(string.Format("About to process the stock of {0} artikels", validArtCodes.Count));
                int counter = 0;

                foreach (var itemNumber in validArtCodes)
                {
                    counter++;
                    if (counter % 100 == 0)
                    {
                        log.Info(string.Format("Processed {0} products", counter));
                    }
                    var productInfo = repository.GetGeneralProductInformation(itemNumber, countryCode);

                    bool loadCMStock = true;

                    if (seasonCodeRulesDoc != null)
                    {
                        if (IsGroupFiltered(itemNumber, productInfo.SeasonCode, seasonCodeRulesDoc))
                        {
                            loadCMStock = false;
                        }
                    }

                    var artikelStockCM = (from p in stockCM
                                          where p.ItemNumber.ToLower() == itemNumber.ToLower()
                                          select p).ToList();

                    var artikelStockWMS = (from p in stockWms
                                           where p.ItemNumber.ToLower() == itemNumber.ToLower()
                                           select p).ToList();

                    var artikelStockWehkamp = (from p in stockWehkamp
                                               where p.ItemNumber.ToLower() == itemNumber.ToLower()
                                               select p).ToList();

                    var artikelStockTransfer = (from p in stockTransfer
                                                where p.ItemNumber.ToLower() == itemNumber.ToLower()
                                                select p).ToList();

                    result.Add(GetVendorStock(itemNumber, 0, CCStockType.Webshop));
                    result.Add(GetVendorStock(itemNumber, 0, CCStockType.CM));
                    result.Add(GetVendorStock(itemNumber, 0, CCStockType.Transfer));
                    result.Add(GetVendorStock(itemNumber, 0, CCStockType.Wehkamp));
                    result.Add(GetVendorStock(itemNumber, 0, CCStockType.Filiaal890));

                    var validSkus = repository.GetValidSkus(itemNumber);

                    foreach (var color in validSkus.GroupBy(c => c.ColorCode))
                    {
                        string colorLevel = string.Format("{0} {1}", itemNumber, color.Key);

                        result.Add(GetVendorStock(colorLevel, 0, CCStockType.Webshop));
                        result.Add(GetVendorStock(colorLevel, 0, CCStockType.CM));
                        result.Add(GetVendorStock(colorLevel, 0, CCStockType.Transfer));
                        result.Add(GetVendorStock(colorLevel, 0, CCStockType.Wehkamp));
                        result.Add(GetVendorStock(colorLevel, 0, CCStockType.Filiaal890));
                    }

                    foreach (var sku in validSkus)
                    {
                        string skuNew = string.Empty;
                        if (itemNumber == PfaCoolcatConfiguration.Current.ShipmentCostsProduct || itemNumber == PfaCoolcatConfiguration.Current.ReturnCostsProduct ||
                            itemNumber == PfaCoolcatConfiguration.Current.KialaShipmentCostsProduct || itemNumber == PfaCoolcatConfiguration.Current.KialaReturnCostsProduct)
                        {
                            skuNew = itemNumber;
                        }
                        else
                        {
                            skuNew = string.Format("{0} {1} {2}", itemNumber, sku.ColorCode, sku.SizeCode);
                        }

                        int webshopStock  = 0;
                        int ceyenneStock  = 0;
                        int transferStock = 0;
                        int wmsStock      = 0;
                        int wehkampStock  = 0;

                        transferStock = GetSkuStockResult(artikelStockTransfer, sku).Try(c => c.Quantity, 0);
                        ceyenneStock  = (int)(0.5 * GetSkuStockResult(artikelStockCM, sku).Try(c => c.Quantity, 0));
                        wehkampStock  = GetSkuStockResult(artikelStockWehkamp, sku).Try(c => c.Quantity, 0);

                        if (ceyenneStock < 30)
                        {
                            ceyenneStock = 0;
                        }

                        wmsStock = GetSkuStockResult(artikelStockWMS, sku).Try(c => c.Quantity, 0);

                        if (!datcolSuccessful)
                        {
                            //What do we do with the vendorid here?
                            var w = unit.Scope.Repository <VendorStock>().GetAllAsQueryable(c => c.VendorID == 1 && c.VendorStockTypeID == 3 && c.Product.VendorItemNumber == skuNew).FirstOrDefault();

                            wmsStock = 0;
                            if (w != null)
                            {
                                wmsStock = w.QuantityOnHand;
                            }
                        }

                        webshopStock = ceyenneStock + wmsStock + transferStock;

                        if (!loadCMStock)
                        {
                            webshopStock = webshopStock - ceyenneStock;
                            ceyenneStock = 0;
                        }

                        result.Add(GetVendorStock(skuNew, webshopStock, CCStockType.Webshop));
                        result.Add(GetVendorStock(skuNew, ceyenneStock, CCStockType.CM));
                        result.Add(GetVendorStock(skuNew, transferStock, CCStockType.Transfer));
                        result.Add(GetVendorStock(skuNew, wehkampStock, CCStockType.Wehkamp));

                        if (datcolSuccessful)
                        {
                            result.Add(GetVendorStock(skuNew, wmsStock, CCStockType.Filiaal890));
                        }
                    }
                }
            }

            List <VendorStockCollectionModel> groupedResult = new List <VendorStockCollectionModel>();

            //for the regular vendors add all stock locations without Wehkamp
            foreach (var vendor in _vendorIDs)
            {
                groupedResult.Add(new VendorStockCollectionModel()
                {
                    VendorID        = vendor,
                    DefaultVendorID = 1,
                    StockCollection = result.Where(c => c.StockType != CCStockType.Wehkamp.ToString()).ToList()
                });
            }


            var wehkampStockCollection = result.Where(c => c.StockType == CCStockType.Wehkamp.ToString()).ToList();

            //For vendor Wehkamp, add the stock the webshop location for exporting
            wehkampStockCollection.AddRange((from r in wehkampStockCollection
                                             select GetVendorStock(r.CustomItemNumber, r.QuantityOnHand, CCStockType.Webshop)).ToList());

            //wehkamp
            groupedResult.Add(new VendorStockCollectionModel()
            {
                VendorID        = _wehkampVendorID,
                DefaultVendorID = 1,
                StockCollection = wehkampStockCollection
            });

            return(groupedResult);
        }