Exemple #1
0
        public IBasket FindBasketById(IUser currentUser, string externalId)
        {
            string pricelistseed = string.Empty;

            if (currentUser != null && currentUser.PriceLists != null)
            {
                pricelistseed = string.Join(",", currentUser.PriceLists);
            }


            string url = $"ShoppingService.svc/rest/GetBasket?id={externalId}&cultureCode={currentUser.LanguageCode}&currencyId={currentUser.CurrencyCode}&pricelistSeed={pricelistseed}";

            var stormBasket = _stormConnectionManager.GetResult <StormBasket>(url);

            if (stormBasket == null)
            {
                return(null);
            }
            if (!stormBasket.IsBuyable)
            {
                return(null);
            }

            return(BasketToDto(stormBasket));
        }
        public ICheckout GetCheckout(IUser currentUser, string basketExternalId)
        {
            string pricelistseed = string.Empty;

            if (currentUser != null && currentUser.PriceLists != null)
            {
                pricelistseed = string.Join(",", currentUser.PriceLists);
            }
            string url = $"ShoppingService.svc/rest/GetCheckout2?format=json";

            url += $"&basketId={basketExternalId}";
            url += addUserUrlDetails(currentUser);

            var stormCheckout = _stormConnectionManager.GetResult <StormCheckout>(url);

            if (stormCheckout == null)
            {
                return(null);
            }

            var checkout = StormCheckoutToCheckoutDto(stormCheckout);

            // Set a default payment method configured in the settings file as Storm:DefaultPaymentMethodId
            var defaultPaymentMethod = _configuration["Storm:DefaultPaymentMethodId"];

            if (!string.IsNullOrEmpty(defaultPaymentMethod))
            {
                if (checkout.PaymentMethod == null)
                {
                    return(SetPaymentMethod(currentUser, basketExternalId, defaultPaymentMethod));
                }
            }

            return(checkout);
        }
Exemple #3
0
        public List <IManufacturer> FindAllManufacturers(IUser currentUser)
        {
            // Find the list of products
            string url = "ProductService.svc/rest/ListManufacturers?format=json";

            url += addUserUrlDetails(currentUser);

            var manufacturerList = _connectionManager.GetResult <ItemListResult <StormManufacturer> >(url);

            List <IManufacturer> list = new List <IManufacturer>();

            foreach (var mfr in manufacturerList.Items)
            {
                ManufacturerDto dto = new ManufacturerDto();
                dto.ExternalId = mfr.Id.ToString();
                dto.Code       = mfr.UniqueName;
                dto.Name       = mfr.Name;
                dto.ImageUrl   = mfr.LogoKey;
                list.Add(dto);
            }

            return(list);
        }
Exemple #4
0
        public IList <ICategory> FindAll(IUser currentUser)
        {
            // URL ProductService.svc/rest/ListCategoryItems?format=json
            string url = $"ProductService.svc/rest/ListCategoryItems";

            // This method is supposed to be stored in cache so that it will not retrieve
            // categories from Storm each time.
            var allCategories = _stormConnectionManager.GetResult <List <StormCategory> >(url);

            IList <ICategory> result = new List <ICategory>();

            foreach (var stormcat in allCategories)
            {
                // This will add all categories recursively since the ToDto()
                // method will run on children.
                result.Add(stormcat.ToDto());
            }

            return(filterRootCategory(result));
        }
Exemple #5
0
        public IUser Login(string username, string password)
        {
            string u = WebUtility.UrlEncode(username);
            string p = WebUtility.UrlEncode(password);

            string url  = $"CustomerService.svc/rest/Login?loginName={username}&password={password}";
            var    user = _stormConnectionManager.GetResult <StormCustomer>(url);

            if (user == null || user.Id == 0)
            {
                return(null);
            }

            UserDto dto = new UserDto();

            dto.ExternalId = user.Id.ToString();
            dto.FirstName  = user.FirstName;
            dto.LastName   = user.LastName;
            dto.Address1   = user.InvoiceAddress?.Line1;
            dto.Address2   = user.InvoiceAddress?.Line2;
            dto.Zip        = user.InvoiceAddress?.Zip;
            dto.Phone      = user.CellPhone;
            dto.City       = user.InvoiceAddress?.City;
            dto.Email      = user.Email;
            dto.Code       = user.Code;

            if (user.PricelistIds != null)
            {
                dto.PriceLists = new List <string>();
                foreach (var entry in user.PricelistIds)
                {
                    dto.PriceLists.Add(entry.ToString());
                }
            }


            return(dto);
        }
        public IProductList FindByCategory(IUser currentUser, IProductListInputModel query)
        {
            // Find the list of products
            string url = "ProductService.svc/rest/ListProducts2?";

            url += addUserUrlDetails(currentUser);

            url += "&statusSeed=" + _configuration["Storm:StatusSeed"];

            if (query.CategoryIds != null)
            {
                url += "&categorySeed=" + string.Join(",", query.CategoryIds);
            }

            if (query.FlagIds != null)
            {
                url += "&flagSeed=" + string.Join(",", query.FlagIds);
            }
            if (!string.IsNullOrEmpty(query.Query))
            {
                url += "&searchString=" + System.Web.HttpUtility.UrlEncode(query.Query);
            }

            url += "&pageNo=" + (query.PageNumber > 0 ? query.PageNumber : 1);
            url += "&pageSize=" + (query.PageSize > 0?query.PageSize:PageSize);
            url += "&asVariants=1";

            var productList = _connectionManager.GetResult <StormProductList>(url);

            ProductListDto result = new ProductListDto();

            result.ProductCount = productList.ItemCount;
            result.PageSize     = PageSize;
            result.PageNumber   = (query.PageNumber > 0 ? query.PageNumber : 1);
            result.Products     = new List <IProduct>();

            Dictionary <string, ProductDto> variants = new Dictionary <string, ProductDto>();

            foreach (var item in productList.Items)
            {
                ProductDto p = (ProductDto)_productBuilder.BuildFromItem(item);

                if (!string.IsNullOrEmpty(p.GroupByKey))
                {
                    if (variants.ContainsKey(p.GroupByKey))
                    {
                        variants[p.GroupByKey].Variants.Add((VariantDto)p.PrimaryVariant);
                    }
                    else
                    {
                        variants[p.GroupByKey] = p;
                        result.Products.Add(p);
                    }
                }
                else
                {
                    result.Products.Add(p);
                }
            }

            return(result);
        }