예제 #1
0
        /// <summary>
        /// Initializes this class with default values
        /// </summary>
        private void Initialize()
        {
            // see if the key is already in the request cache
            var cachedContextData = _cache.RequestCache.GetCacheItem(CustomerCookieName);

            if (cachedContextData != null)
            {
                ContextData = (CustomerContextData)cachedContextData;
                var key = ContextData.Key;
                TryGetCustomer(key);
                return;
            }

            // retrieve the merchello consumer cookie
            var cookie = _umbracoContext.HttpContext.Request.Cookies[CustomerCookieName];

            if (cookie != null)
            {
                try
                {
                    ContextData = cookie.ToCustomerContextData();
                    TryGetCustomer(ContextData.Key);
                }
                catch (Exception ex)
                {
                    LogHelper.Error <CustomerContext>("Decrypted guid did not parse", ex);
                    CreateAnonymousCustomer();
                }
            }
            else
            {
                CreateAnonymousCustomer();
            } // a cookie was not found
        }
예제 #2
0
        /// <summary>
        /// Creates an anonymous customer
        /// </summary>
        private void CreateAnonymousCustomer()
        {
            var customer = _customerService.CreateAnonymousCustomerWithKey();

            CurrentCustomer = customer;
            ContextData     = new CustomerContextData()
            {
                Key = customer.Key
            };

            CacheCustomer(customer);
        }