Developer forum

Forum » Integration » QueuedOrdersSyncScheduledTask not working if carts not enabled for anonymous users

QueuedOrdersSyncScheduledTask not working if carts not enabled for anonymous users

Jan Sangill
Reply

Hi,

WHat would be the best approach to send orders to BC if you are running the website with live integration when users are logged in, but with prices from the DW if users are not logged in?

The checkbox "Carts and orders for anonymous users" is not set, because I only need this if a user is logged in.

If a user is not logged in, the orders processed still need to go to BC. I have setup the task QueuedOrdersSyncScheduledTask to achieve this. However this then says it cant run because anonymous orders are not allowed. COuld I overwite this in this specifick instance - or is there a smarter way to achieve this?

Does it make sense? Let me know.


Replies

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply

Hi Jan,
it looks like you need to uncheck the "Live product info for anonymous users" option and check the  "Carts and orders for anonymous users" option, so in that case the prices for the not logged in users will be from Dynamicweb while order calculation and creation will go to the BC.
Hope that helps
BR, Dmitrij

 
Jan Sangill
Reply

Hi Dmitriy,

the issue is I do not want the Carts and orders for anonymous users checcked, because then this will be calculated from ERP for these people. This should only happen for logged in users.?

But I cant export the orders if it is unchecked:/ Which I need to do.

Any way to set this before I run this addin and then set it back after addin?

Does this make sense?

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

Hi Jan,
then you need to implement the custom subscriber to the Live integration event: OnBeforeSendingOrderToErp
and have the code like that:

using Dynamicweb.Extensibility.Notifications;
using Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Notifications;
using Dynamicweb.Environment;
using Dynamicweb.Security.UserManagement;

namespace Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Examples.Notifications
{    
    /// <summary>
    /// Class OrderBeforeSendToErpSubscriber.
    /// </summary>
    /// <seealso cref="NotificationSubscriber" />
    [Subscribe(Order.OnBeforeSendingOrderToErp)]
    public class OrderBeforeSendToErpSubscriber : 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.OnBeforeSendingOrderToErpArgs)args;

            // TODO: Add code here            
            if(!myArgs.CreateOrder && ExecutingContext.IsFrontEnd())            
            {
                var user = User.GetUserByID(myArgs.Order.CustomerAccessUserId);
                if (user == null)
                {
                    myArgs.Cancel = true;
                }
            }
        }
    }
}


And set the checkbox "
Carts and orders for anonymous users" to on. Then the subscriber will cancel order sending when the order is not complete and there is no logged in user.

BR, Dmitrij

Votes for this answer: 1
 
Jan Sangill
Reply

Yes - ofc:> That would be a way out of it. It is implemented, and seems to be working as it should be.

TY

 

You must be logged in to post in the forum