Exemplo n.º 1
0
 public AkeneoCategory CreateNewCategory(AkeneoCategory category, AkeneoProduct product)
 {
     try
     {
         _logger.info($"Creating category {category.CategoryName} : {product.productName} -> start");
         IBaseRequestHandler <NameValueCollection, WebClientHeader> httpManager = new BaseWebClientWriter();
         var _c = new AkeneoBaseCategoriesIndexerConverter();
         category.CategoryId = category.CategoryName.Trim().ToLower().Replace(" ", "_").Replace("-", "_").Replace("/", "_").Replace("?", "_").Replace(".", "_").Replace(",", "_").Replace("&", "_");
         AkeneoIndexedCategoriesDtoEmbedCollectionItem dtoCat = _c.ConvertToDtoEntity(category);
         if (!ReferenceEquals(dtoCat, null) &&
             !ReferenceEquals(dtoCat.CategoryCode, null) &&
             !ReferenceEquals(dtoCat.CategoriesLocales, null) &&
             !ReferenceEquals(dtoCat.CategoriesLocales.Count, 0))
         {
             var EncodedContent = JsonConvert.SerializeObject(dtoCat);
             httpManager.AddHeader(new WebClientHeader("Authorization", $"Bearer {akeneoAuthInfo.access_token}"));
             httpManager.AddBodyParameter(EncodedContent);
             httpManager.PostDataAsStringContext($"{Akeneo.BaseAkeneoUrl}{Akeneo.AkeneoCategoryListUrl}");
             return(category);
         }
         return(null);
         //AkeneoIndexedCategoriesDtoEmbedCollectionItem
     }
     catch (Exception e)
     {
         _logger.error($"{category.CategoryName} -> {product.productName} Error in creating akeneo category: {e.Message} -> {e.StackTrace}");
         return(null);
     }
 }
Exemplo n.º 2
0
        public AkeneoProduct Preprocess(AkeneoProduct product)
        {
            if (!ReferenceEquals(CollectionRules, null) & CollectionRules.Count > 0)
            {
                try
                {
                    var targetCollection = CollectionRules.Where(c => c.CollectionToMatch.Trim().Equals(product.productCategory.Trim())).ToList();
                    if (!ReferenceEquals(targetCollection, null) && targetCollection.Count > 0)
                    {
                        product.productCategory = targetCollection.FirstOrDefault().CollectionToAssign;
                    }
                }
                catch (Exception)
                {
                }
            }
            if (!ReferenceEquals(VendorsRules, null) && VendorsRules.Count > 0)
            {
                try
                {
                    var targetVendor = VendorsRules.Where(v => v.VendorToCompare.Trim().Equals(product.productVendor.Trim())).ToList();
                    if (!ReferenceEquals(targetVendor, null) && targetVendor.Count > 0)
                    {
                        product.productVendor = targetVendor.FirstOrDefault().VendorToAssign;
                    }
                }
                catch (Exception)
                {
                }
            }
            if (ReferenceEquals(product.productCategory, String.Empty) || ReferenceEquals(product.productCategory, null))
            {
                product.productCategory = "No idea";
            }
            var _tempCat = GetCategoryId(product.productCategory);

            if (_tempCat.Equals(String.Empty))
            {
                if (ReferenceEquals(product.productCategory, null))
                {
                    product.productCategory = String.Empty;
                }
                AkeneoCategory _cat = new AkeneoCategory();
                if (product.productCategory.Equals(String.Empty))
                {
                    _cat.CategoryName = "Empty scrapping node";
                }
                else
                {
                    _cat.CategoryName = product.productCategory;
                }
                _cat = CreateNewCategory(_cat, product);
                if (!ReferenceEquals(_cat, null))
                {
                    lock (ListedCategoriesList)
                    {
                        ListedCategoriesList.Add(_cat);
                    }
                    product.productCategory = _cat.CategoryId;
                }
            }
            else
            {
                product.productCategory = _tempCat;
            }
            return(product);
        }