Skip to content

Commit 9bc9353

Browse files
authored
Merge pull request #54 from dynamicweb/dbe/24901-Post-ProductInfo-Processing-Hook
Post-ProductInfo Processing Hook
2 parents e2d6508 + efbffdf commit 9bc9353

File tree

4 files changed

+78
-1
lines changed

4 files changed

+78
-1
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using Dynamicweb.Extensibility.Notifications;
2+
using Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Notifications;
3+
4+
namespace Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Examples.Notifications
5+
{
6+
/// <summary>
7+
/// Class ProductInfoOnAfterProcessResponseSubscriber.
8+
/// </summary>
9+
/// <seealso cref="NotificationSubscriber" />
10+
[Subscribe(ProductInfo.OnAfterProductInfoProcessResponse)]
11+
public class ProductInfoOnAfterProcessResponseSubscriber : NotificationSubscriber
12+
{
13+
/// <summary>
14+
/// Call to invoke observer.
15+
/// </summary>
16+
/// <param name="notification">The notification.</param>
17+
/// <param name="args">The args.</param>
18+
public override void OnNotify(string notification, NotificationArgs args)
19+
{
20+
var myArgs = (ProductInfo.OnAfterProductInfoProcessResponseArgs)args;
21+
22+
// TODO: Add code here
23+
if (myArgs?.ProductInfo != null)
24+
{
25+
26+
}
27+
}
28+
}
29+
}

src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/Dynamicweb.Ecommerce.DynamicwebLiveIntegration.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<Version>10.4.27</Version>
3+
<Version>10.4.28</Version>
44
<AssemblyVersion>1.0.0.0</AssemblyVersion>
55
<Title>Live Integration</Title>
66
<Description>Live Integration</Description>

src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/Notifications/ProductInfo.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ public static class ProductInfo
3232
/// </example>
3333
public const string OnAfterGenerateProductInfoXml = "Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Notifications.LiveIntegration.OnAfterGenerateProductInfoXml";
3434

35+
/// <summary>
36+
/// Occurs after the response from ERP is returned before the product info object is stored. This enables you to change or analyze the product info object before it's added to cache.
37+
/// </summary>
38+
public const string OnAfterProductInfoProcessResponse = "Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Notifications.LiveIntegration.OnAfterProductInfoProcessResponse";
39+
3540
private static List<PriceProductSelection> GetProductSelectionsFromProducts(Dictionary<Product, double> products)
3641
{
3742
var productSelections = new List<PriceProductSelection>();
@@ -168,5 +173,45 @@ public OnAfterGenerateProductInfoXmlArgs(List<PriceProductSelection> products, P
168173
/// </summary>
169174
public Logger Logger { get; }
170175
}
176+
177+
/// <summary>
178+
/// Arguments class for the OnAfterProductInfoProcessResponse subscriber.
179+
/// </summary>
180+
/// <seealso cref="NotificationArgs" />
181+
public class OnAfterProductInfoProcessResponseArgs : NotificationArgs
182+
{
183+
/// <summary>
184+
/// Initializes a new instance of the <see cref="OnAfterProductInfoProcessResponseArgs"/> class.
185+
/// </summary>
186+
public OnAfterProductInfoProcessResponseArgs(Products.ProductInfo productInfo, XmlDocument responseXml, Settings liveIntegrationSettings, Logger logger)
187+
{
188+
ProductInfo = productInfo;
189+
ResponseXml = responseXml;
190+
Settings = liveIntegrationSettings;
191+
Logger = logger;
192+
}
193+
194+
/// <summary>
195+
/// Gets the product info object.
196+
/// </summary>
197+
/// <value>The products.</value>
198+
public Products.ProductInfo ProductInfo { get; }
199+
200+
/// <summary>
201+
/// Gets the response XML document.
202+
/// </summary>
203+
/// <value>The XML document.</value>
204+
public XmlDocument ResponseXml { get; }
205+
206+
/// <summary>
207+
/// Settings
208+
/// </summary>
209+
public Settings Settings { get; }
210+
211+
/// <summary>
212+
/// Logger
213+
/// </summary>
214+
public Logger Logger { get; }
215+
}
171216
}
172217
}

src/Dynamicweb.Ecommerce.DynamicwebLiveIntegration/Products/ProductManager.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,9 @@ private static Dictionary<string, ProductInfo> ProcessResponse(Settings settings
449449
productInfo["ProductDefaultUnitId"] = item.SelectSingleNode("column [@columnName='ProductDefaultUnitId']")?.InnerText;
450450
}
451451

452+
Dynamicweb.Extensibility.Notifications.NotificationManager.Notify(Notifications.ProductInfo.OnAfterProductInfoProcessResponse,
453+
new Notifications.ProductInfo.OnAfterProductInfoProcessResponseArgs(productInfo, response, settings, logger));
454+
452455
// avoid exception to duplicate products in XML
453456
infos.TryAdd(productIdentifier, productInfo);
454457
}

0 commit comments

Comments
 (0)