Exemple #1
0
        public ProductImporter(IUnitOfWork uow, OnlineStoreNomenclatureFactory onlineStoreNomenclatureFactory, Dictionary <string, ProductGroup> productGroups, ProductGroup unknownGroup)
        {
            this.uow = uow ?? throw new ArgumentNullException(nameof(uow));
            this.onlineStoreNomenclatureFactory = onlineStoreNomenclatureFactory ?? throw new ArgumentNullException(nameof(onlineStoreNomenclatureFactory));
            this.productGroups       = productGroups ?? throw new ArgumentNullException(nameof(productGroups));
            this.unknownProductGroup = unknownGroup ?? throw new ArgumentNullException(nameof(unknownGroup));

            LoadNomenclatures();
        }
        private void LoadNomenclatures(IDictionary <object, object> productsData)
        {
            using (IUnitOfWork uow = UnitOfWorkFactory.CreateWithoutRoot())
            {
                CategoryImporter categoryImporter = new CategoryImporter(uow);
                var rootGroupId         = nomenclatureParametersProvider.RootProductGroupForOnlineStoreNomenclatures;
                var rootGroup           = uow.GetById <ProductGroup>(rootGroupId);
                var unknownProductGroup = GetUnknownProductGroup(uow, rootGroup);

                var categories   = (JObject)productsData["category"];
                var resultGroups = categoryImporter.ImportCategories(categories, onlineStoreId, rootGroup);
                uow.Commit();

                OnlineStoreNomenclatureFactory onlineStoreNomenclatureFactory = new OnlineStoreNomenclatureFactory(nomenclatureParametersProvider, nomenclatureRepository);
                ProductImporter productImporter = new ProductImporter(uow, onlineStoreNomenclatureFactory, resultGroups, unknownProductGroup);
                var             products        = (JArray)productsData["product"];
                productImporter.LoadProducts(products, onlineStoreId);
            }
        }