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

Fix duplicate Product Shared Option on Import products #404

Merged
merged 2 commits into from
Jun 2, 2022
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
69 changes: 36 additions & 33 deletions Libraries/Hotcakes.Commerce/Catalog/CatalogImport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@ protected override string SheetName
[Serializable]
internal class ChoicesSheetImport : WorksheetImport
{
private readonly List<Option> options;
private List<Option> options;
private string _previousSlug;

internal ChoicesSheetImport(ExcelReader reader, HotcakesApplication hccApp, Action<double, string> log)
Expand Down Expand Up @@ -897,7 +897,7 @@ protected override bool ProcessRow(Row row)
{
p.Options.RemoveAll(e => e.Bvin == opt.Bvin);
opt = options.Where(y => y.Bvin == opt.Bvin).FirstOrDefault();
}
}

var shared = GetCellBool(row, "D");
if (shared && opt == null)
Expand All @@ -911,39 +911,42 @@ protected override bool ProcessRow(Row row)
}

var isNew = opt == null;
var processedOptionItems = new List<string>();

if (isNew)
if (isNew)
{
opt = new Option {Name = choiceName, IsShared = shared};
}

opt.SetProcessor(optionType);
var processedOptionItems = new List<string>();
var column = "E";
while (column.Length < 10)
{
var choiceItem = GetCell(row, column);

if (string.IsNullOrWhiteSpace(choiceItem))
{
break;
}

if (opt.OptionType == OptionTypes.Html)
{
opt.TextSettings.AddOrUpdate("html", choiceItem);
}
else
{
if (opt.Items.All(e => e.Name != choiceItem))
{
opt.AddItem(choiceItem);
}
processedOptionItems.Add(choiceItem);
}

column = GetNextColumn(column);
}

opt.SetProcessor(optionType);
var column = "E";
while (column.Length < 10)
{
var choiceItem = GetCell(row, column);

if (string.IsNullOrWhiteSpace(choiceItem))
{
break;
}

if (opt.OptionType == OptionTypes.Html)
{
opt.TextSettings.AddOrUpdate("html", choiceItem);
}
else
{
if (opt.Items.All(e => e.Name != choiceItem))
{
opt.AddItem(choiceItem);
}
processedOptionItems.Add(choiceItem);
}

column = GetNextColumn(column);
}

_hccApp.CatalogServices.ProductOptions.Create(opt);
options = _hccApp.CatalogServices.ProductOptions.FindAll(0, int.MaxValue);
}

if (!isNew && !opt.IsShared)
{
Expand All @@ -952,7 +955,7 @@ protected override bool ProcessRow(Row row)


p.Options.Add(opt);
_hccApp.CatalogServices.Products.Update(p);
//_hccApp.CatalogServices.Products.Update(p);

if (opt.IsShared)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,15 @@ private void RenderSingleItem(StringBuilder sb, Option o, bool isAlternate)
sb.Append("<td class=\"hcProductEditChoice\">");
sb.Append(o.Render());
sb.Append("</td>");
sb.Append("<td width='5%'><a href=\"" + destinationLink + "\">");
sb.Append("<img class=\"hcIconEdit\" alt=\"Edit\" />");
sb.Append("<td width='5%'><a class='hcIconEdit' href =\"" + destinationLink + "\">");
//sb.Append("<img class=\"hcIconEdit\" alt=\"Edit\" />");
sb.Append("</a></td>");
sb.Append("<td width='5%'>");
sb.Append("<a id=\"rem" + o.Bvin +
"\" class=\"trash\" href=\"ProductSharedChoices_Delete.aspx?redirect=y&id=");
"\" class=\"hcIconDelete hcDeleteColumn trash\" href=\"ProductSharedChoices_Delete.aspx?redirect=y&id=");
sb.Append(o.Bvin);
sb.Append("\" >");
sb.Append("<img alt=\"delete\" class=\"hcIconDelete\" />");
//sb.Append("<img alt=\"delete\" class=\"hcIconDelete\" />");
sb.Append("</a></td>");
sb.Append("</tr>");
}
Expand Down