Developer forum

Forum » Integration » Custom Customer field for Live Prices

Custom Customer field for Live Prices

Chris Søgaard
Chris Søgaard
Reply

Hi

When requesting live prices from code unit, is there any way to control which field on AccessUser table is sent as "AccessUserCustomerNumber" on this request from the setting or is it only possible by extending the live integration framework?

<GetEcomData ExternalUserId="E000010" AccessUserCustomerNumber="20000">
  <tables>
    <Products type="filter" unitPrices="true">
      <Product>
        <ProductId>1906-S</ProductId>
        <ProductVariantId></ProductVariantId>
        <ProductNumber>1900-S</ProductNumber>       
        <ProductIdentifier>1900-S..LANG1</ProductIdentifier> 
        <CurrencyCode>GBP</CurrencyCode>
        <Quantity>1</Quantity>
      </Product>
    </Products>
  </tables>
</GetEcomData>

We have some customers that have structured BC with several accounts for each customer, and sometimes we must sent a custom field as "AccessUserCustomerNumber". Usually we would extend the live integration by including the Live Integration source code, and control it here, but there might be a smarter way to control this?

Best Regards 

Chris


Replies

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

Hi Chris,
in order to change that you need to subscribe to the Live Integration extensibility points:
Notifications.ProductInfo.OnBeforeGenerateProductInfoXml
then inside this subscriber change:
var user = User.GetCurrentExtranetUser();
var originalCustomerNumber = user.CustomerNumber;
Context.Current.Items["originalCustomerNumber"] = originalCustomerNumber;
user.CustomerNumber = yourValue;

Then in order to restore back the changed customer number subscribe to:
Notifications.ProductInfo.OnAfterGenerateProductInfoXml
and restore back:
var user = User.GetCurrentExtranetUser();
user.CustomerNumber = Context.Current.Items["originalCustomerNumber"];

Kind regards, Dmitrij

 

Votes for this answer: 1
 
Chris Søgaard
Chris Søgaard
Reply

Hi Dmitriy

Thank you for the quick reply once again.

This is somehow also what we do today, but just inside the source code for live integration. I will try and use the NotificationSubscribers instead.

BR Chris

 
Chris Søgaard
Chris Søgaard
Reply

Hi Dmitriy

I have tried using the suggested notification subscribers instead of changing the Live Integration source code, as we've previously done. It seems to work with subscribers when rendering product info on pages, but I can't seem to get it to work in the cart and on the order confirmation page.

I have tried using the subscribers "OnBeforeErpCommunication"/"OnAfterErpCommunication" and also "OnBeforeGenerateOrderLineXml"/"OnAfterGenerateOrderLineXml". The first one seems to be hit, but it still shows the wrong price in the cart and on order confirmation screen.

The live prices is shown correctly everywhere on users where we don't have to include the custom field.

Any suggestions?

BR Chris

 
Dynamicweb Employee
Dmitriy Benyuk
Reply

Hi Chris,

It is not clear wha you want to achieve regarding the prices for the Order.
You can use the OnAfterSendingOrderToErp notification and modify responseDocument xml and set your custom prices there, so
they should be taken from that xml and be used later in the next Live integration processing.
Kind regards, Dmitrij

 
Chris Søgaard
Chris Søgaard
Reply

Hi Dmitriy

Yes, maybe I was a bit unclear about this, also I mentioned the order confirmation, but actually I meant the checkout page. I will try and explain in details the problem.

In BC our client have 1 customer number for ordering and 1 customer number for invoicing. The following rules apply:

  • All customer specific prices are related to the invoice customer.
  • All orders should be created on the ordering customer

This effectively means that all requests for getting prices should use the invoice customer number while all creation of orders should use the ordering customer. My job is to show the correct price on the following pages:

  • Product pages
  • Cart(s)
  • Checkout

Your previous example showed me how I could control the request for prices on the product pages, and this works fine. My problem is that I cannot get the prices to show correctly in the cart and on checkout page. I have tried subscribing to these events:

  • OnBeforeSendingOrderToErp/OnAfterSendingOrderToErp
  • OnBeforeErpCommunication/OnAfterErpCommunication
  • OnBeforeGenerateOrderLineXml/OnAfterGenerateOrderLineXml

With a logic equal or similar to this:

        public override void OnNotify(string notification, NotificationArgs args)
        {
            OnBeforeSendingOrderToErpArgs orderArgs = (OnBeforeSendingOrderToErpArgs)args;

            if (orderArgs.Order.Complete)
            {
                User user = User.GetCurrentExtranetUser();
                string billToCustomerValue;
                if (user != null && (billToCustomerValue = user.CustomFieldValues.FirstOrDefault(x => x.CustomField.SystemName == "AccessUser_Bill_to_Customer")?.Value.ToString()) != null)
                {
                    Context.Current.Items["originalCustomerNumber"] = user.CustomerNumber;
                    orderArgs.Order.CustomerNumber = billToCustomerValue;
                }
            }
        }

 

or this

        public override void OnNotify(string notification, NotificationArgs args)
        {
            OnBeforeSendingOrderToErpArgs orderArgs = (OnBeforeSendingOrderToErpArgs)args;

            if (orderArgs.Order.Complete)
            {
                User user = User.GetCurrentExtranetUser();
                string billToCustomerValue;
                if (user != null && (billToCustomerValue = user.CustomFieldValues.FirstOrDefault(x => x.CustomField.SystemName == "AccessUser_Bill_to_Customer")?.Value.ToString()) != null)
                {
                    Context.Current.Items["originalCustomerNumber"] = user.CustomerNumber;
                    user.CustomerNumber = billToCustomerValue;
                }
            }
        }

 

There must be a way to reliably control the order calculation through the subscribers, but I just can't get it to work. Am I using the wrong subscribers?

 

 
Dynamicweb Employee
Dmitriy Benyuk
Reply

Hi Chris,
try to get the user in this way:
var user = User.GetUserByID(order.CustomerAccessUserId) ?? (!ExecutingContext.IsBackEnd() ? User.GetCurrentExtranetUser() : null);
And set its customer number: user?.CustomerNumber
And user OnBeforeGenerateOrderXml/OnAfterGenerateOrderXml notifications.
Regards, Dmitrij

 
Chris Søgaard
Chris Søgaard
Reply

Hi Dmitriy

I have tested this and unfortunately this still gives me the wrong price.

I can see in the order XML send to ERP, that the customer number is still the original customer number and not the custom field that I intend to send. If I use the test tool and apply the custom field value to the XML property "OrderCustomerNumber" I get the correct price.

BR Chris

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

Hi Chris,

here are the working subscribers attached, so you can use them.
Hope that will solve your problem.
The difference was in getting the right user object, it has to be like that:
var user = User.GetUserByID(order.CustomerAccessUserId);
                if (user == null)
                {
                    user = User.GetCurrentExtranetUser();
                }
Kind regards, Dmitrij

Votes for this answer: 1
 
Chris Søgaard
Chris Søgaard
Reply

Hi Dmitriy

This works! Thank you for figuring this out.

BR Chris

 

You must be logged in to post in the forum