Copied to clipboard

Flag this post as spam?

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


  • Eidos 44 posts 66 karma points
    Feb 04, 2015 @ 11:56
    Eidos
    0

    Receiver Email replicated

    The "order confirmation" email is sent to all customer email of all order (before the site is restarted)

    I simplified my checkout code in:

    IBasket basket = CurrentCustomer.Basket();
                BasketSalePreparation basketSalePreparation = basket.SalePreparation();
                IAddress address = new Address();
                address.Address1 = "Address1";
                address.Address2 = "Address2";
                address.CountryCode = "IT";
                address.Email = "umbracoATgruppoeidosDOTit";
                address.IsCommercial = false;
                address.Locality = "Locality";
                address.Name = "Name";
                address.Organization = "Organization";
                address.Phone = "Phone";
                address.PostalCode = "PostalCode";
                address.Region = "Region";
                basketSalePreparation.SaveBillToAddress(address);
                basketSalePreparation.SaveShipToAddress(address);
                IEnumerable paymentS = MerchelloContext.Current.Gateways.Payment.GetPaymentGatewayMethods();
                IPaymentGatewayMethod p = paymentS.FirstOrDefault();
                if (p != null)
                {
                    basketSalePreparation.SavePaymentMethod(p.PaymentMethod);
                    IShipment shipment = Basket.PackageBasket(address).FirstOrDefault();
                    IEnumerable quotes = shipment.ShipmentRateQuotes();
                    IEnumerable shipmentRateQuotes = quotes as IShipmentRateQuote[] ?? quotes.ToArray();
                    if (shipmentRateQuotes.Count() > 0)
                    {
                        IShipmentRateQuote q = shipmentRateQuotes.ElementAt(0);
                        IShipmentRateQuote quote = shipment.ShipmentRateQuoteByShipMethod(q.ShipMethod.Key);
                        basketSalePreparation.SaveShipmentRateQuote(quote);
                        if (basketSalePreparation.IsReadyToInvoice())
                        {
                            IPaymentResult attempt = basketSalePreparation.AuthorizePayment(p.PaymentMethod.Key);
                            if (attempt.Payment.Success)
                            {
                                IEnumerable emailS = new[] { basketSalePreparation.GetBillToAddress().Email };
                                Notification.Trigger("OrderConfirmation", attempt, emailS);
                            }
                        }
                    }
                }

     

    First order email is sent to "umbracoATgruppoeidosDOTit", second order is sent to "umbracoATgruppoeidosDOTit" and "umbracoATgruppoeidosDOTit", and so on.

    Where is wrong?

    Thanks!

  • Alex Lindgren 159 posts 356 karma points
    Feb 05, 2015 @ 22:51
    Alex Lindgren
    0

    I am running into this exact same problem. One thing I've noticed is that when the application is restarted it gets 'reset' back to just the one (or more) that were set in the back office. You can also check by looking at the record in the table .merchNotificationMessage. (I was confused at first, because I must have saved the additional recipients at one point.) FYI, I'm running Merchello 1.5 which I've forked. Any work-arounds appreciated!

    Alex

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Feb 05, 2015 @ 23:06
    Rusty Swayne
    0

    This sounds like a caching issue that I thought had been patched. I'll take another look and get it patched up for the 1.7.0 release which will be out by Tuesday at the latest.

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Feb 05, 2015 @ 23:44
    Rusty Swayne
    1

    Alex,

    If you are working on a Merchello Fork try adding

    this.RebuildCache();
    

    as the first line in the OrderConfirmationMonitor class's OnNext method.

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Feb 05, 2015 @ 23:45
    Rusty Swayne
    0

    This definitely has not been fixed so a better solution will be included in 1.7.0 next week.

  • Alex Lindgren 159 posts 356 karma points
    Feb 06, 2015 @ 18:15
    Alex Lindgren
    1

    Thanks Rusty. Not sure why, but this.RebuildCache() did not work for me but I was able to add some code that copied the list of recipients to a variable and then add it back. It's hacky, but we are going live very, very soon, and I needed to resolve this (and I had already forked Merchello core). Thanks again Rusty for helping me out!

    Most people should wait for 1.7.0, but here's the code from the OnNext method of the OrderConfirmationMonitor class with my hack:

            foreach (var message in Messages)
            {
                string originalRecipients = message.Recipients; // hack
                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);
                message.Recipients = originalRecipients; // hack
            }
    
  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Feb 10, 2015 @ 16:09
    Rusty Swayne
    0

    Alex,

    The fix in 1.7.0 works well and is proved in several integration tests.

    I've added an extension method to INotificationMessage

              /// <summary>
        /// Performs a member wise clone of a notification message
        /// </summary>
        /// <param name="message">
        /// The message to be cloned.
        /// </param>
        /// <returns>
        /// The <see cref="INotificationMessage"/>.
        /// </returns>
        public static INotificationMessage MemberwiseClone(this INotificationMessage message)
        {
            ////http://issues.merchello.com/youtrack/issue/M-591
            return new NotificationMessage(message.MethodKey, message.Name, message.FromAddress)
                            {
                                Key = message.Key,
                                BodyText = message.BodyText,
                                Recipients = message.Recipients,
                                BodyTextIsFilePath = message.BodyTextIsFilePath,
                                Description = message.Description,
                                Disabled = message.Disabled,
                                MaxLength = message.MaxLength,
                                MonitorKey = message.MonitorKey,
                                ReplyTo = message.ReplyTo,
                                SendToCustomer = message.SendToCustomer,
                                CreateDate = message.CreateDate,
                                UpdateDate = message.UpdateDate
                            };
        }
    

    and then used return a member wise clone of the message from Messages property of Merchello.Core.Gateways.Notification.Monitors.NotificationMonitorBase

              /// <summary>
        /// Gets the cached collection of <see cref="INotificationMessage"/>
        /// </summary>
        protected IEnumerable<INotificationMessage> Messages
        {
            get
            {
                ////http://issues.merchello.com/youtrack/issue/M-591
                return _messages.Value.Select(x => x.MemberwiseClone());
            }
        }
    
Please Sign in or register to post replies

Write your reply to:

Draft