Skip to content

Commit

Permalink
Merge pull request #353 from FromDoppler/DOP-1401-recommended-product
Browse files Browse the repository at this point in the history
DOP-1401 - Recommended product
  • Loading branch information
ck-makingsense authored Mar 20, 2024
2 parents 5dbcc4a + 20029ac commit 4676884
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Doppler.HtmlEditorApi.Test/Domain/DopplerHtmlDocumentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ public void GetTrackableUrls_should_not_map_field_names()
}

[Fact]
public void SanitizeDynamicContentNode_should_modify_html_dynamic_content_when_has_two_or_more_child_node_and_replace_image_src()
public void SanitizeDynamicContentNodes_should_modify_html_dynamic_content_when_has_two_or_more_child_node_and_replace_image_src()
{
// Arrange
var input = $@"<dynamiccontent action=""abandoned_cart"" items=""2"">
Expand Down Expand Up @@ -361,7 +361,7 @@ public void SanitizeDynamicContentNode_should_modify_html_dynamic_content_when_h
</dynamiccontent>";

// Act
htmlDocument.SanitizeDynamicContentNode();
htmlDocument.SanitizeDynamicContentNodes();
var content = htmlDocument.GetDopplerContent();

// Assert
Expand Down
2 changes: 1 addition & 1 deletion Doppler.HtmlEditorApi/Controllers/CampaignsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ private async Task<DopplerHtmlDocument> ExtractHtmlDomFromCampaignContent(string
htmlDocument.ReplaceFieldNameTagsByFieldIdTags(dopplerFieldsProcessor.GetFieldIdOrNull);
htmlDocument.RemoveUnknownFieldIdTags(dopplerFieldsProcessor.FieldIdExist);
htmlDocument.SanitizeTrackableLinks();
htmlDocument.SanitizeDynamicContentNode();
htmlDocument.SanitizeDynamicContentNodes();
return htmlDocument;
}

Expand Down
22 changes: 12 additions & 10 deletions Doppler.HtmlEditorApi/Domain/DopplerHtmlDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,22 +94,24 @@ public void SanitizeTrackableLinks()
/// - Remove repeated cart item tags
/// - Replace img src value by [[[DC:IMAGE]]]
/// </summary>
public void SanitizeDynamicContentNode()
public void SanitizeDynamicContentNodes()
{
var dynamicContentNode = _contentNode.SelectSingleNode("//dynamiccontent");
if (dynamicContentNode != null)
var dynamicContentNodes = _contentNode.SelectNodes("//dynamiccontent");
if (dynamicContentNodes != null)
{
var divNodes = dynamicContentNode.SelectNodes("div");
if (divNodes != null && divNodes.Count > 1)
for (var i = 0; i < dynamicContentNodes.Count; i++)
{
for (var i = 1; i < divNodes.Count; i++)
var divNodes = dynamicContentNodes[i].SelectNodes("div");
if (divNodes != null && divNodes.Count > 1)
{
dynamicContentNode.RemoveChild(divNodes[i]);
for (var j = 1; j < divNodes.Count; j++)
{
dynamicContentNodes[i].RemoveChild(divNodes[j]);
}
}
var imgNode = dynamicContentNodes[i].SelectSingleNode(".//img");
imgNode?.SetAttributeValue("src", "[[[DC:IMAGE]]]");
}

var imgNode = dynamicContentNode.SelectSingleNode(".//img");
imgNode?.SetAttributeValue("src", "[[[DC:IMAGE]]]");
}
}

Expand Down

0 comments on commit 4676884

Please sign in to comment.