Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove ProductVariantProdCounter #54

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>10.7.0</Version>
<Version>10.7.1</Version>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<Title>Ecom Provider</Title>
<Description>Ecom Provider</Description>
Expand Down
56 changes: 14 additions & 42 deletions src/EcomDestinationWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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"]);
Expand Down Expand Up @@ -898,8 +898,7 @@ protected DataTable ExistingProducts
if (_existingProducts == null)
{
List<string> columnsToSelect = new List<string>() {
"ProductID", "ProductLanguageID", "ProductVariantID","ProductNumber", "ProductName",
"ProductVariantCounter", "ProductVariantProdCounter"
"ProductID", "ProductLanguageID", "ProductVariantID","ProductNumber", "ProductName", "ProductVariantCounter"
};
IEnumerable<string> ecomProductsPKColumns = MappingIdEcomProductsPKColumns.Values.SelectMany(i => i);
if (ecomProductsPKColumns != null)
Expand Down Expand Up @@ -1251,8 +1250,7 @@ private bool WriteProducts(Dictionary<string, object> 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
Expand Down Expand Up @@ -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" });
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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)
{
Expand Down Expand Up @@ -3778,10 +3751,10 @@ public void UpdateFieldsInExistingProductsWithVariantIDs(string keyColumn, Mappi
if (existigProductVariantIdsCombination.ContainsKey(key))
{
string? rowProductVariantId = row["ProductVariantID"].ToString();
List<Tuple<string, string, string>>? variantsInfoList = (List<Tuple<string, string, string>>?)existigProductVariantIdsCombination[key];
List<Tuple<string, string>>? variantsInfoList = (List<Tuple<string, string>>?)existigProductVariantIdsCombination[key];
if (variantsInfoList is not null)
{
foreach (Tuple<string, string, string> variantInfo in variantsInfoList)
foreach (Tuple<string, string> variantInfo in variantsInfoList)
{
if (string.IsNullOrEmpty(rowProductVariantId) || !string.Equals(rowProductVariantId, variantInfo.Item1))
{
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -3834,23 +3806,23 @@ private Hashtable GetExistingProductVariantsIDsCombinations(string searchingDiff
key = row[searchingDifferentProductsColumn].ToString() ?? "";
}

Tuple<string?, string?, string?> variantInfo = new Tuple<string?, string?, string?>
Tuple<string?, string?> variantInfo = new Tuple<string?, string?>
(
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<Tuple<string?, string?, string?>> variantIDsList = (List<Tuple<string?, string?, string?>>)value;
List<Tuple<string?, string?>> variantIDsList = (List<Tuple<string?, string?>>)value;
variantIDsList?.Add(variantInfo);
}
}
else
{
result[key] = new List<Tuple<string?, string?, string?>>() { variantInfo };
result[key] = new List<Tuple<string?, string?>>() { variantInfo };
}
}
}
Expand Down
Loading