Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • William Zhang 39 posts 243 karma points
    Aug 26, 2016 @ 18:03
    William Zhang
    0

    NullReferenceException for OrderShipped notification

    Hi,

    I'm getting a NullReferenceException for the OrderShipped notification. The error occurs in RazorMonitorBase in the OnNext() method:

    public override void OnNext(TModel value)
    {
        if (!Messages.Any()) return;
    
        var formatter = new RazorFormatter(value);
    
        foreach (var message in Messages)
        {
            // --> Error occurs here because value.Contacts is null
            if (value.Contacts.Any() && message.SendToCustomer)
            {
                // add the additional contacts to the recipients list
                if (!message.Recipients.EndsWith(";"))
                    message.Recipients += ";";
    
                if (message.Recipients[0] == ';')
                    message.Recipients = message.Recipients.TrimStart(';');
    
                message.Recipients = string.Format("{0}{1}", message.Recipients, string.Join(";", value.Contacts));
            }
    
            // send the message
            NotificationContext.Send(message, formatter);
        }
    }
    

    I'm not really sure how to prevent this error, since it seems that the Contacts property is never set in the OrderShippedTrigger class:

    protected override void Notify(IShipment model, IEnumerable<string> contacts)
    {
        if (model == null || !model.Items.Any()) return;
        // The contacts parameter is never passed into the factory?
        var notifyModel = _factory.Value.Build(model);
    
        NotifyMonitors(notifyModel);
    }
    

    So even if I provide an empty list of contacts to the Notification.Trigger() method it still doesn't fix the issue...

  • William Zhang 39 posts 243 karma points
    Aug 31, 2016 @ 10:22
    William Zhang
    0

    Anyone?

  • Simon Dingley 1470 posts 3427 karma points c-trib
    Nov 07, 2016 @ 13:19
    Simon Dingley
    0

    Hi William - did you ever resolve this? I have the same problem at the moment.

  • William Zhang 39 posts 243 karma points
    Nov 07, 2016 @ 13:28
    William Zhang
    0

    Hi Simon,

    Nope, I ended up dumping the Notification handler and manually sending emails with the .NET SmtpClient, and using Merchello's RazorFormatter to format the Razor templates.

  • Simon Dingley 1470 posts 3427 karma points c-trib
    Nov 07, 2016 @ 13:40
    Simon Dingley
    0

    In case it might be of use to you I just had success creating my own monitor and adding the contact as follows:

    namespace MyProject.Infrastructure.Workflow.Notification.Monitor
    {
        using Merchello.Core.Gateways.Notification;
        using Merchello.Core.Gateways.Notification.Triggering;
        using Merchello.Core.Models.MonitorModels;
        using Merchello.Core.Observation;
        using Merchello.Web.Workflow.Notification.Monitor;
    
        [MonitorFor("641FC661-4A17-4CB1-A321-AF267985B03F", typeof(OrderShippedTrigger), "Order Shipped ()", true)]
        public class MyProjectOrderShippedMonitor : RazorMonitorBase<IShipmentResultNotifyModel>
        {
            /// <summary>
            /// Initializes a new instance of the <see cref="OrderShippedMonitor"/> class.
            /// </summary>
            /// <param name="notificationContext">
            /// The notification context.
            /// </param>
            public MyProjectOrderShippedMonitor(INotificationContext notificationContext)
                : base(notificationContext)
            {
            }
    
            public override void OnNext(IShipmentResultNotifyModel value)
            {
                value.Contacts = new[] { value.Shipment.Email };
                base.OnNext(value);
            }
        }
    }
    
  • William Zhang 39 posts 243 karma points
    Nov 07, 2016 @ 13:46
    William Zhang
    0

    Great, thanks!

    I didn't create my own monitor since I assumed that this would be fixed in future versions of Merchello :) If I'm not mistaken this should be fixed in v2.3 - which version are you running?

  • Simon Dingley 1470 posts 3427 karma points c-trib
    Nov 07, 2016 @ 13:47
    Simon Dingley
    0

    v2.2 on this site. I'll have to check newer versions and make sure I remove my monitor after upgrading or duplicates will be sent out.

    Thanks

Please Sign in or register to post replies

Write your reply to:

Draft