Skip to content

Commit

Permalink
Merge pull request HotcakesCommerce#404 from erw13n/Issues/Issue-379
Browse files Browse the repository at this point in the history
Fix duplicate Product Shared Option on Import products
  • Loading branch information
WillStrohl authored Jun 2, 2022
2 parents 2161a7d + f5594a6 commit b2d1d1d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 37 deletions.
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

0 comments on commit b2d1d1d

Please sign in to comment.