Developer forum

Forum » Integration » Dynamicweb Connector Service

Dynamicweb Connector Service

Bjørn Ingebrigtsen
Reply

Is there a way to include Company name in Live Integration so we can direct the call to the correct company in  AX/FO?
Currently I am not able to manipulate the XML that is sent in with the request for product info. 


Replies

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply
This post has been marked as an answer

Hi there,

You can subscribe to notifications like Order.OnAfterGenerateOrderXml. For example:

using Dynamicweb.Extensibility.Notifications;
using Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Notifications;
using Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Configuration;
using System.Xml;

namespace Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Examples.Notifications
{
    [Subscribe(Order.OnAfterGenerateOrderXml)]
    public class OrderAfterGenerateXmlSubscriber : NotificationSubscriber
    {
        public override void OnNotify(string notification, NotificationArgs args)
        {
            var myArgs = (Order.OnAfterGenerateOrderXmlArgs)args;

            if (myArgs?.Document != null)
            {
                var itemNode = myArgs.Document.SelectSingleNode("//item [@table='EcomOrders']");
                if (itemNode != null)
                {
                    AddChildXmlNode(itemNode, "CompanyCode", GetCompanyCode(myArgs.Order));
                }
            }
        }

        private string GetCompanyCode(Order order)
        {
            // Do something to get the code
            return companyCode
        }
        
        private void AddChildXmlNode(XmlNode parent, string nodeName, string nodeValue)
        {
            var node = parent.OwnerDocument.CreateElement("column");
            node.SetAttribute("columnName", nodeName);
            node.InnerText = nodeValue;
            parent.AppendChild(node);
        }
    }
}

Within this subscriber you have access to the XML document and the Order. You can then have some logic that gets the company code and adds it as a node in the XML

Hope this helps,

Imar

Votes for this answer: 1
 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

BTW: the code above is for an order. For live prices you can use OnAfterGenerateProductInfoXml and its associated OnAfterGenerateProductInfoXmlArgs class.

Imar

 
Bjørn Ingebrigtsen
Reply
This post has been marked as an answer

Thanks Imar!

I thought I could set it in the Live integration connection and have multiple Live integration elements, but this definitely is easier.

Votes for this answer: 1
 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

>> I thought I could set it in the Live integration connection and have multiple Live integration elements

I think the common way to do that is to register multiple live connections, each targeting a different company. You can then select the correct connection by associating a live connection with a site and shop:

That's more visible than a subscriber, but whether you can use it or not depends on your scenario.

 

 
Bjørn Ingebrigtsen
Reply

The last solution was what I was thinking, but I would still need to use subscription to pass along the Company name, since there is no option to include anything in the live integration setup. 

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

I guess you could when you set up multiple end points that then connect to a specific company directly. But if the company needs to be determined at runtime, the subscriber route is your best option.

Cheers,

Imar

 

You must be logged in to post in the forum