Developer forum

Forum » Integration » Live Integration and custom Shipping Provider

Live Integration and custom Shipping Provider

Lars Bo Wassini Dynamicweb Employee
Lars Bo Wassini
Reply

I have a customer where the shipping options are dependent on the items in the cart. This means that even though the the shipping fee is calculated by the ERP (BC), we have created a shipping provider to let the user have access to the different delivery methods.

When a cart is going through the checkout process, we send the cart to BC using the custom shipping provider. BC then returns a list of shipping options including the fee and we shows this to the customer, who then selects the wanted shipping provider. This provider is then sent to BC with the order.

The problem is now that when we set the Live Integration option "ERP controls shipping calculations" our custom shipping provider is never called, BUT if we disable it, a standard shipping line is added to the order using the Live Integration/Code Unit. Is there a way to prevent the Live Integration from creating the additional order line?


Replies

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply

Hi Lars,
if you want to disable the creation of the shipping order line from the Codeunit then you need to set the option "ERP controls shipping" to true.
BR, Dmitrij

 
Lars Bo Wassini Dynamicweb Employee
Lars Bo Wassini
Reply

But then the custom shipping provider is never called. It seems that the check also disables our custom code.

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

That should not happen but if it doesn't work then you can try this approach:
1) Subscribe to OnBeforeGenerateOrderXml:
settings.ErpControlsShipping = true; // This will prevent addition of the shipping order line in the response
2) Subscribe to OnAfterGenerateOrderXml:
settings.ErpControlsShipping = false; // Restore changed value back so custom provider is called

Votes for this answer: 1
 
Lars Bo Wassini Dynamicweb Employee
Lars Bo Wassini
Reply

Thanks.

We have changed from a custom shipping provider to a subscriber.

 
Lars Bo Wassini Dynamicweb Employee
Lars Bo Wassini
Reply

It seems that when we prevent this line from being sent we have run into another problem: If the line is not sent, the Code Unit returns the total price - witout the shipping fee we provide in the XML.

This wouldn't be a problem if DW then would add the fee from our custom shipping provider - but this is not happening when using full card communication. Instead it takes the total price returned from the ERP and then it SUBTRACTS the shipping fee to calculate the sub-total.

For anonymous customers (not using the live integration) everything works as expected.

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply

Then In OnBeforeGenerateOrderXml subscriber you can check if the order is Complete and if yes (that would be a CreateOrder request) then ensure that: 
settings.ErpControlsShipping = false; // this will add the shipping fields to the request so codeunit will add that shipping price to the total order:

// Dynamicweb handles shipping
AddChildXmlNode(itemNode, "OrderShippingMethodName", order.ShippingMethod, true);
AddChildXmlNode(itemNode, "OrderShippingMethodId", order.ShippingMethodId);
AddChildXmlNode(itemNode, "OrderShippingFee", order.ShippingFee.PriceWithVAT.ToIntegrationString(currentSettings, logger));
AddChildXmlNode(itemNode, "OrderShippingFeeWithoutVat", order.ShippingFee.PriceWithoutVAT.ToIntegrationString(currentSettings, logger));
AddChildXmlNode(itemNode, "OrderShippingItemType", settings.ErpShippingItemType);
AddChildXmlNode(itemNode, "OrderShippingItemKey", settings.ErpShippingItemKey);
AddChildXmlNode(itemNode, "OrderShippingCode", order.ShippingMethodCode);
AddChildXmlNode(itemNode, "OrderShippingAgentCode", order.ShippingMethodAgentCode);
AddChildXmlNode(itemNode, "OrderShippingAgentServiceCode", order.ShippingMethodAgentServiceCode);

If you need smth changed in the request xml then you can change the xml in the OnAfterGenerateOrderXml subscriber


 

 

You must be logged in to post in the forum