Ejemplo n.º 1
0
        public async Task <CartBuilder> GetOrCreateNewTransientCartAsync(Store store, Customer customer, Language language, Currency currency)
        {
            _store        = store;
            _customer     = customer;
            _currency     = currency;
            _language     = language;
            _cartCacheKey = GetCartCacheKey(store.Id, customer.Id);

            _cart = await _cacheManager.GetAsync(_cartCacheKey, _cartCacheRegion, async() =>
            {
                ShoppingCart retVal;

                var cartSearchResult = await _cartApi.CartModuleGetCurrentCartAsync(_store.Id, _customer.Id);
                if (cartSearchResult == null)
                {
                    retVal = CreateNewTransientCart();
                }
                else
                {
                    var detalizedCart = await _cartApi.CartModuleGetCartByIdAsync(cartSearchResult.Id);
                    retVal            = detalizedCart.ToWebModel(_currency, _language);
                }

                return(retVal);
            });

            await EvaluatePromotionsAsync();

            return(this);
        }
Ejemplo n.º 2
0
        public virtual async Task <ICartBuilder> GetOrCreateNewTransientCartAsync(Store store, CustomerInfo customer, Language language, Currency currency)
        {
            var cacheKey = GetCartCacheKey(store.Id, customer.Id);

            _cart = await _cacheManager.GetAsync(cacheKey, _cartCacheRegion, async() =>
            {
                ShoppingCart retVal;

                var cartSearchResult = await _cartApi.CartModuleGetCurrentCartAsync(store.Id, customer.Id);
                if (cartSearchResult == null)
                {
                    retVal = new ShoppingCart(currency, language);

                    retVal.CustomerId = customer.Id;
                    retVal.Name       = "Default";
                    retVal.StoreId    = store.Id;

                    if (!customer.IsRegisteredUser)
                    {
                        retVal.CustomerName = StorefrontConstants.AnonymousUsername;
                    }
                    else
                    {
                        retVal.CustomerName = string.Format("{0} {1}", customer.FirstName, customer.LastName);
                    }
                }
                else
                {
                    var detalizedCart = await _cartApi.CartModuleGetCartByIdAsync(cartSearchResult.Id);
                    retVal            = detalizedCart.ToWebModel(currency, language);
                }
                retVal.Customer = customer;


                return(retVal);
            });

            return(this);
        }