Example #1
0
        /// <summary>
        /// Merge anonymous user quote to newly log in user quote by log in event
        /// </summary>
        public virtual async Task Handle(UserLoginEvent @event)
        {
            if (@event == null)
            {
                return;
            }
            var workContext  = @event.WorkContext;
            var prevUser     = @event.WorkContext.CurrentUser;
            var prevUserCart = @event.WorkContext.CurrentCart.Value;

            //If previous user was anonymous and it has not empty cart need merge anonymous cart to personal
            if (workContext.CurrentStore.QuotesEnabled && !prevUser.IsRegisteredUser &&
                workContext.CurrentQuoteRequest != null && workContext.CurrentQuoteRequest.Value.Items.Any())
            {
                await _quoteBuilder.GetOrCreateNewTransientQuoteRequestAsync(workContext.CurrentStore, @event.User, workContext.CurrentLanguage, workContext.CurrentCurrency);

                await _quoteBuilder.MergeFromOtherAsync(workContext.CurrentQuoteRequest.Value);

                await _quoteBuilder.SaveAsync();
            }
        }