From fd427a8166763a0ce7a5092ff1c4e65c0dc49c75 Mon Sep 17 00:00:00 2001 From: Dmitriy Benyuk Date: Wed, 25 Sep 2024 12:15:01 +0300 Subject: [PATCH] Remove ProductVariantProdCounter --- ...aIntegration.Providers.EcomProvider.csproj | 2 +- src/EcomDestinationWriter.cs | 56 +++++-------------- 2 files changed, 15 insertions(+), 43 deletions(-) diff --git a/src/Dynamicweb.DataIntegration.Providers.EcomProvider.csproj b/src/Dynamicweb.DataIntegration.Providers.EcomProvider.csproj index 067c804..af0b91f 100644 --- a/src/Dynamicweb.DataIntegration.Providers.EcomProvider.csproj +++ b/src/Dynamicweb.DataIntegration.Providers.EcomProvider.csproj @@ -1,6 +1,6 @@  - 10.7.0 + 10.7.1 1.0.0.0 Ecom Provider Ecom Provider diff --git a/src/EcomDestinationWriter.cs b/src/EcomDestinationWriter.cs index cf70aeb..384aa08 100644 --- a/src/EcomDestinationWriter.cs +++ b/src/EcomDestinationWriter.cs @@ -256,7 +256,7 @@ internal void CreateTempTables() EnsureDestinationColumns(currentTable, columnMappingDictionary, destColumns, ["VariantOptionID", "VariantOptionLanguageID"]); break; case "EcomProducts": - EnsureDestinationColumns(currentTable, columnMappingDictionary, destColumns, ["ProductVariantID", "ProductID", "ProductLanguageID", "ProductDefaultShopId", "ProductVariantProdCounter", "ProductVariantCounter"]); + EnsureDestinationColumns(currentTable, columnMappingDictionary, destColumns, ["ProductVariantID", "ProductID", "ProductLanguageID", "ProductDefaultShopId", "ProductVariantCounter"]); break; case "EcomProductCategoryFieldValue": EnsureDestinationColumns(currentTable, columnMappingDictionary, destColumns, ["FieldValueFieldCategoryId", "FieldValueProductId", "FieldValueProductVariantId", "FieldValueProductLanguageId"]); @@ -898,8 +898,7 @@ protected DataTable ExistingProducts if (_existingProducts == null) { List columnsToSelect = new List() { - "ProductID", "ProductLanguageID", "ProductVariantID","ProductNumber", "ProductName", - "ProductVariantCounter", "ProductVariantProdCounter" + "ProductID", "ProductLanguageID", "ProductVariantID","ProductNumber", "ProductName", "ProductVariantCounter" }; IEnumerable ecomProductsPKColumns = MappingIdEcomProductsPKColumns.Values.SelectMany(i => i); if (ecomProductsPKColumns != null) @@ -1251,8 +1250,7 @@ private bool WriteProducts(Dictionary row, Mapping mapping, Dict if (existingProductRow != null) { - dataRow["ProductVariantCounter"] = existingProductRow["ProductVariantCounter"]; - dataRow["ProductVariantProdCounter"] = existingProductRow["ProductVariantProdCounter"]; + dataRow["ProductVariantCounter"] = existingProductRow["ProductVariantCounter"]; } //Find groups, create if missing, add relations @@ -3394,7 +3392,7 @@ private void AddMappingsToJobThatNeedsToBeThereForMoveToMainTables() EnsureMapping(ecomProductsMapping, DestinationColumnMappings["EcomProducts"], tableColumnsDictionary["EcomProducts"], new string[] { "ProductID", "ProductVariantID", "ProductLanguageID" }); EnsureMapping(ecomProductsMapping, DestinationColumnMappings["EcomProducts"], tableColumnsDictionary["EcomProducts"], - new string[] { "ProductVariantProdCounter", "ProductVariantCounter" }); + new string[] { "ProductVariantCounter" }); HandleIsKeyColumns(ecomProductsMapping, new string[] { "ProductVariantID", "ProductLanguageID" }); } @@ -3659,12 +3657,10 @@ public void UpdateVariantFieldsInProducts() { var ecomVariantOptionsProductRelationTables = FindDataTablesStartingWithName("EcomVariantOptionsProductRelation"); if (DataToWrite.Tables.Contains("EcomVariantgroupProductrelation") && ecomVariantOptionsProductRelationTables.Count() > 0) - { - bool variantProdCounterColExist = productsDataTable.Columns.Contains("ProductVariantID") && - productsDataTable.Columns.Contains("ProductVariantProdCounter"); + { bool variantCounterColExist = productsDataTable.Columns.Contains("ProductVariantCounter"); - if (!variantProdCounterColExist && !variantCounterColExist) + if (!variantCounterColExist) { continue; } @@ -3676,30 +3672,7 @@ public void UpdateVariantFieldsInProducts() foreach (DataRow row in tableRows.Values.SelectMany(c => c)) { string productId = row["ProductID"].ToString() ?? ""; - string langId = row["ProductLanguageID"].ToString() ?? ""; - //Check if it is already existing product row and it has filled variants counter fileds - skip it - if (variantProdCounterColExist && (row["ProductVariantProdCounter"] == DBNull.Value || row["ProductVariantProdCounter"].ToString() == "0")) - { - if (string.IsNullOrEmpty(row["ProductVariantID"].ToString())) - { - int variantProdCounter = 0; - ProductVariantsCountDictionary.TryGetValue(string.Format("{0}.{1}", productId, langId), out variantProdCounter); - row["ProductVariantProdCounter"] = variantProdCounter > 0 ? variantProdCounter - 1 : 0; - } - else - { - if (productVariantCounterDict.TryGetValue(productId + langId, out int count)) - { - productVariantCounterDict[productId + langId] = count + 1; - row["ProductVariantProdCounter"] = count + 1; - } - else - { - productVariantCounterDict.Add(productId + langId, 0); - row["ProductVariantProdCounter"] = 0; - } - } - } + string langId = row["ProductLanguageID"].ToString() ?? ""; //Check if it is already existing product row and it has filled variants counter fileds - skip it if ((row["ProductVariantCounter"] == System.DBNull.Value || row["ProductVariantCounter"].ToString() == "0") && variantCounterColExist) { @@ -3778,10 +3751,10 @@ public void UpdateFieldsInExistingProductsWithVariantIDs(string keyColumn, Mappi if (existigProductVariantIdsCombination.ContainsKey(key)) { string? rowProductVariantId = row["ProductVariantID"].ToString(); - List>? variantsInfoList = (List>?)existigProductVariantIdsCombination[key]; + List>? variantsInfoList = (List>?)existigProductVariantIdsCombination[key]; if (variantsInfoList is not null) { - foreach (Tuple variantInfo in variantsInfoList) + foreach (Tuple variantInfo in variantsInfoList) { if (string.IsNullOrEmpty(rowProductVariantId) || !string.Equals(rowProductVariantId, variantInfo.Item1)) { @@ -3793,8 +3766,7 @@ public void UpdateFieldsInExistingProductsWithVariantIDs(string keyColumn, Mappi newRow.ItemArray = (object?[])row.ItemArray.Clone(); } newRow["ProductVariantID"] = variantInfo.Item1; - newRow["ProductVariantCounter"] = variantInfo.Item2; - newRow["ProductVariantProdCounter"] = variantInfo.Item3; + newRow["ProductVariantCounter"] = variantInfo.Item2; rowsToAdd.Add(newRow); } } @@ -3834,23 +3806,23 @@ private Hashtable GetExistingProductVariantsIDsCombinations(string searchingDiff key = row[searchingDifferentProductsColumn].ToString() ?? ""; } - Tuple variantInfo = new Tuple + Tuple variantInfo = new Tuple ( row["ProductVariantID"].ToString(), - row["ProductVariantCounter"].ToString(), row["ProductVariantProdCounter"].ToString() + row["ProductVariantCounter"].ToString() ); if (result.ContainsKey(key)) { var value = result[key]; if (value is not null) { - List> variantIDsList = (List>)value; + List> variantIDsList = (List>)value; variantIDsList?.Add(variantInfo); } } else { - result[key] = new List>() { variantInfo }; + result[key] = new List>() { variantInfo }; } } }