Ejemplo n.º 1
0
        protected virtual async Task <Store> ConvertStoreAndLoadDependeciesAsync(StoreApi.Store storeDto, Currency currency = null)
        {
            var result = storeDto.ToStore();

            if (currency != null)
            {
                var paymentSearchCriteria = new PaymentMethodsSearchCriteria {
                    StoreId = result.Id
                };
                var paymentsSearchResult = await _paymentModule.SearchPaymentMethodsAsync(paymentSearchCriteria);

                result.PaymentMethods = paymentsSearchResult.Results
                                        .Where(pm => pm.IsActive != null && pm.IsActive.Value)
                                        .Select(pm =>
                {
                    var paymentMethod         = pm.ToStorePaymentMethod(currency);
                    paymentMethod.Name        = pm.TypeName;
                    paymentMethod.DisplayName = pm.Name;
                    return(paymentMethod);
                }).ToArray();
            }
            var taxSearchCriteria = new TaxProviderSearchCriteria {
                StoreId = result.Id
            };
            var taxProviderSearchResult = await _taxModule.SearchTaxProvidersAsync(taxSearchCriteria);

            result.FixedTaxRate = GetFixedTaxRate(taxProviderSearchResult.Results.Select(xp => xp.JsonConvert <TaxProvider>()).ToArray());

            //use url for stores from configuration file with hight priority than store url defined in manager
            result.Url = _storefrontOptions.StoreUrls[result.Id] ?? result.Url;

            return(result);
        }
Ejemplo n.º 2
0
        public async Task <Store> GetStoreByIdAsync(string id, Currency currency)
        {
            var storeDto = await _storeApi.GetStoreByIdAsync(id);

            var result = storeDto.ToStore();

            if (!storeDto.PaymentMethods.IsNullOrEmpty() && currency != null)
            {
                result.PaymentMethods = storeDto.PaymentMethods
                                        .Where(pm => pm.IsActive != null && pm.IsActive.Value)
                                        .Select(pm => pm.ToStorePaymentMethod(currency)).ToArray();
            }
            else if (storeDto.PaymentMethods.IsNullOrEmpty() && currency != null)
            {
                var paymentSearchCriteria = new PaymentMethodsSearchCriteria {
                    StoreId = id
                };
                var paymentsSearchResult = await _paymentModule.SearchPaymentMethodsAsync(paymentSearchCriteria);

                result.PaymentMethods = paymentsSearchResult.Results
                                        .Where(pm => pm.IsActive != null && pm.IsActive.Value)
                                        .Select(pm =>
                {
                    var paymentMethod  = pm.JsonConvert <StorePaymentMethod>().ToStorePaymentMethod(currency);
                    paymentMethod.Name = pm.TypeName;
                    return(paymentMethod);
                }).ToArray();
            }

            if (storeDto.TaxProviders.IsNullOrEmpty())
            {
                var taxSearchCriteria = new TaxProviderSearchCriteria {
                    StoreId = id
                };
                var taxProviderSearchResult = await _taxModule.SearchTaxProvidersAsync(taxSearchCriteria);

                result.FixedTaxRate = GetFixedTaxRate(taxProviderSearchResult.Results.Select(xp => xp.JsonConvert <TaxProvider>()).ToArray());
            }
            else
            {
                result.FixedTaxRate = GetFixedTaxRate(storeDto.TaxProviders);
            }
            //use url for stores from configuration file with hight priority than store url defined in manager
            result.Url = _storefrontOptions.StoreUrls[result.Id] ?? result.Url;

            return(result);
        }
        public async Task <Store> GetStoreByIdAsync(string id, Currency currency)
        {
            var storeDto = await _storeApi.GetStoreByIdAsync(id);

            var result = storeDto.ToStore();

            if (!storeDto.PaymentMethods.IsNullOrEmpty() && currency != null)
            {
                result.PaymentMethods = storeDto.PaymentMethods
                                        .Where(pm => pm.IsActive != null && pm.IsActive.Value)
                                        .Select(pm => pm.ToStorePaymentMethod(currency)).ToArray();
            }
            else if (storeDto.PaymentMethods.IsNullOrEmpty() && currency != null)
            {
                var paymentSearchCriteria = new PaymentMethodsSearchCriteria {
                    StoreId = id
                };
                var paymentsSearchResult = await _paymentModule.SearchPaymentMethodsAsync(paymentSearchCriteria);

                result.PaymentMethods = paymentsSearchResult.Results
                                        .Where(pm => pm.IsActive != null && pm.IsActive.Value)
                                        .Select(pm =>
                {
                    var paymentMethod  = pm.JsonConvert <StorePaymentMethod>().ToStorePaymentMethod(currency);
                    paymentMethod.Name = pm.TypeName;
                    return(paymentMethod);
                }).ToArray();
            }

            if (storeDto.TaxProviders.IsNullOrEmpty())
            {
                var taxSearchCriteria = new TaxProviderSearchCriteria {
                    StoreId = id
                };
                var taxProviderSearchResult = await _taxModule.SearchTaxProvidersAsync(taxSearchCriteria);

                result.FixedTaxRate = GetFixedTaxRate(taxProviderSearchResult.Results.Select(xp => xp.JsonConvert <TaxProvider>()).ToArray());
            }
            else
            {
                result.FixedTaxRate = GetFixedTaxRate(storeDto.TaxProviders);
            }

            return(result);
        }