Exemplo n.º 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);
        }
Exemplo n.º 2
0
        protected override void Process()
        {
            foreach (Vendor vendor in Vendors.Where(x => ((VendorType)x.VendorType).Has(VendorType.Barcodes) && x.IsActive))
            {
                try
                {
                    if (vendor.VendorSettings.GetValueByKey <int>("AssortmentImportID", 0) < 1)
                    {
                        continue;
                    }

                    log.DebugFormat("Start Barcodes Import for Vendor '{0} ({1})'", vendor.Name, vendor.VendorID);

                    using (var unit = GetUnitOfWork())
                    {
                        DataSet barcodes = new DataSet();

                        using (JdeAssortmentSoapClient cl = new JdeAssortmentSoapClient())
                        {
                            barcodes = cl.GetBarcodes();

                            var dataList = (from b in barcodes.Tables[0].AsEnumerable()
                                            where VendorImportUtility.SetDataSetValue("ivxrt", b) != "DC"
                                            select new Concentrator.Objects.Vendors.Bulk.VendorBarcodeBulk.VendorImportBarcode
                            {
                                Barcode = VendorImportUtility.SetDataSetValue("IVCITM", b),
                                CustomItemNumber = VendorImportUtility.SetDataSetValue("IVITM", b),
                                Type = 0,
                                VendorID = vendor.ParentVendorID.HasValue ? vendor.ParentVendorID.Value : vendor.VendorID
                            }).AsEnumerable();

                            using (var vendorAssortmentBulk = new VendorBarcodeBulk(dataList, vendor.ParentVendorID.HasValue ? vendor.ParentVendorID.Value : vendor.VendorID, 0))
                            {
                                vendorAssortmentBulk.Init(unit.Context);
                                vendorAssortmentBulk.Sync(unit.Context);
                            }

                            var sapDataList = (from b in barcodes.Tables[0].AsEnumerable()
                                               where VendorImportUtility.SetDataSetValue("ivxrt", b) == "DC"
                                               select new Concentrator.Objects.Vendors.Bulk.VendorBarcodeBulk.VendorImportBarcode
                            {
                                Barcode = VendorImportUtility.SetDataSetValue("IVCITM", b),
                                CustomItemNumber = VendorImportUtility.SetDataSetValue("IVITM", b),
                                Type = 3,
                                VendorID = vendor.ParentVendorID.HasValue ? vendor.ParentVendorID.Value : vendor.VendorID
                            }).AsEnumerable();

                            using (var vendorAssortmentBulk = new VendorBarcodeBulk(sapDataList, vendor.ParentVendorID.HasValue ? vendor.ParentVendorID.Value : vendor.VendorID, 3))
                            {
                                vendorAssortmentBulk.Init(unit.Context);
                                vendorAssortmentBulk.Sync(unit.Context);
                            }
                        }
                    }

                    log.DebugFormat("Finished Barcode Import for vendor '{0} ({1})'", vendor.Name, vendor.VendorID);
                }
                catch (Exception ex)
                {
                    log.Error("Error import BAS assortment", ex);
                }
            }
        }