コード例 #1
0
        public ActionResult GetAll()
        {
            using (var unit = GetUnitOfWork())
            {
                var repo = new ProductModelRepository(unit, _defaultVendorID);

                var types = unit.Service <Product>().GetAll(c => _vendorIDs.Any(x => x == c.SourceVendorID) && c.IsConfigurable)
                            .Select(c => c.VendorItemNumber)
                            .ToList()
                            .Select(c => c.Split(new char[] { '-' }).Try(l => l[0], string.Empty))
                            .Distinct()
                            .ToList();

                var filledIn = repo.GetAll();

                return(List((from p in types
                             where !string.IsNullOrEmpty(p)
                             let existing = filledIn.FirstOrDefault(c => c.ModelCode == p)
                                            select new ModelDescriptionModel()
                {
                    ModelCode = p,
                    Translation = existing == null ? string.Empty : existing.Translation
                }).AsQueryable()));
            }
        }
コード例 #2
0
        public static ProductModelRepository GetProductModelRepository(IUnitOfWork unitOfWork)
        {
            var repository = new ProductModelRepository();

            repository.UnitOfWork = unitOfWork;
            return(repository);
        }
コード例 #3
0
 public ProdeuctModelManager()
 {
     _generalCategoryRepository = new GeneralCategoryRepository();
     _categoryRepository        = new CategoryRepository();
     _subCategoryRepository     = new SubCategoryRepository();
     _productModelRepository    = new ProductModelRepository();
 }
コード例 #4
0
        public ProviderMutation(ProductModelRepository productModelRepository, ProductRepository productRepository)
        {
            FieldAsync <ProductModelType>(
                "createModel",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <ProductModelInputType> > {
                Name = "model"
            }),
                resolve: async context =>
            {
                var model = context.GetArgument <ProductModel>("model");
                return(await context.TryAsyncResolve(
                           async c => await productModelRepository.AddProductModel(model)));
            }
                );

            FieldAsync <ProductType>(
                "createProduct",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <ProductInputType> > {
                Name = "product"
            }),
                resolve: async context =>
            {
                var product = context.GetArgument <Product>("product");
                return(await context.TryAsyncResolve(
                           async c => await productRepository.AddProduct(product)));
            }
                );
        }
コード例 #5
0
        public Product GetProduct(Product product)
        {
            IRepositoryBase <ProductCategory> repositoryCategory = new ProductCategoryRepository();

            product.ProductCategoryCollection = repositoryCategory.GetAll().ToList();
            IRepositoryBase <ProductSubCategory> repositorySubCategory = new ProductSubCategoryRepository();

            product.ProductSubCategoryCollection = repositorySubCategory.GetAll().ToList();
            IRepositoryBase <ProductModel> repositoryProductModel = new ProductModelRepository();

            product.ProductModelCollection = repositoryProductModel.GetAll().ToList();
            return(product);
        }
コード例 #6
0
        /// <summary>
        /// Occurs when RunWorkerAsync is called.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="DoWorkEventArgs"/> instance containing the event data.</param>
        private void LoadProductModelsBackground(object sender, DoWorkEventArgs e)
        {
            IProductModelRepository productModelRepository = new ProductModelRepository();

            BackgroundWorker source = (BackgroundWorker)sender;

            var results = productModelRepository.GetAllProductModels();
            int index   = 0;

            foreach (var item in results)
            {
                Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, new Action(delegate { }));
                source.ReportProgress(++index, item);
            }
        }
コード例 #7
0
        public ActionResult Delete(string id)
        {
            try
            {
                using (var unit = GetUnitOfWork())
                {
                    var repo = new ProductModelRepository(unit, _defaultVendorID);
                    repo.Delete(id);
                }

                return(Success("Successfully removed type"));
            }
            catch (Exception e)
            {
                return(Failure("Something went wrong ", e));
            }
        }
コード例 #8
0
        public ActionResult Update(string _ModelCode, string Translation)
        {
            try
            {
                using (var unit = GetUnitOfWork())
                {
                    var repo = new ProductModelRepository(unit, _defaultVendorID);
                    repo.Update(_ModelCode, Translation);
                }

                return(Success("Successfully added type"));
            }
            catch (Exception e)
            {
                return(Failure("Something went wrong ", e));
            }
        }
コード例 #9
0
        public ActionResult Create(ModelDescriptionModel model)
        {
            try
            {
                using (var unit = GetUnitOfWork())
                {
                    var repo = new ProductModelRepository(unit, _defaultVendorID);
                    repo.Add(model);
                }

                return(Success("Successfully added type"));
            }
            catch (Exception e)
            {
                return(Failure("Something went wrong ", e));
            }
        }
コード例 #10
0
        public ActionResult Update(ProductModel products)
        {
            var prod = new ProductModelRepository().Products.ToList().Find(x => x.ProductId.Equals(products.ProductId));

            if (prod != null)
            {
                prod.ProductName  = products.ProductName;
                prod.UnitPrice    = products.UnitPrice;
                prod.UnitsInStock = products.UnitsInStock;
                prod.Discontinued = products.Discontinued;
                if (products.ProductCategory != null)
                {
                    prod.ProductCategory =
                        new ProductModelRepository().ProductCategories.ToList()
                        .Find(x => x.ProductCategoryId.Equals(products.ProductCategory.ProductCategoryId));
                }
            }

            return(Json(null));
        }
コード例 #11
0
        public ProviderQuery(ProductRepository productRepository, ProductModelRepository productModelRepository)
        {
            Field <ListGraphType <ProductType> >(
                "products",
                arguments: new QueryArguments(new QueryArgument <IdGraphType> {
                Name = "id"
            }),
                resolve: context =>
            {
                var _productId = context.GetArgument <int?>("id");
                return(_productId == null ? productRepository.GetAll() : productRepository.GetById(_productId.Value));
            });

            Field <ListGraphType <ProductModelType> >(
                "productModels",
                arguments: new QueryArguments(new QueryArgument <IdGraphType> {
                Name = "id"
            }),
                resolve: context =>
            {
                var _productModelId = context.GetArgument <int?>("id");
                return(_productModelId == null ? productModelRepository.GetAll() : productModelRepository.GetById(_productModelId.Value));
            });
        }
コード例 #12
0
        public ActionResult ReadCategories()
        {
            var products = new ProductModelRepository().ProductCategories;

            return(Json(products));
        }
コード例 #13
0
        protected override void Process()
        {
            var defaultVendorIDSetting = GetConfiguration().AppSettings.Settings["VendorID"];

            if (defaultVendorIDSetting == null)
            {
                throw new Exception("Setting VendorID is missing");
            }

            DefaultVendorID = Int32.Parse(defaultVendorIDSetting.Value);

            var vendorIdsToProcess = GetConfiguration().AppSettings.Settings["VendorIDs"];

            if (vendorIdsToProcess == null)
            {
                throw new Exception("Setting VendorIDs is missing");
            }

            _vendorIDs = vendorIdsToProcess.Value.Split(',').Select(x => Convert.ToInt32(x)).ToArray();

            var attributes = new List <ProductAttributeMetaData>();

            using (var unit = GetUnitOfWork())
            {
                try
                {
                    InitAttributeMapping();
                    SetupAttributes(unit, _attributeMapping, DefaultVendorID, out attributes);
                }
                catch (Exception e)
                {
                    log.Debug(e.InnerException);
                }

                foreach (var vendorID in _vendorIDs)
                {
                    _configuredAttributes = new Dictionary <string, List <string> >();



                    var repositoryProductTypes = new ProductTypeRepository((IServiceUnitOfWork)unit, DefaultVendorID);
                    var repositoryModels       = new ProductModelRepository((IServiceUnitOfWork)unit, DefaultVendorID);

                    bool useAdvicePrice        = false;
                    var  useAdvicePriceSetting = unit.Scope.Repository <VendorSetting>().GetSingle(c => c.VendorID == vendorID && c.SettingKey == USE_ADVICE_PRICE_FROM_XML_SETTING_KEY);
                    if (useAdvicePriceSetting != null)
                    {
                        bool.TryParse(useAdvicePriceSetting.Value, out useAdvicePrice);
                    }


                    var ReturnCostsVendorItemNumber = unit.Scope.Repository <VendorSetting>().GetSingle(c => c.VendorID == vendorID && c.SettingKey == "ReturnCostsProduct");
                    if (ReturnCostsVendorItemNumber != null)
                    {
                        ReturnVendorItemNumber = ReturnCostsVendorItemNumber.Value;
                    }

                    var ShipmentCostsVendorItemNumber = unit.Scope.Repository <VendorSetting>().GetSingle(c => c.VendorID == vendorID && c.SettingKey == "ShipmentCostsProduct");
                    if (ShipmentCostsVendorItemNumber != null)
                    {
                        ShipmentVendorItemNumber = ShipmentCostsVendorItemNumber.Value;
                    }

                    foreach (var attributeMapping in _attributeMapping)
                    {
                        attributeMapping.VendorID = vendorID;
                    }


                    var xmlAssortmentRepository = new XmlAssortmentRepository(vendorID, unit, log);
                    foreach (var assortment in xmlAssortmentRepository.GetAssortment(vendorID))
                    {
                        var assortmentList  = new List <VendorAssortmentBulk.VendorAssortmentItem>();
                        var stockPerProduct = (from p in unit.Scope.Repository <Product>().GetAll(c => c.SourceVendorID == vendorID)
                                               let stock = p.VendorStocks.FirstOrDefault(c => c.VendorID == vendorID)
                                                           where stock != null
                                                           select new
                        {
                            p.VendorItemNumber,
                            stock.QuantityOnHand
                        }).ToDictionary(c => c.VendorItemNumber, c => c.QuantityOnHand);

                        var productGroup = assortment.Assortments.GroupBy(c => c.ConfigurableVendorItemNumber).ToList();

                        foreach (var configurableProductGroup in productGroup)
                        {
                            var first = configurableProductGroup.First();
                            var isConfigurableProductAWebsiteProduct = configurableProductGroup.Select(x => x.Website).Contains("WEB");

                            var type = first.TypeCode;

                            var typeObject  = repositoryProductTypes.Get(type);
                            var modelObject = repositoryModels.Get(first.ModelCode);

                            #region "Configurable Product"
                            var configurableProduct = new VendorAssortmentBulk.VendorAssortmentItem();

                            if (first.ConfigurableVendorItemNumber != ShipmentVendorItemNumber && first.ConfigurableVendorItemNumber != ReturnVendorItemNumber)
                            {
                                #region BrandVendor
                                configurableProduct.BrandVendors = new List <VendorAssortmentBulk.VendorImportBrand>()
                                {
                                    new VendorAssortmentBulk.VendorImportBrand()
                                    {
                                        VendorID        = DefaultVendorID,
                                        VendorBrandCode = first.Brand,
                                        Name            = first.Brand
                                    }
                                };
                                #endregion

                                #region GeneralProductInfo
                                configurableProduct.VendorProduct = new VendorAssortmentBulk.VendorProduct
                                {
                                    VendorID                    = vendorID,
                                    DefaultVendorID             = DefaultVendorID,
                                    CustomItemNumber            = configurableProductGroup.Key,
                                    VendorItemNumber            = configurableProductGroup.Key,
                                    VendorBrandCode             = first.Brand,
                                    IsConfigurable              = 1,
                                    VendorProductGroupCode1     = first.ProductGroupCode1,
                                    VendorProductGroupCodeName1 = first.ProductGroupCode1,
                                    VendorProductGroupCode2     = first.ProductGroupCode2,
                                    VendorProductGroupCodeName2 = first.ProductGroupCode2,
                                    VendorProductGroupCode3     = first.ProductGroupCode3,
                                    VendorProductGroupCodeName3 = first.ProductGroupCode3,
                                    VendorProductGroupCode4     = first.Brand,
                                    VendorProductGroupCodeName4 = first.Brand,
                                    ShortDescription            = first.ShortDescription,
                                    LongDescription             = first.LongDescription,
                                    Barcode = String.Empty
                                };
                                #endregion

                                #region ProductDescription
                                configurableProduct.VendorProductDescriptions = new List <VendorAssortmentBulk.VendorProductDescription>()
                                {
                                    new Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorProductDescription()
                                    {
                                        VendorID                = vendorID,
                                        DefaultVendorID         = DefaultVendorID,
                                        CustomItemNumber        = first.ConfigurableVendorItemNumber,
                                        LanguageID              = 1,
                                        ProductName             = first.ShortDescription,
                                        ShortContentDescription = first.ShortDescription,
                                        LongContentDescription  = first.LongDescription
                                    }
                                };
                                #endregion

                                #region Attributes

                                configurableProduct.VendorImportAttributeValues = new List
                                                                                  <VendorAssortmentBulk.VendorImportAttributeValue>()
                                {
                                    new VendorAssortmentBulk.VendorImportAttributeValue()
                                    {
                                        AttributeCode    = "Season",
                                        Value            = first.ProductGroupCode2,
                                        AttributeID      = attributes.FirstOrDefault(c => c.AttributeCode == "Season").AttributeID,
                                        CustomItemNumber = first.ConfigurableVendorItemNumber,
                                        DefaultVendorID  = DefaultVendorID,
                                        LanguageID       = null,
                                        VendorID         = ConcentratorVendorID
                                    },
                                    new Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorImportAttributeValue()
                                    {
                                        AttributeCode    = "IsBra",
                                        Value            = typeObject == null ? "false" : typeObject.IsBra.ToString(),
                                        AttributeID      = attributes.FirstOrDefault(c => c.AttributeCode == "IsBra").AttributeID,
                                        CustomItemNumber = first.ConfigurableVendorItemNumber,
                                        DefaultVendorID  = DefaultVendorID,
                                        LanguageID       = null,
                                        VendorID         = ConcentratorVendorID
                                    },
                                    new Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorImportAttributeValue()
                                    {
                                        AttributeCode    = "Group",
                                        Value            = typeObject == null ? type : typeObject.ProductType.ToString(),
                                        AttributeID      = attributes.FirstOrDefault(c => c.AttributeCode == "Group").AttributeID,
                                        CustomItemNumber = first.ConfigurableVendorItemNumber,
                                        DefaultVendorID  = DefaultVendorID,
                                        LanguageID       = null,
                                        VendorID         = ConcentratorVendorID
                                    }
                                };

                                #region ProductType Translation Attributes

                                if (typeObject != null) //add translations
                                {
                                    foreach (var translation in typeObject.Translations)
                                    {
                                        configurableProduct.VendorImportAttributeValues.Add(new VendorAssortmentBulk.VendorImportAttributeValue
                                        {
                                            AttributeCode    = "Type",
                                            Value            = translation.Value,
                                            AttributeID      = attributes.FirstOrDefault(c => c.AttributeCode == "Type").AttributeID,
                                            CustomItemNumber = first.ConfigurableVendorItemNumber,
                                            DefaultVendorID  = DefaultVendorID,
                                            LanguageID       = translation.Key.ToString(),
                                            VendorID         = ConcentratorVendorID
                                        });
                                    }
                                }

                                #endregion

                                #region Model Translation

                                if (modelObject != null)
                                {
                                    configurableProduct.VendorImportAttributeValues.Add(new Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorImportAttributeValue()
                                    {
                                        AttributeCode    = "Model",
                                        Value            = modelObject.Translation,
                                        AttributeID      = attributes.FirstOrDefault(c => c.AttributeCode == "Model").AttributeID,
                                        CustomItemNumber = first.ConfigurableVendorItemNumber,
                                        DefaultVendorID  = DefaultVendorID,
                                        LanguageID       = null,
                                        VendorID         = ConcentratorVendorID
                                    });
                                }

                                #endregion

                                #endregion

                                #region Prices
                                configurableProduct.VendorImportPrices =
                                    new List <Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorImportPrice>()
                                {
                                    new Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorImportPrice()
                                    {
                                        VendorID         = vendorID,
                                        DefaultVendorID  = DefaultVendorID,
                                        CustomItemNumber = configurableProductGroup.Key,
                                        CommercialStatus = isConfigurableProductAWebsiteProduct ? "Active" : "Non-Web",
                                        Price            = "0"
                                    }
                                };
                                #endregion

                                #region VendorStock
                                configurableProduct.VendorImportStocks = new List <VendorAssortmentBulk.VendorImportStock>()
                                {
                                    new VendorAssortmentBulk.VendorImportStock()
                                    {
                                        VendorID         = vendorID,
                                        DefaultVendorID  = DefaultVendorID,
                                        CustomItemNumber = configurableProductGroup.Key,
                                        StockType        = "Webshop",
                                        StockStatus      = "NonStock"
                                    }
                                };
                                #endregion

                                assortmentList.Add(configurableProduct);

                                configurableProduct.RelatedProducts = new List <VendorAssortmentBulk.VendorImportRelatedProduct>();

                                var otherProductsFromModel =
                                    assortment.Assortments.Where(c => c.ModelCode == first.ModelCode && c.TypeCode != first.ModelCode)
                                    .Select(c => c.ConfigurableVendorItemNumber)
                                    .Distinct()
                                    .ToList();
                                var otherProductsFromModelAndSameType      = new List <string>();
                                var otherProductsFromModelAndDifferentType = new List <string>();

                                foreach (var product in otherProductsFromModel)
                                {
                                    //var typeRelated = product.Split(new char[] {'-'}, StringSplitOptions.RemoveEmptyEntries)[1];
                                    var typeObjectRelated = repositoryProductTypes.Get(type);

                                    if (typeObjectRelated != null && typeObject != null)
                                    {
                                        if (typeObjectRelated.IsBra == typeObject.IsBra)
                                        {
                                            otherProductsFromModelAndSameType.Add(product);
                                        }
                                        else
                                        {
                                            otherProductsFromModelAndDifferentType.Add(product);
                                        }
                                    }
                                }

                                foreach (var relatedFromType in otherProductsFromModelAndSameType)
                                {
                                    configurableProduct.RelatedProducts.Add(new VendorAssortmentBulk.VendorImportRelatedProduct()
                                    {
                                        CustomItemNumber        = configurableProductGroup.Key,
                                        DefaultVendorID         = DefaultVendorID,
                                        VendorID                = vendorID,
                                        RelatedCustomItemNumber = relatedFromType,
                                        IsConfigured            = 0,
                                        RelatedProductType      = "ModelType"
                                    });
                                }

                                foreach (var relatedFromType in otherProductsFromModelAndDifferentType)
                                {
                                    configurableProduct.RelatedProducts.Add(new VendorAssortmentBulk.VendorImportRelatedProduct()
                                    {
                                        CustomItemNumber        = configurableProductGroup.Key,
                                        DefaultVendorID         = DefaultVendorID,
                                        VendorID                = vendorID,
                                        RelatedCustomItemNumber = relatedFromType,
                                        IsConfigured            = 0,
                                        RelatedProductType      = "ModelTypeCross"
                                    });
                                }
                            }
                            #endregion

                            var isBra = typeObject != null && typeObject.IsBra;

                            foreach (var simpleItem in configurableProductGroup)
                            {
                                var cupsizeProduct = false;

                                #region "Simple Product"
                                var simpleProduct = new VendorAssortmentBulk.VendorAssortmentItem();

                                #region "Brand"
                                simpleProduct.BrandVendors = new List <VendorAssortmentBulk.VendorImportBrand>()
                                {
                                    new VendorAssortmentBulk.VendorImportBrand()
                                    {
                                        VendorID        = DefaultVendorID,
                                        VendorBrandCode = simpleItem.Brand,
                                        Name            = simpleItem.Brand
                                    }
                                };
                                #endregion

                                #region "Vendor Product"
                                simpleProduct.VendorProduct = new VendorAssortmentBulk.VendorProduct
                                {
                                    VendorID                    = vendorID,
                                    DefaultVendorID             = DefaultVendorID,
                                    CustomItemNumber            = simpleItem.SimpleVendorItemNumber,
                                    VendorItemNumber            = simpleItem.SimpleVendorItemNumber,
                                    VendorBrandCode             = first.Brand,
                                    IsConfigurable              = 0,
                                    VendorProductGroupCode1     = simpleItem.ProductGroupCode1,
                                    VendorProductGroupCodeName1 = simpleItem.ProductGroupCode1,
                                    VendorProductGroupCode2     = simpleItem.ProductGroupCode2,
                                    VendorProductGroupCodeName2 = simpleItem.ProductGroupCode2,
                                    VendorProductGroupCode3     = simpleItem.ProductGroupCode3,
                                    VendorProductGroupCodeName3 = simpleItem.ProductGroupCode3,
                                    VendorProductGroupCode4     = first.Brand,
                                    VendorProductGroupCodeName4 = first.Brand,
                                    ShortDescription            = simpleItem.ShortDescription,
                                    LongDescription             = simpleItem.LongDescription,
                                    Barcode = simpleItem.Barcode,
                                    ParentProductCustomItemNumber = configurableProductGroup.Key
                                };
                                #endregion

                                #region "Product Description"
                                simpleProduct.VendorProductDescriptions = new List <VendorAssortmentBulk.VendorProductDescription>()
                                {
                                    new Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorProductDescription()
                                    {
                                        VendorID                = vendorID,
                                        DefaultVendorID         = DefaultVendorID,
                                        CustomItemNumber        = simpleItem.SimpleVendorItemNumber,
                                        LanguageID              = 1,
                                        ProductName             = simpleItem.ShortDescription,
                                        ShortContentDescription = simpleItem.ShortDescription,
                                        LongContentDescription  = simpleItem.LongDescription
                                    }
                                };
                                #endregion

                                #region "Attribute"
                                simpleProduct.VendorImportAttributeValues = new List <VendorAssortmentBulk.VendorImportAttributeValue>()
                                {
                                    new Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorImportAttributeValue()
                                    {
                                        AttributeCode    = "Color",
                                        Value            = simpleItem.ColourcodeSupplier,
                                        AttributeID      = attributes.FirstOrDefault(c => c.AttributeCode == "Color").AttributeID,
                                        CustomItemNumber = simpleItem.SimpleVendorItemNumber,
                                        DefaultVendorID  = DefaultVendorID,
                                        LanguageID       = null,
                                        VendorID         = ConcentratorVendorID
                                    },
                                    new Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorImportAttributeValue()
                                    {
                                        AttributeCode    = "Group",
                                        Value            = typeObject == null ? type : typeObject.ProductType.ToString(),
                                        AttributeID      = attributes.FirstOrDefault(c => c.AttributeCode == "Group").AttributeID,
                                        CustomItemNumber = simpleItem.SimpleVendorItemNumber,
                                        DefaultVendorID  = DefaultVendorID,
                                        LanguageID       = null,
                                        VendorID         = ConcentratorVendorID
                                    }
                                };

                                if (!string.IsNullOrEmpty(simpleItem.SubsizeSupplier))
                                {
                                    simpleProduct.VendorImportAttributeValues.Add(new VendorAssortmentBulk.VendorImportAttributeValue()
                                    {
                                        AttributeCode    = "Size",
                                        Value            = string.Format("{0}{1}", simpleItem.SizeSupplier, simpleItem.SubsizeSupplier),
                                        AttributeID      = attributes.FirstOrDefault(c => c.AttributeCode == "Size").AttributeID,
                                        CustomItemNumber = simpleItem.SimpleVendorItemNumber,
                                        DefaultVendorID  = DefaultVendorID,
                                        LanguageID       = null,
                                        VendorID         = ConcentratorVendorID
                                    });

                                    cupsizeProduct = true;
                                }
                                else
                                {
                                    simpleProduct.VendorImportAttributeValues.Add(new VendorAssortmentBulk.VendorImportAttributeValue()
                                    {
                                        AttributeCode    = "Size",
                                        Value            = simpleItem.SizeSupplier,
                                        AttributeID      = attributes.FirstOrDefault(c => c.AttributeCode == "Size").AttributeID,
                                        CustomItemNumber = simpleItem.SimpleVendorItemNumber,
                                        DefaultVendorID  = DefaultVendorID,
                                        LanguageID       = null,
                                        VendorID         = ConcentratorVendorID
                                    });
                                }

                                if (isBra)
                                {
                                    simpleProduct.VendorImportAttributeValues.Add(new VendorAssortmentBulk.VendorImportAttributeValue()
                                    {
                                        AttributeCode    = "TopSize",
                                        Value            = string.Format("{0}{1}", simpleItem.SizeSupplier, simpleItem.SubsizeSupplier),
                                        AttributeID      = attributes.FirstOrDefault(c => c.AttributeCode == "TopSize").AttributeID,
                                        CustomItemNumber = simpleItem.SimpleVendorItemNumber,
                                        DefaultVendorID  = DefaultVendorID,     // 50
                                        LanguageID       = null,
                                        VendorID         = ConcentratorVendorID // 48
                                    });
                                }
                                else
                                {
                                    simpleProduct.VendorImportAttributeValues.Add(new VendorAssortmentBulk.VendorImportAttributeValue()
                                    {
                                        AttributeCode    = "BottomSize",
                                        Value            = simpleItem.SizeSupplier,
                                        AttributeID      = attributes.FirstOrDefault(c => c.AttributeCode == "BottomSize").AttributeID,
                                        CustomItemNumber = simpleItem.SimpleVendorItemNumber,
                                        DefaultVendorID  = DefaultVendorID,     // 50
                                        LanguageID       = null,
                                        VendorID         = ConcentratorVendorID // 48
                                    });
                                }


                                #endregion

                                #region "Price"
                                simpleProduct.VendorImportPrices = new List <Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorImportPrice>()
                                {
                                    new Concentrator.Objects.Vendors.Bulk.VendorAssortmentBulk.VendorImportPrice()
                                    {
                                        VendorID         = vendorID,
                                        DefaultVendorID  = DefaultVendorID,
                                        CustomItemNumber = simpleItem.SimpleVendorItemNumber,
                                        CommercialStatus = simpleItem.Website.Equals("WEB") ? "Active" : "Non-Web",
                                        Price            = (useAdvicePrice  ? simpleItem.AdvicePrice :  simpleItem.LabellingPrice).ToString(CultureInfo.InvariantCulture),
                                        CostPrice        = (useAdvicePrice  ? simpleItem.AdvicePrice :  simpleItem.LabellingPrice).ToString(CultureInfo.InvariantCulture)
                                    }
                                };
                                #endregion

                                #region "Stock"

                                if (!stockPerProduct.ContainsKey(simpleItem.SimpleVendorItemNumber))
                                {
                                    simpleProduct.VendorImportStocks = new List <VendorAssortmentBulk.VendorImportStock>()
                                    {
                                        new VendorAssortmentBulk.VendorImportStock()
                                        {
                                            VendorID         = vendorID,
                                            DefaultVendorID  = DefaultVendorID,
                                            CustomItemNumber = simpleItem.SimpleVendorItemNumber,
                                            StockType        = "Webshop",
                                            StockStatus      = "ENA"
                                        }
                                    };
                                }
                                else
                                {
                                    simpleProduct.VendorImportStocks = new List <VendorAssortmentBulk.VendorImportStock>();
                                }
                                #endregion

                                assortmentList.Add(simpleProduct);

                                if (first.ConfigurableVendorItemNumber != ShipmentVendorItemNumber && first.ConfigurableVendorItemNumber != ReturnVendorItemNumber)
                                {
                                    configurableProduct.RelatedProducts.Add(new VendorAssortmentBulk.VendorImportRelatedProduct()
                                    {
                                        CustomItemNumber        = first.ConfigurableVendorItemNumber,
                                        DefaultVendorID         = DefaultVendorID,
                                        IsConfigured            = 1,
                                        VendorID                = vendorID,
                                        RelatedCustomItemNumber = simpleItem.SimpleVendorItemNumber,
                                        RelatedProductType      = "Configured product"
                                    });

                                    AddConfiguredAttributes(configurableProduct, cupsizeProduct);
                                }
                                #endregion
                            }
                        }

                        try
                        {
                            var bulkConfig = new VendorAssortmentBulkConfiguration {
                                IsPartialAssortment = IsPartialAssortment
                            };
                            using (var vendorAssortmentBulk = new VendorAssortmentBulk(assortmentList, vendorID, DefaultVendorID, bulkConfig))
                            {
                                vendorAssortmentBulk.Init(unit.Context);
                                vendorAssortmentBulk.Sync(unit.Context);
                            }
                        }
                        catch (Exception ex)
                        {
                            log.AuditError(ex.Message);
                        }

                        foreach (var productAttributeConfiguration in _configuredAttributes)
                        {
                            var product = unit.Scope.Repository <Product>().GetSingle(c => c.VendorItemNumber == productAttributeConfiguration.Key && c.IsConfigurable);

                            foreach (var code in productAttributeConfiguration.Value)
                            {
                                var ent = product.ProductAttributeMetaDatas.FirstOrDefault(c => c.AttributeCode == code);

                                if (ent == null)
                                {
                                    var attr = unit.Scope.Repository <ProductAttributeMetaData>().GetSingle(c => c.AttributeCode == code);

                                    product.ProductAttributeMetaDatas.Add(attr);
                                }
                            }
                        }
                        unit.Save();
                        CopyArticleInformationToTnt(assortment.FileName);
                    }
                }
            }
        }
コード例 #14
0
 public ProductModelManager()
 {
     _Repository = new ProductModelRepository();
 }
コード例 #15
0
 public IEnumerable <ProductModel> Similar([FromBody] ProductModel product)
 {
     return(ProductModelRepository.GetSimilarProducts(product));
 }
コード例 #16
0
        protected override void Process()
        {
            var vendorIDsToProcessSetting = GetConfiguration().AppSettings.Settings["VendorIDs"];

            if (vendorIDsToProcessSetting == null)
            {
                throw new Exception("Setting VendorIDs is missing");
            }

            var vendorIDsToProcess = vendorIDsToProcessSetting.Value.Split(',').Select(x => Convert.ToInt32(x)).ToArray();

            var defaultVendorIDSetting = GetConfiguration().AppSettings.Settings["VendorID"];

            if (defaultVendorIDSetting == null)
            {
                throw new Exception("Setting VendorID is missing");
            }

            var defaultVendorID = Int32.Parse(defaultVendorIDSetting.Value);

            using (var unit = GetUnitOfWork())
            {
                ProductModelRepository repositoryModels = new ProductModelRepository((IServiceUnitOfWork)unit, defaultVendorID);

                var modelAttributeID          = unit.Scope.Repository <ProductAttributeMetaData>().GetAll().ToList().FirstOrDefault(c => c.AttributeCode.ToLower() == "model").AttributeID;
                var productAttributeValueRepo = unit.Scope.Repository <ProductAttributeValue>();
                var products = unit.Scope.Repository <Product>().GetAll(c => vendorIDsToProcess.Contains(c.SourceVendorID) && c.IsConfigurable).ToList();

                foreach (var product in products)
                {
                    var modelCode = product.VendorItemNumber.Try(c => c.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries)[0], string.Empty);

                    if (string.IsNullOrEmpty(modelCode)) //if model code can't be retrieved from the product, continue
                    {
                        continue;
                    }

                    var modelTranlsation = repositoryModels.Get(modelCode);
                    if (modelTranlsation == null || string.IsNullOrEmpty(modelTranlsation.Translation))//if translation hasn't been set, continue
                    {
                        continue;
                    }

                    var value = product.ProductAttributeValues.FirstOrDefault(c => c.AttributeID == modelAttributeID);
                    if (value == null)
                    {
                        value = new ProductAttributeValue()
                        {
                            Product     = product,
                            AttributeID = modelAttributeID
                        };

                        productAttributeValueRepo.Add(value);
                    }

                    value.Value = modelTranlsation.Translation;
                }

                unit.Save();
            }
        }