Developer forum

Forum » Integration » Ignore variants in BC

Ignore variants in BC

Martin Moen
Reply

We do get an error from BC related to variants.
The variants are setup in DW, but not present in BC. And that is by design since we do not want the variants in BC.
The "variants" are registered in BC as separate item numbers, and we do connect them as variants and family products through DW.

6/29/2022 2:05:49 PM: ConnectionError: Error CalculateOrder Order Id:'ORDERXXXX' CreateOrder:'True' Message:'The remote server returned an error: (500) Internal Server Error. Response: The field Variant Code of table Sales Line contains a value (VOXXX) that cannot be found in the related table (Item Variant).'.


Is it possible tho ignore the variant field in the xml either when DW sends it to BC, or in the BC plugin before it is created/calculated?
Are there any subscribers we can use to manipulate this?


Replies

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

Hi Martin,
yes, you can use the Live integration subscribers.
In the Live integration you can implement the custom product provider like that for the getting specific product information requests:
using Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Configuration;
using Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Products;
using Dynamicweb.Ecommerce.Integration;
using Dynamicweb.Ecommerce.Prices;
using Dynamicweb.Ecommerce.Products;

namespace Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Examples
{
    /// <summary>
    /// Class CustomProductProvider.
    /// </summary>
    /// <seealso cref="Products.ProductProviderBase" />
    public class CustomProductProvider : ProductProviderBase
    {
        /// <summary>
        /// Gets the product identifier.
        /// </summary>
        /// <param name="product">The product.</param>
        /// <returns>System.String.</returns>
        public override string GetProductIdentifier(Settings settings, Product product)
        {
            return GetProductIdentifier(settings, product, null);
        }

        /// <summary>
        /// Gets the product identifier.
        /// </summary>
        /// <param name="product">The product.</param>
        /// <param name="unitId">The product unit Id.</param>
        /// <returns>System.String.</returns>
        public override string GetProductIdentifier(Settings settings, Product product, string unitId)
        {
            string unit = string.IsNullOrEmpty(unitId) ? string.Empty : $"-{unitId}";
            return $"{product.Id}-{product.LanguageId}-{product.Number}{unit}";
        }
    }
}


For the order requests you need to subscribe to:
Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Notifications.Orders.OnAfterGenerateOrderXml
and have the code like that to change the variant id string in the output xml nodes:

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

namespace Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Examples.Notifications
{
    /// <summary>
    /// Class OrderAfterGenerateXmlSubscriber.
    /// </summary>
    /// <seealso cref="NotificationSubscriber" />
    [Subscribe(Order.OnAfterGenerateOrderXml)]
    public class OrderAfterGenerateXmlSubscriber : NotificationSubscriber
    {
        /// <summary>
        /// Call to invoke observer.
        /// </summary>
        /// <param name="notification">The notification.</param>
        /// <param name="args">The args.</param>
        public override void OnNotify(string notification, NotificationArgs args)
        {
            var myArgs = (Order.OnAfterGenerateOrderXmlArgs)args;            
            if (myArgs?.Document != null)
            {
                var settings = SettingsManager.GetSettingsByShop(myArgs.Order.ShopId);
                if (settings != null && !settings.ErpControlsShipping)
                {
                    var order = myArgs.Order;
                    var shipping = Services.Shippings.GetShipping(order.ShippingMethodId);
                    if (shipping != null)
                    {
                        var nodes = myArgs.Document.SelectNodes("//item [@table='EcomOrders']/column[@columnName='OrderLineProductVariantId']");
                        if (nodes != null)
                        {
                            // TODO: Add code here to remove node text
                        }
                    }
                }
            }
        }
    }
}

BR, Dmitrij

Votes for this answer: 1
 
Martin Moen
Reply

Thanks Dmitrij, just what I needed :)

 

You must be logged in to post in the forum