Exemple #1
0
        /// <summary>
        /// Prepare address model
        /// </summary>
        /// <param name="model">Address model</param>
        /// <param name="address">Address</param>
        protected virtual async Task PrepareAddressModelAsync(AddressModel model, Address address)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            //set some of address fields as enabled and required
            model.CountryEnabled        = true;
            model.StateProvinceEnabled  = true;
            model.CountyEnabled         = true;
            model.CityEnabled           = true;
            model.StreetAddressEnabled  = true;
            model.StreetAddress2Enabled = true;
            model.ZipPostalCodeEnabled  = true;
            model.PhoneEnabled          = true;
            model.FaxEnabled            = true;

            //prepare available countries
            await _baseAdminModelFactory.PrepareCountriesAsync(model.AvailableCountries);

            //prepare available states
            await _baseAdminModelFactory.PrepareStatesAndProvincesAsync(model.AvailableStates, model.CountryId);

            //prepare custom address attributes
            await _addressAttributeModelFactory.PrepareCustomAddressAttributesAsync(model.CustomAddressAttributes, address);
        }
        /// <summary>
        /// Prepare address model
        /// </summary>
        /// <param name="model">Address model</param>
        /// <param name="address">Address</param>
        /// <returns>A task that represents the asynchronous operation</returns>
        public virtual async Task PrepareAddressModelAsync(AddressModel model, Address address = null)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            //prepare available countries
            await _baseAdminModelFactory.PrepareCountriesAsync(model.AvailableCountries);

            //prepare available states
            await _baseAdminModelFactory.PrepareStatesAndProvincesAsync(model.AvailableStates, model.CountryId);

            //prepare custom address attributes
            await _addressAttributeModelFactory.PrepareCustomAddressAttributesAsync(model.CustomAddressAttributes, address);

            if (address == null)
            {
                return;
            }

            model.FormattedCustomAddressAttributes = await _addressAttributeFormatter.FormatAttributesAsync(address.CustomAttributes);
        }
        /// <summary>
        /// Prepare address model
        /// </summary>
        /// <param name="model">Address model</param>
        /// <param name="address">Address</param>
        protected virtual async Task PrepareAddressModelAsync(AddressModel model, Address address = null)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            //set all address fields as enabled and required
            model.FirstNameEnabled      = true;
            model.FirstNameRequired     = true;
            model.LastNameEnabled       = true;
            model.LastNameRequired      = true;
            model.EmailEnabled          = true;
            model.EmailRequired         = true;
            model.CompanyEnabled        = true;
            model.CountryEnabled        = true;
            model.CountryRequired       = true;
            model.StateProvinceEnabled  = true;
            model.CountyEnabled         = true;
            model.CountyRequired        = true;
            model.CityEnabled           = true;
            model.CityRequired          = true;
            model.StreetAddressEnabled  = true;
            model.StreetAddressRequired = true;
            model.StreetAddress2Enabled = true;
            model.ZipPostalCodeEnabled  = true;
            model.ZipPostalCodeRequired = true;
            model.PhoneEnabled          = true;
            model.PhoneRequired         = true;
            model.FaxEnabled            = true;

            //prepare available countries
            await _baseAdminModelFactory.PrepareCountriesAsync(model.AvailableCountries);

            //prepare available states
            await _baseAdminModelFactory.PrepareStatesAndProvincesAsync(model.AvailableStates, model.CountryId);
        }
Exemple #4
0
        public async Task <IActionResult> Configure(string testTaxResult = null)
        {
            if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageTaxSettings))
            {
                return(AccessDeniedView());
            }

            //prepare common properties
            var model = new ConfigurationModel
            {
                AccountId              = _avalaraTaxSettings.AccountId,
                LicenseKey             = _avalaraTaxSettings.LicenseKey,
                CompanyCode            = _avalaraTaxSettings.CompanyCode,
                UseSandbox             = _avalaraTaxSettings.UseSandbox,
                CommitTransactions     = _avalaraTaxSettings.CommitTransactions,
                ValidateAddress        = _avalaraTaxSettings.ValidateAddress,
                TaxOriginAddressTypeId = (int)_avalaraTaxSettings.TaxOriginAddressType,
                EnableLogging          = _avalaraTaxSettings.EnableLogging,
                TestTaxResult          = testTaxResult
            };

            model.IsConfigured          = !string.IsNullOrEmpty(_avalaraTaxSettings.AccountId) && !string.IsNullOrEmpty(_avalaraTaxSettings.LicenseKey);
            model.TaxOriginAddressTypes = (await TaxOriginAddressType.DefaultTaxAddress.ToSelectListAsync(false))
                                          .Select(type => new SelectListItem(type.Text, type.Value)).ToList();
            model.HideGeneralBlock = await _genericAttributeService.GetAttributeAsync <bool>(await _workContext.GetCurrentCustomerAsync(), AvalaraTaxDefaults.HideGeneralBlock);

            model.HideLogBlock = await _genericAttributeService.GetAttributeAsync <bool>(await _workContext.GetCurrentCustomerAsync(), AvalaraTaxDefaults.HideLogBlock);

            //prepare address model
            await _baseAdminModelFactory.PrepareCountriesAsync(model.TestAddress.AvailableCountries);

            await _baseAdminModelFactory.PrepareStatesAndProvincesAsync(model.TestAddress.AvailableStates, model.TestAddress.CountryId);

            //prepare tax transaction log model
            model.TaxTransactionLogSearchModel.SetGridPageSize();

            //get active account companies
            var activeCompanies = model.IsConfigured ? await _avalaraTaxManager.GetAccountCompaniesAsync() : null;

            if (activeCompanies?.Any() ?? false)
            {
                model.Companies = activeCompanies.OrderBy(company => company.isDefault ?? false ? 0 : 1).Select(company => new SelectListItem
                {
                    Text  = company.isTest ?? false ? $"{company.name} (Test)" : company.name,
                    Value = company.companyCode
                }).ToList();
            }

            var defaultCompanyCode = _avalaraTaxSettings.CompanyCode;

            if (!model.Companies.Any())
            {
                //add the special item for 'there are no companies' with empty guid value
                var noCompaniesText = await _localizationService.GetResourceAsync("Plugins.Tax.Avalara.Fields.Company.NotExist");

                model.Companies.Add(new SelectListItem {
                    Text = noCompaniesText, Value = Guid.Empty.ToString()
                });
                defaultCompanyCode = Guid.Empty.ToString();
            }
            else if (string.IsNullOrEmpty(_avalaraTaxSettings.CompanyCode) || _avalaraTaxSettings.CompanyCode.Equals(Guid.Empty.ToString()))
            {
                defaultCompanyCode = model.Companies.FirstOrDefault()?.Value;
            }

            //set the default company
            model.CompanyCode = defaultCompanyCode;
            _avalaraTaxSettings.CompanyCode = defaultCompanyCode;
            await _settingService.SaveSettingAsync(_avalaraTaxSettings);

            //display warning in case of company currency differ from the primary store currency
            var primaryCurrency = await _currencyService.GetCurrencyByIdAsync(_currencySettings.PrimaryStoreCurrencyId);

            var selectedCompany = activeCompanies?.FirstOrDefault(company => company.companyCode.Equals(defaultCompanyCode));

            if (!selectedCompany?.baseCurrencyCode?.Equals(primaryCurrency?.CurrencyCode, StringComparison.InvariantCultureIgnoreCase) ?? false)
            {
                var warning = string.Format(await _localizationService.GetResourceAsync("Plugins.Tax.Avalara.Fields.Company.Currency.Warning"),
                                            selectedCompany.name, selectedCompany.baseCurrencyCode, primaryCurrency?.CurrencyCode);
                _notificationService.WarningNotification(warning);
            }

            return(View("~/Plugins/Tax.Avalara/Views/Configuration/Configure.cshtml", model));
        }