Exemplo n.º 1
0
        /// <summary>
        /// Inits the marketing context.
        /// </summary>
        private void InitMarketingContext()
        {
            OrderGroup group = OrderGroup;

            _currency = group.BillingCurrency;
            SetContext(MarketingContext.ContextConstants.ShoppingCart, group);

            // Set customer segment context
            var principal = PrincipalInfo.CurrentPrincipal;

            if (principal != null)
            {
                CustomerProfileWrapper profile = GetCurrentUserProfile();
                if (profile != null)
                {
                    SetContext(MarketingContext.ContextConstants.CustomerProfile, profile);

                    var contactId       = principal.GetContactId();
                    var customerContact = CustomerContext.Current.GetContactById(contactId);
                    if (contactId != group.CustomerId)
                    {
                        customerContact = CustomerContext.Current.GetContactById(group.CustomerId);
                    }
                    if (customerContact != null)
                    {
                        SetContext(MarketingContext.ContextConstants.CustomerContact, customerContact);

                        Guid accountId      = (Guid)customerContact.PrimaryKeyId;
                        Guid organizationId = Guid.Empty;
                        if (customerContact.ContactOrganization != null)
                        {
                            organizationId = (Guid)customerContact.ContactOrganization.PrimaryKeyId;
                        }

                        SetContext(MarketingContext.ContextConstants.CustomerSegments, MarketingContext.Current.GetCustomerSegments(accountId, organizationId));
                    }
                }
            }

            // Set customer promotion history context
            SetContext(MarketingContext.ContextConstants.CustomerId, OrderGroup.CustomerId);

            // Now load current order usage dto, which will help us determine the usage limits
            // Load existing usage Dto for the current order
            PromotionUsageDto usageDto = PromotionManager.GetPromotionUsageDto(0, Guid.Empty, group.OrderGroupId);

            SetContext(MarketingContext.ContextConstants.PromotionUsage, usageDto);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Inits the marketing context.
        /// </summary>
        private void InitMarketingContext()
        {
            OrderGroup group = this.OrderGroup;

            SetContext(MarketingContext.ContextConstants.ShoppingCart, group);

            // Set customer segment context
            MembershipUser user = SecurityContext.Current.CurrentUser;

            if (user != null)
            {
                CustomerProfileWrapper profile = SecurityContext.Current.CurrentUserProfile as CustomerProfileWrapper;

                if (profile != null)
                {
                    SetContext(MarketingContext.ContextConstants.CustomerProfile, profile);

                    CustomerContact customerContact = CustomerContext.Current.GetContactForUser(user);
                    if ((Guid)customerContact.PrimaryKeyId != group.CustomerId)
                    {
                        customerContact = CustomerContext.Current.GetContactById(group.CustomerId);
                    }
                    if (customerContact != null)
                    {
                        SetContext(MarketingContext.ContextConstants.CustomerContact, customerContact);

                        Guid accountId      = (Guid)customerContact.PrimaryKeyId;
                        Guid organizationId = Guid.Empty;
                        if (customerContact.ContactOrganization != null)
                        {
                            organizationId = (Guid)customerContact.ContactOrganization.PrimaryKeyId;
                        }

                        SetContext(MarketingContext.ContextConstants.CustomerSegments, MarketingContext.Current.GetCustomerSegments(accountId, organizationId));
                    }
                }
            }

            // Set customer promotion history context
            SetContext(MarketingContext.ContextConstants.CustomerId, this.OrderGroup.CustomerId);

            // Now load current order usage dto, which will help us determine the usage limits
            // Load existing usage Dto for the current order
            PromotionUsageDto usageDto = PromotionManager.GetPromotionUsageDto(0, Guid.Empty, group.OrderGroupId);

            SetContext(MarketingContext.ContextConstants.PromotionUsage, usageDto);
        }