Posted on 26/04/2021 10:24:33
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?