Developer forum

Forum » Integration » Populate ProductInfo LiveIntegration with custom data from ERP

Populate ProductInfo LiveIntegration with custom data from ERP

Jan Sangill
Reply

Hi,
Previously we used a custom project for LiveIntegration. As we upgraded to newest DW 9 - we use this version directly in DW9.

We have an issue here, where the ERP is sending QuantatyPrices along like this:

<table tableName="EcomProducts">
    <item table="EcomProducts">
      <column columnName="ProductId"><![CDATA[370080]]></column>
      <column columnName="ProductVariantId"><![CDATA[104720]]></column>
      <column columnName="ProductIdentifier"><![CDATA[370080.104720.LANG2]]></column>
      <column columnName="ProductNumber"><![CDATA[370080]]></column>
      <column columnName="ProductPrice"><![CDATA[78.88]]></column>
      <column columnName="ProductPriceWithVat"><![CDATA[98.60]]></column>
      <column columnName="ProductStock"><![CDATA[0]]></column>
      <column columnName="ProductCurrencyCode"><![CDATA[]]></column>
      <QuantityPrices>
        <QuantityPrice>
          <Quantity>12</Quantity>
          <PriceQuantity>34.55</PriceQuantity>
          <CurrencyCode />
        </QuantityPrice>
      </QuantityPrices>
....

In the Old setup in ProcessResponse this was done:

 

 var tupleList = new List<(string, string)>();
 var quantityPriceNodes = item.SelectNodes("QuantityPrices/QuantityPrice");

 foreach (XmlElement ele in quantityPriceNodes)
 {
     tupleList.Add((
         ele.SelectSingleNode("Quantity")?.InnerText,
         ele.SelectSingleNode("PriceQuantity")?.InnerText)
     );
 }

 productInfo["PricePrQuantity"] = tupleList;

How can I achieve this in the new with a subscriber? Since I do not get the original XML in OnAfterGenerateProductInfoXml or in OnBeforeGenerateProductInfoXml I cant manipulate the XML.

Any ideas?


Replies

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Hi Jan

OnAfterGenerateProductInfoXml  exposes an XmlDocument that you can interrogate for the prices:

var myArgs = (ProductInfo.OnAfterGenerateProductInfoXmlArgs)args;
if (myArgs?.XmlDocument != null)
{
  // Use myArgs.XmlDocument here which contains the response from the ERP.
}

If that's not what you need, can you elaborate on what you mean with "original XML"?

Imar

 

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Oh, I think I see what you mean. OnBeforeGenerateProductInfoXml  and OnAfterGenerateProductInfoXml both run before communicating with the ERP and allow you to manipulate the request only. If you need the response, subscribe to OnAfterErpCommunication which exposes OnAfterErpCommunicationArgs as the args class which looks like this:

public class OnAfterErpCommunicationArgs : NotificationArgs
{
    public OnAfterErpCommunicationArgs(string request, string response, XmlDocument xmlDocument, string referenceName, Exception exception, Settings settings, Logger logger)
    {
        Request = request;
        Response = response;
        XmlDocument = xmlDocument;
        ReferenceName = referenceName;
        Exception = exception;
        Settings = settings;
        Logger = logger;
    }
}

XmlDocument contains the response XML and ReferenceName contains a marker (like GetProductsInfo in your example) which you can use to figure out what type of request was made.

Hope this helps,

Imar

 

 
Jan Sangill
Reply

Hi, yes this helped a little.

OnAfterErpCommunication does give me the XmlDocument. 

What I am doing is I am calling myself:
 ProductManager.GetProductInfo(product, settings, user);
This returns only the productInfo dictionary.

I have tried manipulating the XmlDocument in OnAfterErpCommunication without luck. Nothing is added to that I actually add. 
I am trying to add a node with: QuantityPrices (se below actual response returned.)
I have even tried just adding a random node to <item table="EcomProducts">.

Is this possible? Am I just doing it wrong:>?

This is how the XML is in response:
<tables version="1.2.0.51_NAV26.0.34122.0">
  <table tableName="EcomProducts">
    <item table="EcomProducts">
      <column columnName="ProductId"><![CDATA[370080]]></column>
      <column columnName="ProductVariantId"><![CDATA[104720]]></column>
      <column columnName="ProductIdentifier"><![CDATA[370080.104720.LANG2]]></column>
      <column columnName="ProductNumber"><![CDATA[370080]]></column>
      <column columnName="ProductPrice"><![CDATA[78.88]]></column>
      <column columnName="ProductPriceWithVat"><![CDATA[98.60]]></column>
      <column columnName="ProductStock"><![CDATA[0]]></column>
      <column columnName="ProductCurrencyCode"><![CDATA[]]></column>
      <QuantityPrices>
        <QuantityPrice>
          <Quantity>12</Quantity>
          <PriceQuantity>34.55</PriceQuantity>
          <CurrencyCode />
        </QuantityPrice>
      </QuantityPrices>
      <UnitOfMeasures>
        <UnitOfMeasure>
          <Quantity>1</Quantity>
          <Code>BDT</Code>
        </UnitOfMeasure>
        <UnitOfMeasure>
          <Quantity>25</Quantity>
          <Code>KRT</Code>
        </UnitOfMeasure>
      </UnitOfMeasures>
    </item>
  </table>
</tables>

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

I see. I think you're right. Looks like the XML is sent to the Subscriber, but upon return it uses the original XML, not the modified XML so it's not aware of the changes. Then I am out of ideas. Maybe @Dmitriy knows how to do this.

Imar

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply

Hi Jan,
could you modify the ERP side so it returns the EcomPrices as a separate xml table like this:
Request:

<GetEcomData AccessUserCustomerNumber="56222000">
  <tables>
    <Products type="filter" unitPrices="true">
      <Product>
        <ProductId>6127201390</ProductId>
        <ProductVariantId></ProductVariantId>
        <ProductNumber>6127201390</ProductNumber>       
        <ProductIdentifier></ProductIdentifier> 
        <CurrencyCode>DKK</CurrencyCode>
        <Quantity>400</Quantity>
      </Product>
    </Products>
  </tables>
</GetEcomData>

Response:

<?xml version="1.0" encoding="utf-16"?>
<tables version="1.2.0.19_NAV19.0.29884.32731">
  <table tableName="EcomProducts">
    <item table="EcomProducts">
      <column columnName="ProductId"><![CDATA[6127201390]]></column>
      <column columnName="ProductVariantId"><![CDATA[]]></column>
      <column columnName="ProductIdentifier"><![CDATA[]]></column>
      <column columnName="ProductNumber"><![CDATA[6127201390]]></column>
      <column columnName="ProductPrice"><![CDATA[90]]></column>
      <column columnName="ProductStock"><![CDATA[0]]></column>
      <column columnName="ProductCurrencyCode"><![CDATA[]]></column>
      <column columnName="ProductDefaultUnitId"><![CDATA[Unit_STK]]></column>
    </item>
  </table>
  <table tableName="EcomPrices">
    <item table="EcomPrices">
      <column columnName="PriceProductId"><![CDATA[6127201390]]></column>
      <column columnName="PriceUserCustomerNumber"><![CDATA[56222000]]></column>
      <column columnName="PriceProductUnitId"><![CDATA[Unit_KASSE]]></column>
      <column columnName="PriceQuantity"><![CDATA[400]]></column>
      <column columnName="PriceAmount"><![CDATA[90]]></column>
    </item>
    <item table="EcomPrices">
      <column columnName="PriceProductId"><![CDATA[6127201390]]></column>
      <column columnName="PriceUserCustomerNumber"><![CDATA[56222000]]></column>
      <column columnName="PriceProductUnitId"><![CDATA[Unit_PAKKE]]></column>
      <column columnName="PriceQuantity"><![CDATA[144]]></column>
      <column columnName="PriceAmount"><![CDATA[90]]></column>
    </item>
  </table>
</tables>

Then this "Prices" information will be populated by the Live integration into the productInfo object so you can then acces it using this code:

var prices = (IList<ProductPrice>)productInfo["Prices"];

BR, Dmitrij

 
Jan Sangill
Reply

Hi DImitri, I can find out if that is possible. Is this the only way to achieve this? No way for me to hook into something so I can actually get this back in PriceInfo via:
ProductManager.GetProductInfo(product, settings, user);

Let me know

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply
This post has been marked as an answer

Hi Jan,
it seems you can try to create you custom product provider instead:
CustomProductProvider : ProductProviderBase
and then override the method:

public virtual IList<ProductPrice> ExtractPrices(Settings settings, XmlDocument response, Logger logger)

There you can parse the custom response xml and fill the list of prices which then will be added to the productInfo object.
BR, Dmitrij

Votes for this answer: 1
 
Jan Sangill
Reply

Hi Dmitriy , Ty. That would do it properly.

 

You must be logged in to post in the forum