public virtual void AddVendorTokens(IList<Token> tokens, Customer customer) { string accountActivationUrl = string.Format("{0}customer/activation?token={1}&email={2}&v={3}", GetStoreUrl(), customer.GetAttribute<string>(SystemCustomerAttributeNames.AccountActivationToken), HttpUtility.UrlEncode(customer.Email), customer.VendorId.ToString()); tokens.Add(new Token("Vendor.AccountActivationURL", accountActivationUrl, true)); //event notification _eventPublisher.EntityTokensAdded(customer, tokens); }
private string GetSelectedCheckoutAttributesThatHasNotBeenSentToKlarna(Customer customer, int currentStoreId) { string checkoutAttributesXml = null; var originalCheckoutAttributesXml = customer.GetAttribute <string>(SystemCustomerAttributeNames.CheckoutAttributes, currentStoreId); var allCheckoutAttributes = _checkoutAttributeService.GetAllCheckoutAttributes(currentStoreId); foreach (var checkoutAttribute in allCheckoutAttributes.Where(x => !x.ShouldHaveValues())) { var selectedValues = _checkoutAttributeParser.ParseValues(originalCheckoutAttributesXml, checkoutAttribute.Id); foreach (var selectedValue in selectedValues) { checkoutAttributesXml = _checkoutAttributeParser.AddCheckoutAttribute(checkoutAttributesXml, checkoutAttribute, selectedValue); } } return(checkoutAttributesXml); }
protected virtual IList<CustomerAttributeModel> PrepareCustomCustomerAttributes(Customer customer, string overrideAttributesXml = "") { if (customer == null) throw new ArgumentNullException("customer"); var result = new List<CustomerAttributeModel>(); var customerAttributes = _customerAttributeService.GetAllCustomerAttributes(); foreach (var attribute in customerAttributes) { var attributeModel = new CustomerAttributeModel { Id = attribute.Id, Name = attribute.GetLocalized(x => x.Name), IsRequired = attribute.IsRequired, AttributeControlType = attribute.AttributeControlType, }; if (attribute.ShouldHaveValues()) { //values var attributeValues = _customerAttributeService.GetCustomerAttributeValues(attribute.Id); foreach (var attributeValue in attributeValues) { var valueModel = new CustomerAttributeValueModel { Id = attributeValue.Id, Name = attributeValue.GetLocalized(x => x.Name), IsPreSelected = attributeValue.IsPreSelected }; attributeModel.Values.Add(valueModel); } } //set already selected attributes var selectedAttributesXml = !String.IsNullOrEmpty(overrideAttributesXml) ? overrideAttributesXml : customer.GetAttribute<string>(SystemCustomerAttributeNames.CustomCustomerAttributes, _genericAttributeService); switch (attribute.AttributeControlType) { case AttributeControlType.DropdownList: case AttributeControlType.RadioList: case AttributeControlType.Checkboxes: { if (!String.IsNullOrEmpty(selectedAttributesXml)) { //clear default selection foreach (var item in attributeModel.Values) item.IsPreSelected = false; //select new values var selectedValues = _customerAttributeParser.ParseCustomerAttributeValues(selectedAttributesXml); foreach (var attributeValue in selectedValues) foreach (var item in attributeModel.Values) if (attributeValue.Id == item.Id) item.IsPreSelected = true; } } break; case AttributeControlType.ReadonlyCheckboxes: { //do nothing //values are already pre-set } break; case AttributeControlType.TextBox: case AttributeControlType.MultilineTextbox: { if (!String.IsNullOrEmpty(selectedAttributesXml)) { var enteredText = _customerAttributeParser.ParseValues(selectedAttributesXml, attribute.Id); if (enteredText.Count > 0) attributeModel.DefaultValue = enteredText[0]; } } break; case AttributeControlType.ColorSquares: case AttributeControlType.ImageSquares: case AttributeControlType.Datepicker: case AttributeControlType.FileUpload: default: //not supported attribute control types break; } result.Add(attributeModel); } return result; }
/// <summary> /// Check discount requirements /// </summary> /// <param name="discount">Discount</param> /// <param name="customer">Customer</param> /// <returns>true - requirement is met; otherwise, false</returns> public virtual bool IsDiscountValid(Discount discount, Customer customer) { if (discount == null) throw new ArgumentNullException("discount"); var couponCodeToValidate = ""; if (customer != null) couponCodeToValidate = customer.GetAttribute<string>(SystemCustomerAttributeNames.DiscountCouponCode, _genericAttributeService); return IsDiscountValid(discount, customer, couponCodeToValidate); }
protected virtual void PrepareCustomerModel(CustomerModel model, Customer customer, bool excludeProperties) { if (customer != null) { model.Id = customer.Id; if (!excludeProperties) { model.Email = customer.Email; model.Username = customer.Username; model.VendorId = customer.VendorId; model.AdminComment = customer.AdminComment; model.IsTaxExempt = customer.IsTaxExempt; model.Active = customer.Active; model.AffiliateId = customer.AffiliateId; model.TimeZoneId = customer.GetAttribute<string>(SystemCustomerAttributeNames.TimeZoneId); model.VatNumber = customer.GetAttribute<string>(SystemCustomerAttributeNames.VatNumber); model.VatNumberStatusNote = ((VatNumberStatus)customer.GetAttribute<int>(SystemCustomerAttributeNames.VatNumberStatusId)) .GetLocalizedEnum(_localizationService, _workContext); model.CreatedOn = _dateTimeHelper.ConvertToUserTime(customer.CreatedOnUtc, DateTimeKind.Utc); model.LastActivityDate = _dateTimeHelper.ConvertToUserTime(customer.LastActivityDateUtc, DateTimeKind.Utc); model.LastIpAddress = customer.LastIpAddress; model.LastVisitedPage = customer.GetAttribute<string>(SystemCustomerAttributeNames.LastVisitedPage); model.SelectedCustomerRoleIds = customer.CustomerRoles.Select(cr => cr.Id).ToArray(); //form fields model.FirstName = customer.GetAttribute<string>(SystemCustomerAttributeNames.FirstName); model.LastName = customer.GetAttribute<string>(SystemCustomerAttributeNames.LastName); model.Gender = customer.GetAttribute<string>(SystemCustomerAttributeNames.Gender); model.DateOfBirth = customer.GetAttribute<DateTime?>(SystemCustomerAttributeNames.DateOfBirth); model.Company = customer.GetAttribute<string>(SystemCustomerAttributeNames.Company); model.StreetAddress = customer.GetAttribute<string>(SystemCustomerAttributeNames.StreetAddress); model.StreetAddress2 = customer.GetAttribute<string>(SystemCustomerAttributeNames.StreetAddress2); model.ZipPostalCode = customer.GetAttribute<string>(SystemCustomerAttributeNames.ZipPostalCode); model.City = customer.GetAttribute<string>(SystemCustomerAttributeNames.City); model.CountryId = customer.GetAttribute<int>(SystemCustomerAttributeNames.CountryId); model.StateProvinceId = customer.GetAttribute<int>(SystemCustomerAttributeNames.StateProvinceId); model.Phone = customer.GetAttribute<string>(SystemCustomerAttributeNames.Phone); model.Fax = customer.GetAttribute<string>(SystemCustomerAttributeNames.Fax); } } model.UsernamesEnabled = _customerSettings.UsernamesEnabled; model.AllowUsersToChangeUsernames = _customerSettings.AllowUsersToChangeUsernames; model.AllowCustomersToSetTimeZone = _dateTimeSettings.AllowCustomersToSetTimeZone; foreach (var tzi in _dateTimeHelper.GetSystemTimeZones()) model.AvailableTimeZones.Add(new SelectListItem { Text = tzi.DisplayName, Value = tzi.Id, Selected = (tzi.Id == model.TimeZoneId) }); if (customer != null) { model.DisplayVatNumber = _taxSettings.EuVatEnabled; } else { model.DisplayVatNumber = false; } //vendors PrepareVendorsModel(model); //customer attributes PrepareCustomerAttributeModel(model, customer); model.GenderEnabled = _customerSettings.GenderEnabled; model.DateOfBirthEnabled = _customerSettings.DateOfBirthEnabled; model.CompanyEnabled = _customerSettings.CompanyEnabled; model.StreetAddressEnabled = _customerSettings.StreetAddressEnabled; model.StreetAddress2Enabled = _customerSettings.StreetAddress2Enabled; model.ZipPostalCodeEnabled = _customerSettings.ZipPostalCodeEnabled; model.CityEnabled = _customerSettings.CityEnabled; model.CountryEnabled = _customerSettings.CountryEnabled; model.StateProvinceEnabled = _customerSettings.StateProvinceEnabled; model.PhoneEnabled = _customerSettings.PhoneEnabled; model.FaxEnabled = _customerSettings.FaxEnabled; //countries and states if (_customerSettings.CountryEnabled) { model.AvailableCountries.Add(new SelectListItem { Text = _localizationService.GetResource("Admin.Address.SelectCountry"), Value = "0" }); foreach (var c in _countryService.GetAllCountries(true)) { model.AvailableCountries.Add(new SelectListItem { Text = c.Name, Value = c.Id.ToString(), Selected = c.Id == model.CountryId }); } if (_customerSettings.StateProvinceEnabled) { //states var states = _stateProvinceService.GetStateProvincesByCountryId(model.CountryId).ToList(); if (states.Count > 0) { model.AvailableStates.Add(new SelectListItem { Text = _localizationService.GetResource("Admin.Address.SelectState"), Value = "0" }); foreach (var s in states) { model.AvailableStates.Add(new SelectListItem { Text = s.Name, Value = s.Id.ToString(), Selected = (s.Id == model.StateProvinceId) }); } } else { bool anyCountrySelected = model.AvailableCountries.Any(x => x.Selected); model.AvailableStates.Add(new SelectListItem { Text = _localizationService.GetResource(anyCountrySelected ? "Admin.Address.OtherNonUS" : "Admin.Address.SelectState"), Value = "0" }); } } } //customer roles model.AvailableCustomerRoles = _customerService .GetAllCustomerRoles(true) .Select(cr => cr.ToModel()) .ToList(); //reward points history if (customer != null) { model.DisplayRewardPointsHistory = _rewardPointsSettings.Enabled; } else { model.DisplayRewardPointsHistory = false; } model.AddRewardPointsValue = 0; model.AddRewardPointsMessage = "Some comment here..."; //external authentication records if (customer != null) { model.AssociatedExternalAuthRecords = GetAssociatedExternalAuthRecords(customer); } }
protected virtual void PrepareCustomerAttributeModel(CustomerModel model, Customer customer) { var customerAttributes = _customerAttributeService.GetAllCustomerAttributes(); foreach (var attribute in customerAttributes) { var attributeModel = new CustomerModel.CustomerAttributeModel { Id = attribute.Id, Name = attribute.Name, IsRequired = attribute.IsRequired, AttributeControlType = attribute.AttributeControlType, }; if (attribute.ShouldHaveValues()) { //values var attributeValues = _customerAttributeService.GetCustomerAttributeValues(attribute.Id); foreach (var attributeValue in attributeValues) { var attributeValueModel = new CustomerModel.CustomerAttributeValueModel { Id = attributeValue.Id, Name = attributeValue.Name, IsPreSelected = attributeValue.IsPreSelected }; attributeModel.Values.Add(attributeValueModel); } } //set already selected attributes if (customer != null) { var selectedCustomerAttributes = customer.GetAttribute<string>(SystemCustomerAttributeNames.CustomCustomerAttributes, _genericAttributeService); switch (attribute.AttributeControlType) { case AttributeControlType.DropdownList: case AttributeControlType.RadioList: case AttributeControlType.Checkboxes: { if (!String.IsNullOrEmpty(selectedCustomerAttributes)) { //clear default selection foreach (var item in attributeModel.Values) item.IsPreSelected = false; //select new values var selectedValues = _customerAttributeParser.ParseCustomerAttributeValues(selectedCustomerAttributes); foreach (var attributeValue in selectedValues) foreach (var item in attributeModel.Values) if (attributeValue.Id == item.Id) item.IsPreSelected = true; } } break; case AttributeControlType.ReadonlyCheckboxes: { //do nothing //values are already pre-set } break; case AttributeControlType.TextBox: case AttributeControlType.MultilineTextbox: { if (!String.IsNullOrEmpty(selectedCustomerAttributes)) { var enteredText = _customerAttributeParser.ParseValues(selectedCustomerAttributes, attribute.Id); if (enteredText.Count > 0) attributeModel.DefaultValue = enteredText[0]; } } break; case AttributeControlType.ColorSquares: case AttributeControlType.Datepicker: case AttributeControlType.FileUpload: default: //not supported attribute control types break; } } model.CustomerAttributes.Add(attributeModel); } }
protected virtual CustomerModel PrepareCustomerModelForList(Customer customer) { return new CustomerModel { Id = customer.Id, Email = customer.IsRegistered() ? customer.Email : _localizationService.GetResource("Admin.Customers.Guest"), Username = customer.Username, FullName = customer.GetFullName(), Company = customer.GetAttribute<string>(SystemCustomerAttributeNames.Company), Phone = customer.GetAttribute<string>(SystemCustomerAttributeNames.Phone), ZipPostalCode = customer.GetAttribute<string>(SystemCustomerAttributeNames.ZipPostalCode), CustomerRoleNames = GetCustomerRolesNames(customer.CustomerRoles.ToList()), Active = customer.Active, CreatedOn = _dateTimeHelper.ConvertToUserTime(customer.CreatedOnUtc, DateTimeKind.Utc), LastActivityDate = _dateTimeHelper.ConvertToUserTime(customer.LastActivityDateUtc, DateTimeKind.Utc), }; }
private static void AddAttribute(MergeVar myMergeVars, Customer customer, string attribute, string mailchimpField) { var value = customer.GetAttribute<string>(attribute); myMergeVars.Add(mailchimpField, value); }
/// <summary> /// Gets a value indicating whether EU VAT exempt (the European Union Value Added Tax) /// </summary> /// <param name="address">Address</param> /// <param name="customer">Customer</param> /// <returns>Result</returns> public virtual bool IsVatExempt(Address address, Customer customer) { if (!_taxSettings.EuVatEnabled) return false; if (address == null || address.Country == null || customer == null) return false; if (!address.Country.SubjectToVat) // VAT not chargeable if shipping outside VAT zone return true; // VAT not chargeable if address, customer and config meet our VAT exemption requirements: // returns true if this customer is VAT exempt because they are shipping within the EU but outside our shop country, they have supplied a validated VAT number, and the shop is configured to allow VAT exemption var customerVatStatus = (VatNumberStatus) customer.GetAttribute<int>(SystemCustomerAttributeNames.VatNumberStatusId); return address.CountryId != _taxSettings.EuVatShopCountryId && customerVatStatus == VatNumberStatus.Valid && _taxSettings.EuVatAllowVatExemption; }
protected virtual void PrepareCustomerModel(CustomerModel model, Customer customer, bool excludeProperties) { var allStores = _storeService.GetAllStores(); if (customer != null) { model.Id = customer.Id; if (!excludeProperties) { model.Email = customer.Email; model.Username = customer.Username; model.VendorId = customer.VendorId; model.AdminComment = customer.AdminComment; model.IsTaxExempt = customer.IsTaxExempt; model.Active = customer.Active; var affiliate = _affiliateService.GetAffiliateById(customer.AffiliateId); if (affiliate != null) { model.AffiliateId = affiliate.Id; model.AffiliateName = affiliate.GetFullName(); } model.TimeZoneId = customer.GetAttribute<string>(SystemCustomerAttributeNames.TimeZoneId); model.VatNumber = customer.GetAttribute<string>(SystemCustomerAttributeNames.VatNumber); model.VatNumberStatusNote = ((VatNumberStatus)customer.GetAttribute<int>(SystemCustomerAttributeNames.VatNumberStatusId)) .GetLocalizedEnum(_localizationService, _workContext); model.CreatedOn = _dateTimeHelper.ConvertToUserTime(customer.CreatedOnUtc, DateTimeKind.Utc); model.LastActivityDate = _dateTimeHelper.ConvertToUserTime(customer.LastActivityDateUtc, DateTimeKind.Utc); model.LastIpAddress = customer.LastIpAddress; model.LastVisitedPage = customer.GetAttribute<string>(SystemCustomerAttributeNames.LastVisitedPage); model.SelectedCustomerRoleIds = customer.CustomerRoles.Select(cr => cr.Id).ToList(); //newsletter subscriptions if (!String.IsNullOrEmpty(customer.Email)) { var newsletterSubscriptionStoreIds = new List<int>(); foreach (var store in allStores) { var newsletterSubscription = _newsLetterSubscriptionService .GetNewsLetterSubscriptionByEmailAndStoreId(customer.Email, store.Id); if (newsletterSubscription != null) newsletterSubscriptionStoreIds.Add(store.Id); model.SelectedNewsletterSubscriptionStoreIds = newsletterSubscriptionStoreIds.ToArray(); } } //form fields model.FirstName = customer.GetAttribute<string>(SystemCustomerAttributeNames.FirstName); model.LastName = customer.GetAttribute<string>(SystemCustomerAttributeNames.LastName); model.Gender = customer.GetAttribute<string>(SystemCustomerAttributeNames.Gender); model.DateOfBirth = customer.GetAttribute<DateTime?>(SystemCustomerAttributeNames.DateOfBirth); model.Company = customer.GetAttribute<string>(SystemCustomerAttributeNames.Company); model.StreetAddress = customer.GetAttribute<string>(SystemCustomerAttributeNames.StreetAddress); model.StreetAddress2 = customer.GetAttribute<string>(SystemCustomerAttributeNames.StreetAddress2); model.ZipPostalCode = customer.GetAttribute<string>(SystemCustomerAttributeNames.ZipPostalCode); model.City = customer.GetAttribute<string>(SystemCustomerAttributeNames.City); model.CountryId = customer.GetAttribute<int>(SystemCustomerAttributeNames.CountryId); model.StateProvinceId = customer.GetAttribute<int>(SystemCustomerAttributeNames.StateProvinceId); model.Phone = customer.GetAttribute<string>(SystemCustomerAttributeNames.Phone); model.Fax = customer.GetAttribute<string>(SystemCustomerAttributeNames.Fax); } } model.UsernamesEnabled = _customerSettings.UsernamesEnabled; model.AllowUsersToChangeUsernames = _customerSettings.AllowUsersToChangeUsernames; model.AllowCustomersToSetTimeZone = _dateTimeSettings.AllowCustomersToSetTimeZone; foreach (var tzi in _dateTimeHelper.GetSystemTimeZones()) model.AvailableTimeZones.Add(new SelectListItem { Text = tzi.DisplayName, Value = tzi.Id, Selected = (tzi.Id == model.TimeZoneId) }); if (customer != null) { model.DisplayVatNumber = _taxSettings.EuVatEnabled; } else { model.DisplayVatNumber = false; } //vendors PrepareVendorsModel(model); //customer attributes PrepareCustomerAttributeModel(model, customer); model.GenderEnabled = _customerSettings.GenderEnabled; model.DateOfBirthEnabled = _customerSettings.DateOfBirthEnabled; model.CompanyEnabled = _customerSettings.CompanyEnabled; model.StreetAddressEnabled = _customerSettings.StreetAddressEnabled; model.StreetAddress2Enabled = _customerSettings.StreetAddress2Enabled; model.ZipPostalCodeEnabled = _customerSettings.ZipPostalCodeEnabled; model.CityEnabled = _customerSettings.CityEnabled; model.CountryEnabled = _customerSettings.CountryEnabled; model.StateProvinceEnabled = _customerSettings.StateProvinceEnabled; model.PhoneEnabled = _customerSettings.PhoneEnabled; model.FaxEnabled = _customerSettings.FaxEnabled; //countries and states if (_customerSettings.CountryEnabled) { model.AvailableCountries.Add(new SelectListItem { Text = _localizationService.GetResource("Admin.Address.SelectCountry"), Value = "0" }); foreach (var c in _countryService.GetAllCountries(showHidden: true)) { model.AvailableCountries.Add(new SelectListItem { Text = c.Name, Value = c.Id.ToString(), Selected = c.Id == model.CountryId }); } if (_customerSettings.StateProvinceEnabled) { //states var states = _stateProvinceService.GetStateProvincesByCountryId(model.CountryId).ToList(); if (states.Any()) { model.AvailableStates.Add(new SelectListItem { Text = _localizationService.GetResource("Admin.Address.SelectState"), Value = "0" }); foreach (var s in states) { model.AvailableStates.Add(new SelectListItem { Text = s.Name, Value = s.Id.ToString(), Selected = (s.Id == model.StateProvinceId) }); } } else { bool anyCountrySelected = model.AvailableCountries.Any(x => x.Selected); model.AvailableStates.Add(new SelectListItem { Text = _localizationService.GetResource(anyCountrySelected ? "Admin.Address.OtherNonUS" : "Admin.Address.SelectState"), Value = "0" }); } } } //newsletter subscriptions model.AvailableNewsletterSubscriptionStores = allStores .Select(s => new CustomerModel.StoreModel() {Id = s.Id, Name = s.Name }) .ToList(); //customer roles var allRoles = _customerService.GetAllCustomerRoles(true); var adminRole = allRoles.FirstOrDefault(c => c.SystemName == SystemCustomerRoleNames.Registered); //precheck Registered Role as a default role while creating a new customer through admin if (customer == null && adminRole != null) { model.SelectedCustomerRoleIds.Add(adminRole.Id); } foreach (var role in allRoles) { model.AvailableCustomerRoles.Add(new SelectListItem { Text = role.Name, Value = role.Id.ToString(), Selected = model.SelectedCustomerRoleIds.Contains(role.Id) }); } //reward points history if (customer != null) { model.DisplayRewardPointsHistory = _rewardPointsSettings.Enabled; model.AddRewardPointsValue = 0; model.AddRewardPointsMessage = "Some comment here..."; //stores foreach (var store in allStores) { model.RewardPointsAvailableStores.Add(new SelectListItem { Text = store.Name, Value = store.Id.ToString(), Selected = (store.Id == _storeContext.CurrentStore.Id) }); } } else { model.DisplayRewardPointsHistory = false; } //external authentication records if (customer != null) { model.AssociatedExternalAuthRecords = GetAssociatedExternalAuthRecords(customer); } //sending of the welcome message: //1. "admin approval" registration method //2. already created customer //3. registered model.AllowSendingOfWelcomeMessage = _customerSettings.UserRegistrationType == UserRegistrationType.AdminApproval && customer != null && customer.IsRegistered(); //sending of the activation message //1. "email validation" registration method //2. already created customer //3. registered //4. not active model.AllowReSendingOfActivationMessage = _customerSettings.UserRegistrationType == UserRegistrationType.EmailValidation && customer != null && customer.IsRegistered() && !customer.Active; }
//address /// <summary> /// Prepare address model /// </summary> /// <param name="model">Model</param> /// <param name="address">Address</param> /// <param name="excludeProperties">A value indicating whether to exclude properties</param> /// <param name="addressSettings">Address settings</param> /// <param name="localizationService">Localization service (used to prepare a select list)</param> /// <param name="stateProvinceService">State service (used to prepare a select list). null to don't prepare the list.</param> /// <param name="addressAttributeService">Address attribute service. null to don't prepare the list.</param> /// <param name="addressAttributeParser">Address attribute parser. null to don't prepare the list.</param> /// <param name="addressAttributeFormatter">Address attribute formatter. null to don't prepare the formatted custom attributes.</param> /// <param name="loadCountries">A function to load countries (used to prepare a select list). null to don't prepare the list.</param> /// <param name="prePopulateWithCustomerFields">A value indicating whether to pre-populate an address with customer fields entered during registration. It's used only when "address" parameter is set to "null"</param> /// <param name="customer">Customer record which will be used to pre-populate address. Used only when "prePopulateWithCustomerFields" is "true".</param> /// <param name="overrideAttributesXml">When specified we do not use attributes of an address; if null, then already saved ones are used</param> public static void PrepareModel(this AddressModel model, Address address, bool excludeProperties, AddressSettings addressSettings, ILocalizationService localizationService = null, IStateProvinceService stateProvinceService = null, IAddressAttributeService addressAttributeService = null, IAddressAttributeParser addressAttributeParser = null, IAddressAttributeFormatter addressAttributeFormatter = null, Func<IList<Country>> loadCountries = null, bool prePopulateWithCustomerFields = false, Customer customer = null, string overrideAttributesXml = "") { if (model == null) throw new ArgumentNullException("model"); if (addressSettings == null) throw new ArgumentNullException("addressSettings"); if (!excludeProperties && address != null) { model.Id = address.Id; model.FirstName = address.FirstName; model.LastName = address.LastName; model.Email = address.Email; model.Company = address.Company; model.CountryId = address.CountryId; model.CountryName = address.Country != null ? address.Country.GetLocalized(x => x.Name) : null; model.StateProvinceId = address.StateProvinceId; model.StateProvinceName = address.StateProvince != null ? address.StateProvince.GetLocalized(x => x.Name) : null; model.City = address.City; model.Address1 = address.Address1; model.Address2 = address.Address2; model.ZipPostalCode = address.ZipPostalCode; model.PhoneNumber = address.PhoneNumber; model.FaxNumber = address.FaxNumber; } if (address == null && prePopulateWithCustomerFields) { if (customer == null) throw new Exception("Customer cannot be null when prepopulating an address"); model.Email = customer.Email; model.FirstName = customer.GetAttribute<string>(SystemCustomerAttributeNames.FirstName); model.LastName = customer.GetAttribute<string>(SystemCustomerAttributeNames.LastName); model.Company = customer.GetAttribute<string>(SystemCustomerAttributeNames.Company); model.Address1 = customer.GetAttribute<string>(SystemCustomerAttributeNames.StreetAddress); model.Address2 = customer.GetAttribute<string>(SystemCustomerAttributeNames.StreetAddress2); model.ZipPostalCode = customer.GetAttribute<string>(SystemCustomerAttributeNames.ZipPostalCode); model.City = customer.GetAttribute<string>(SystemCustomerAttributeNames.City); //ignore country and state for prepopulation. it can cause some issues when posting pack with errors, etc //model.CountryId = customer.GetAttribute<int>(SystemCustomerAttributeNames.CountryId); //model.StateProvinceId = customer.GetAttribute<int>(SystemCustomerAttributeNames.StateProvinceId); model.PhoneNumber = customer.GetAttribute<string>(SystemCustomerAttributeNames.Phone); model.FaxNumber = customer.GetAttribute<string>(SystemCustomerAttributeNames.Fax); } //countries and states if (addressSettings.CountryEnabled && loadCountries != null) { if (localizationService == null) throw new ArgumentNullException("localizationService"); model.AvailableCountries.Add(new SelectListItem { Text = localizationService.GetResource("Address.SelectCountry"), Value = "0" }); foreach (var c in loadCountries()) { model.AvailableCountries.Add(new SelectListItem { Text = c.GetLocalized(x => x.Name), Value = c.Id.ToString(), Selected = c.Id == model.CountryId }); } if (addressSettings.StateProvinceEnabled) { //states if (stateProvinceService == null) throw new ArgumentNullException("stateProvinceService"); var languageId = EngineContext.Current.Resolve<IWorkContext>().WorkingLanguage.Id; var states = stateProvinceService .GetStateProvincesByCountryId(model.CountryId.HasValue ? model.CountryId.Value : 0, languageId) .ToList(); if (states.Count > 0) { model.AvailableStates.Add(new SelectListItem { Text = localizationService.GetResource("Address.SelectState"), Value = "0" }); foreach (var s in states) { model.AvailableStates.Add(new SelectListItem { Text = s.GetLocalized(x => x.Name), Value = s.Id.ToString(), Selected = (s.Id == model.StateProvinceId) }); } } else { bool anyCountrySelected = model.AvailableCountries.Any(x => x.Selected); model.AvailableStates.Add(new SelectListItem { Text = localizationService.GetResource(anyCountrySelected ? "Address.OtherNonUS" : "Address.SelectState"), Value = "0" }); } } } //form fields model.CompanyEnabled = addressSettings.CompanyEnabled; model.CompanyRequired = addressSettings.CompanyRequired; model.StreetAddressEnabled = addressSettings.StreetAddressEnabled; model.StreetAddressRequired = addressSettings.StreetAddressRequired; model.StreetAddress2Enabled = addressSettings.StreetAddress2Enabled; model.StreetAddress2Required = addressSettings.StreetAddress2Required; model.ZipPostalCodeEnabled = addressSettings.ZipPostalCodeEnabled; model.ZipPostalCodeRequired = addressSettings.ZipPostalCodeRequired; model.CityEnabled = addressSettings.CityEnabled; model.CityRequired = addressSettings.CityRequired; model.CountryEnabled = addressSettings.CountryEnabled; model.StateProvinceEnabled = addressSettings.StateProvinceEnabled; model.PhoneEnabled = addressSettings.PhoneEnabled; model.PhoneRequired = addressSettings.PhoneRequired; model.FaxEnabled = addressSettings.FaxEnabled; model.FaxRequired = addressSettings.FaxRequired; //customer attribute services if (addressAttributeService != null && addressAttributeParser != null) { PrepareCustomAddressAttributes(model, address, addressAttributeService, addressAttributeParser, overrideAttributesXml); } if (addressAttributeFormatter != null && address != null) { model.FormattedCustomAddressAttributes = addressAttributeFormatter.FormatAttributes(address.CustomAttributes); } }
protected virtual void PrepareCustomerInfoModel(CustomerInfoModel model, Customer customer, bool excludeProperties) { if (model == null) throw new ArgumentNullException("model"); if (customer == null) throw new ArgumentNullException("customer"); model.AllowCustomersToSetTimeZone = _dateTimeSettings.AllowCustomersToSetTimeZone; foreach (var tzi in _dateTimeHelper.GetSystemTimeZones()) model.AvailableTimeZones.Add(new SelectListItem() { Text = tzi.DisplayName, Value = tzi.Id, Selected = (excludeProperties ? tzi.Id == model.TimeZoneId : tzi.Id == _dateTimeHelper.CurrentTimeZone.Id) }); if (!excludeProperties) { model.VatNumber = customer.GetAttribute<string>(SystemCustomerAttributeNames.VatNumber); model.FirstName = customer.GetAttribute<string>(SystemCustomerAttributeNames.FirstName); model.LastName = customer.GetAttribute<string>(SystemCustomerAttributeNames.LastName); model.Gender = customer.GetAttribute<string>(SystemCustomerAttributeNames.Gender); var dateOfBirth = customer.GetAttribute<DateTime?>(SystemCustomerAttributeNames.DateOfBirth); if (dateOfBirth.HasValue) { model.DateOfBirthDay = dateOfBirth.Value.Day; model.DateOfBirthMonth = dateOfBirth.Value.Month; model.DateOfBirthYear = dateOfBirth.Value.Year; } model.Company = customer.GetAttribute<string>(SystemCustomerAttributeNames.Company); model.StreetAddress = customer.GetAttribute<string>(SystemCustomerAttributeNames.StreetAddress); model.StreetAddress2 = customer.GetAttribute<string>(SystemCustomerAttributeNames.StreetAddress2); model.ZipPostalCode = customer.GetAttribute<string>(SystemCustomerAttributeNames.ZipPostalCode); model.City = customer.GetAttribute<string>(SystemCustomerAttributeNames.City); model.CountryId = customer.GetAttribute<int>(SystemCustomerAttributeNames.CountryId); model.StateProvinceId = customer.GetAttribute<int>(SystemCustomerAttributeNames.StateProvinceId); model.Phone = customer.GetAttribute<string>(SystemCustomerAttributeNames.Phone); model.Fax = customer.GetAttribute<string>(SystemCustomerAttributeNames.Fax); //newsletter var newsletter = _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmailAndStoreId(customer.Email, _storeContext.CurrentStore.Id); model.Newsletter = newsletter != null && newsletter.Active; model.Signature = customer.GetAttribute<string>(SystemCustomerAttributeNames.Signature); model.Email = customer.Email; model.Username = customer.Username; } else { if (_customerSettings.UsernamesEnabled && !_customerSettings.AllowUsersToChangeUsernames) model.Username = customer.Username; } //countries and states if (_customerSettings.CountryEnabled) { model.AvailableCountries.Add(new SelectListItem() { Text = _localizationService.GetResource("Address.SelectCountry"), Value = "0" }); foreach (var c in _countryService.GetAllCountries()) { model.AvailableCountries.Add(new SelectListItem() { Text = c.GetLocalized(x => x.Name), Value = c.Id.ToString(), Selected = c.Id == model.CountryId }); } if (_customerSettings.StateProvinceEnabled) { //states var states = _stateProvinceService.GetStateProvincesByCountryId(model.CountryId).ToList(); if (states.Count > 0) { foreach (var s in states) model.AvailableStates.Add(new SelectListItem() { Text = s.GetLocalized(x => x.Name), Value = s.Id.ToString(), Selected = (s.Id == model.StateProvinceId) }); } else model.AvailableStates.Add(new SelectListItem() { Text = _localizationService.GetResource("Address.OtherNonUS"), Value = "0" }); } } model.DisplayVatNumber = _taxSettings.EuVatEnabled; model.VatNumberStatusNote = ((VatNumberStatus)customer.GetAttribute<int>(SystemCustomerAttributeNames.VatNumberStatusId)) .GetLocalizedEnum(_localizationService, _workContext); model.GenderEnabled = _customerSettings.GenderEnabled; model.DateOfBirthEnabled = _customerSettings.DateOfBirthEnabled; model.CompanyEnabled = _customerSettings.CompanyEnabled; model.CompanyRequired = _customerSettings.CompanyRequired; model.StreetAddressEnabled = _customerSettings.StreetAddressEnabled; model.StreetAddressRequired = _customerSettings.StreetAddressRequired; model.StreetAddress2Enabled = _customerSettings.StreetAddress2Enabled; model.StreetAddress2Required = _customerSettings.StreetAddress2Required; model.ZipPostalCodeEnabled = _customerSettings.ZipPostalCodeEnabled; model.ZipPostalCodeRequired = _customerSettings.ZipPostalCodeRequired; model.CityEnabled = _customerSettings.CityEnabled; model.CityRequired = _customerSettings.CityRequired; model.CountryEnabled = _customerSettings.CountryEnabled; model.StateProvinceEnabled = _customerSettings.StateProvinceEnabled; model.PhoneEnabled = _customerSettings.PhoneEnabled; model.PhoneRequired = _customerSettings.PhoneRequired; model.FaxEnabled = _customerSettings.FaxEnabled; model.FaxRequired = _customerSettings.FaxRequired; model.NewsletterEnabled = _customerSettings.NewsletterEnabled; model.UsernamesEnabled = _customerSettings.UsernamesEnabled; model.AllowUsersToChangeUsernames = _customerSettings.AllowUsersToChangeUsernames; model.CheckUsernameAvailabilityEnabled = _customerSettings.CheckUsernameAvailabilityEnabled; model.SignatureEnabled = _forumSettings.ForumsEnabled && _forumSettings.SignaturesEnabled; //external authentication model.NumberOfExternalAuthenticationProviders = _openAuthenticationService .LoadActiveExternalAuthenticationMethods(_storeContext.CurrentStore.Id) .Count; foreach (var ear in _openAuthenticationService.GetExternalIdentifiersFor(customer)) { var authMethod = _openAuthenticationService.LoadExternalAuthenticationMethodBySystemName(ear.ProviderSystemName); if (authMethod == null || !authMethod.IsMethodActive(_externalAuthenticationSettings)) continue; model.AssociatedExternalAuthRecords.Add(new CustomerInfoModel.AssociatedExternalAuthModel() { Id = ear.Id, Email = ear.Email, ExternalIdentifier = ear.ExternalIdentifier, AuthMethodName = authMethod.GetLocalizedFriendlyName(_localizationService, _workContext.WorkingLanguage.Id) }); } #region Custom customer attributes var customerAttributes = _customerAttributeService.GetAllCustomerAttributes(); foreach (var attribute in customerAttributes) { var caModel = new CustomerAttributeModel() { Id = attribute.Id, Name = attribute.GetLocalized(x => x.Name), IsRequired = attribute.IsRequired, AttributeControlType = attribute.AttributeControlType, }; if (attribute.ShouldHaveValues()) { //values var caValues = _customerAttributeService.GetCustomerAttributeValues(attribute.Id); foreach (var caValue in caValues) { var caValueModel = new CustomerAttributeValueModel() { Id = caValue.Id, Name = caValue.GetLocalized(x => x.Name), IsPreSelected = caValue.IsPreSelected }; caModel.Values.Add(caValueModel); } } //set already selected attributes string selectedCustomerAttributes = customer.GetAttribute<string>(SystemCustomerAttributeNames.CustomCustomerAttributes, _genericAttributeService); switch (attribute.AttributeControlType) { case AttributeControlType.DropdownList: case AttributeControlType.RadioList: case AttributeControlType.Checkboxes: { if (!String.IsNullOrEmpty(selectedCustomerAttributes)) { //clear default selection foreach (var item in caModel.Values) item.IsPreSelected = false; //select new values var selectedCaValues = _customerAttributeParser.ParseCustomerAttributeValues(selectedCustomerAttributes); foreach (var caValue in selectedCaValues) foreach (var item in caModel.Values) if (caValue.Id == item.Id) item.IsPreSelected = true; } } break; case AttributeControlType.ReadonlyCheckboxes: { //do nothing //values are already pre-set } break; case AttributeControlType.TextBox: case AttributeControlType.MultilineTextbox: { if (!String.IsNullOrEmpty(selectedCustomerAttributes)) { var enteredText = _customerAttributeParser.ParseValues(selectedCustomerAttributes, attribute.Id); if (enteredText.Count > 0) caModel.DefaultValue = enteredText[0]; } } break; case AttributeControlType.ColorSquares: case AttributeControlType.Datepicker: case AttributeControlType.FileUpload: default: //not supported attribute control types break; } model.CustomerAttributes.Add(caModel); } #endregion model.NavigationModel = GetCustomerNavigationModel(customer); model.NavigationModel.SelectedTab = CustomerNavigationEnum.Info; }
public virtual void AddCustomerTokens(IList<Token> tokens, Customer customer) { tokens.Add(new Token("Customer.Email", customer.Email)); tokens.Add(new Token("Customer.Username", customer.Username)); tokens.Add(new Token("Customer.FullName", customer.GetFullName())); tokens.Add(new Token("Customer.VatNumber", customer.VatNumber)); tokens.Add(new Token("Customer.VatNumberStatus", customer.VatNumberStatus.ToString())); //TODO add a method for getting URL (use routing because it handles all SEO friendly URLs) string passwordRecoveryUrl = string.Format("{0}passwordrecovery/confirm?token={1}&email={2}", _webHelper.GetStoreLocation(false), customer.GetAttribute<string>(SystemCustomerAttributeNames.PasswordRecoveryToken), customer.Email); string accountActivationUrl = string.Format("{0}customer/activation?token={1}&email={2}", _webHelper.GetStoreLocation(false), customer.GetAttribute<string>(SystemCustomerAttributeNames.AccountActivationToken), customer.Email); var wishlistUrl = string.Format("{0}wishlist/{1}", _webHelper.GetStoreLocation(false), customer.CustomerGuid); tokens.Add(new Token("Customer.PasswordRecoveryURL", passwordRecoveryUrl, true)); tokens.Add(new Token("Customer.AccountActivationURL", accountActivationUrl, true)); tokens.Add(new Token("Wishlist.URLForCustomer", wishlistUrl, true)); }
protected virtual void PrepareCustomerInfoModel(CustomerInfoModel model, Customer customer, bool excludeProperties, string overrideCustomCustomerAttributesXml = "") { if (model == null) throw new ArgumentNullException("model"); if (customer == null) throw new ArgumentNullException("customer"); model.AllowCustomersToSetTimeZone = _dateTimeSettings.AllowCustomersToSetTimeZone; foreach (var tzi in _dateTimeHelper.GetSystemTimeZones()) model.AvailableTimeZones.Add(new SelectListItem { Text = tzi.DisplayName, Value = tzi.Id, Selected = (excludeProperties ? tzi.Id == model.TimeZoneId : tzi.Id == _dateTimeHelper.CurrentTimeZone.Id) }); if (!excludeProperties) { model.VatNumber = customer.GetAttribute<string>(SystemCustomerAttributeNames.VatNumber); model.FirstName = customer.GetAttribute<string>(SystemCustomerAttributeNames.FirstName); model.LastName = customer.GetAttribute<string>(SystemCustomerAttributeNames.LastName); model.Gender = customer.GetAttribute<string>(SystemCustomerAttributeNames.Gender); var dateOfBirth = customer.GetAttribute<DateTime?>(SystemCustomerAttributeNames.DateOfBirth); if (dateOfBirth.HasValue) { model.DateOfBirthDay = dateOfBirth.Value.Day; model.DateOfBirthMonth = dateOfBirth.Value.Month; model.DateOfBirthYear = dateOfBirth.Value.Year; } model.Company = customer.GetAttribute<string>(SystemCustomerAttributeNames.Company); model.StreetAddress = customer.GetAttribute<string>(SystemCustomerAttributeNames.StreetAddress); model.StreetAddress2 = customer.GetAttribute<string>(SystemCustomerAttributeNames.StreetAddress2); model.ZipPostalCode = customer.GetAttribute<string>(SystemCustomerAttributeNames.ZipPostalCode); model.City = customer.GetAttribute<string>(SystemCustomerAttributeNames.City); model.CountryId = customer.GetAttribute<int>(SystemCustomerAttributeNames.CountryId); model.StateProvinceId = customer.GetAttribute<int>(SystemCustomerAttributeNames.StateProvinceId); model.Phone = customer.GetAttribute<string>(SystemCustomerAttributeNames.Phone); model.Fax = customer.GetAttribute<string>(SystemCustomerAttributeNames.Fax); //newsletter var newsletter = _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmailAndStoreId(customer.Email, _storeContext.CurrentStore.Id); model.Newsletter = newsletter != null && newsletter.Active; model.Signature = customer.GetAttribute<string>(SystemCustomerAttributeNames.Signature); model.Email = customer.Email; model.Username = customer.Username; } else { if (_customerSettings.UsernamesEnabled && !_customerSettings.AllowUsersToChangeUsernames) model.Username = customer.Username; } //countries and states if (_customerSettings.CountryEnabled) { model.AvailableCountries.Add(new SelectListItem { Text = _localizationService.GetResource("Address.SelectCountry"), Value = "0" }); foreach (var c in _countryService.GetAllCountries(_workContext.WorkingLanguage.Id)) { model.AvailableCountries.Add(new SelectListItem { Text = c.GetLocalized(x => x.Name), Value = c.Id.ToString(), Selected = c.Id == model.CountryId }); } if (_customerSettings.StateProvinceEnabled) { //states var states = _stateProvinceService.GetStateProvincesByCountryId(model.CountryId, _workContext.WorkingLanguage.Id).ToList(); if (states.Count > 0) { model.AvailableStates.Add(new SelectListItem { Text = _localizationService.GetResource("Address.SelectState"), Value = "0" }); foreach (var s in states) { model.AvailableStates.Add(new SelectListItem { Text = s.GetLocalized(x => x.Name), Value = s.Id.ToString(), Selected = (s.Id == model.StateProvinceId) }); } } else { bool anyCountrySelected = model.AvailableCountries.Any(x => x.Selected); model.AvailableStates.Add(new SelectListItem { Text = _localizationService.GetResource(anyCountrySelected ? "Address.OtherNonUS" : "Address.SelectState"), Value = "0" }); } } } model.DisplayVatNumber = _taxSettings.EuVatEnabled; model.VatNumberStatusNote = ((VatNumberStatus)customer.GetAttribute<int>(SystemCustomerAttributeNames.VatNumberStatusId)) .GetLocalizedEnum(_localizationService, _workContext); model.GenderEnabled = _customerSettings.GenderEnabled; model.DateOfBirthEnabled = _customerSettings.DateOfBirthEnabled; model.DateOfBirthRequired = _customerSettings.DateOfBirthRequired; model.CompanyEnabled = _customerSettings.CompanyEnabled; model.CompanyRequired = _customerSettings.CompanyRequired; model.StreetAddressEnabled = _customerSettings.StreetAddressEnabled; model.StreetAddressRequired = _customerSettings.StreetAddressRequired; model.StreetAddress2Enabled = _customerSettings.StreetAddress2Enabled; model.StreetAddress2Required = _customerSettings.StreetAddress2Required; model.ZipPostalCodeEnabled = _customerSettings.ZipPostalCodeEnabled; model.ZipPostalCodeRequired = _customerSettings.ZipPostalCodeRequired; model.CityEnabled = _customerSettings.CityEnabled; model.CityRequired = _customerSettings.CityRequired; model.CountryEnabled = _customerSettings.CountryEnabled; model.CountryRequired = _customerSettings.CountryRequired; model.StateProvinceEnabled = _customerSettings.StateProvinceEnabled; model.StateProvinceRequired = _customerSettings.StateProvinceRequired; model.PhoneEnabled = _customerSettings.PhoneEnabled; model.PhoneRequired = _customerSettings.PhoneRequired; model.FaxEnabled = _customerSettings.FaxEnabled; model.FaxRequired = _customerSettings.FaxRequired; model.NewsletterEnabled = _customerSettings.NewsletterEnabled; model.UsernamesEnabled = _customerSettings.UsernamesEnabled; model.AllowUsersToChangeUsernames = _customerSettings.AllowUsersToChangeUsernames; model.CheckUsernameAvailabilityEnabled = _customerSettings.CheckUsernameAvailabilityEnabled; model.SignatureEnabled = _forumSettings.ForumsEnabled && _forumSettings.SignaturesEnabled; //external authentication model.NumberOfExternalAuthenticationProviders = _openAuthenticationService .LoadActiveExternalAuthenticationMethods(_storeContext.CurrentStore.Id) .Count; foreach (var ear in _openAuthenticationService.GetExternalIdentifiersFor(customer)) { var authMethod = _openAuthenticationService.LoadExternalAuthenticationMethodBySystemName(ear.ProviderSystemName); if (authMethod == null || !authMethod.IsMethodActive(_externalAuthenticationSettings)) continue; model.AssociatedExternalAuthRecords.Add(new CustomerInfoModel.AssociatedExternalAuthModel { Id = ear.Id, Email = ear.Email, ExternalIdentifier = ear.ExternalIdentifier, AuthMethodName = authMethod.GetLocalizedFriendlyName(_localizationService, _workContext.WorkingLanguage.Id) }); } //custom customer attributes var customAttributes = PrepareCustomCustomerAttributes(customer, overrideCustomCustomerAttributesXml); customAttributes.ForEach(model.CustomerAttributes.Add); }
public virtual void AddCustomerTokens(IList<Token> tokens, Customer customer) { tokens.Add(new Token("Customer.Email", customer.Email)); tokens.Add(new Token("Customer.Username", customer.Username)); tokens.Add(new Token("Customer.FullName", customer.GetFullName())); tokens.Add(new Token("Customer.FirstName", customer.GetAttribute<string>(SystemCustomerAttributeNames.FirstName))); tokens.Add(new Token("Customer.LastName", customer.GetAttribute<string>(SystemCustomerAttributeNames.LastName))); tokens.Add(new Token("Customer.VatNumber", customer.GetAttribute<string>(SystemCustomerAttributeNames.VatNumber))); tokens.Add(new Token("Customer.VatNumberStatus", ((VatNumberStatus)customer.GetAttribute<int>(SystemCustomerAttributeNames.VatNumberStatusId)).ToString())); //note: we do not use SEO friendly URLS because we can get errors caused by having .(dot) in the URL (from the email address) //TODO add a method for getting URL (use routing because it handles all SEO friendly URLs) string passwordRecoveryUrl = string.Format("{0}passwordrecovery/confirm?token={1}&email={2}", GetStoreUrl(), customer.GetAttribute<string>(SystemCustomerAttributeNames.PasswordRecoveryToken), HttpUtility.UrlEncode(customer.Email)); string accountActivationUrl = string.Format("{0}customer/activation?token={1}&email={2}", GetStoreUrl(), customer.GetAttribute<string>(SystemCustomerAttributeNames.AccountActivationToken), HttpUtility.UrlEncode(customer.Email)); var wishlistUrl = string.Format("{0}wishlist/{1}", GetStoreUrl(), customer.CustomerGuid); tokens.Add(new Token("Customer.PasswordRecoveryURL", passwordRecoveryUrl, true)); tokens.Add(new Token("Customer.AccountActivationURL", accountActivationUrl, true)); tokens.Add(new Token("Wishlist.URLForCustomer", wishlistUrl, true)); //event notification _eventPublisher.EntityTokensAdded(customer, tokens); }
/// <summary> /// Migrate shopping cart /// </summary> /// <param name="fromCustomer">From customer</param> /// <param name="toCustomer">To customer</param> /// <param name="includeCouponCodes">A value indicating whether to coupon codes (discount and gift card) should be also re-applied</param> public virtual void MigrateShoppingCart(Customer fromCustomer, Customer toCustomer, bool includeCouponCodes) { if (fromCustomer == null) throw new ArgumentNullException("fromCustomer"); if (toCustomer == null) throw new ArgumentNullException("toCustomer"); if (fromCustomer.ID == toCustomer.ID) return; //the same customer //shopping cart items var fromCart = fromCustomer.ShoppingCartItems.ToList(); for (int i = 0; i < fromCart.Count; i++) { var sci = fromCart[i]; AddToCart(toCustomer, sci.Product, sci.ShoppingCartType, sci.StoreId, sci.AttributesXml, sci.CustomerEnteredPrice, sci.RentalStartDateUtc, sci.RentalEndDateUtc, sci.Quantity, false); } for (int i = 0; i < fromCart.Count; i++) { var sci = fromCart[i]; DeleteShoppingCartItem(sci); } //migrate gift card and discount coupon codes if (includeCouponCodes) { //discount var discountCouponCode = fromCustomer.GetAttribute<string>(SystemCustomerAttributeNames.DiscountCouponCode); if (!String.IsNullOrEmpty(discountCouponCode)) _genericAttributeService.SaveAttribute(toCustomer, SystemCustomerAttributeNames.DiscountCouponCode, discountCouponCode); //gift card foreach (var gcCode in fromCustomer.ParseAppliedGiftCardCouponCodes()) toCustomer.ApplyGiftCardCouponCode(gcCode); //save customer _customerService.UpdateCustomer(toCustomer); } }
/// <summary> /// Gets a customer time zone /// </summary> /// <param name="customer">Customer</param> /// <returns>Customer time zone; if customer is null, then default store time zone</returns> public virtual TimeZoneInfo GetCustomerTimeZone(Customer customer) { //registered user TimeZoneInfo timeZoneInfo = null; if (_dateTimeSettings.AllowCustomersToSetTimeZone) { string timeZoneId = string.Empty; if (customer != null) timeZoneId = customer.GetAttribute<string>(SystemCustomerAttributeNames.TimeZoneId, _genericAttributeService); try { if (!String.IsNullOrEmpty(timeZoneId)) timeZoneInfo = FindTimeZoneById(timeZoneId); } catch (Exception exc) { Debug.Write(exc.ToString()); } } //default timezone if (timeZoneInfo == null) timeZoneInfo = this.DefaultStoreTimeZone; return timeZoneInfo; }
/// <summary> /// Get a value indicating whether a customer is consumer (a person, not a company) located in Europe Union /// </summary> /// <param name="customer">Customer</param> /// <returns>Result</returns> protected virtual bool IsEuConsumer(Customer customer) { if (customer == null) throw new ArgumentNullException("customer"); Country country = null; //get country from billing address if (_addressSettings.CountryEnabled && customer.BillingAddress != null) country = customer.BillingAddress.Country; //get country specified during registration? if (country == null && _customerSettings.CountryEnabled) { var countryId = customer.GetAttribute<int>(SystemCustomerAttributeNames.CountryId); country = _countryService.GetCountryById(countryId); } //get country by IP address if (country == null) { var ipAddress = customer.LastIpAddress; //ipAddress = _webHelper.GetCurrentIpAddress(); var countryIsoCode = _geoLookupService.LookupCountryIsoCode(ipAddress); country = _countryService.GetCountryByTwoLetterIsoCode(countryIsoCode); } //we cannot detect country if (country == null) return false; //outside EU if (!country.SubjectToVat) return false; //company (business) or consumer? var customerVatStatus = (VatNumberStatus)customer.GetAttribute<int>(SystemCustomerAttributeNames.VatNumberStatusId); if (customerVatStatus == VatNumberStatus.Valid) return false; //TODO: use specified company name? (both address and registration one) //consumer return true; }
/// <summary> /// Validate discount /// </summary> /// <param name="discount">Discount</param> /// <param name="customer">Customer</param> /// <returns>Discount validation result</returns> public virtual DiscountValidationResult ValidateDiscount(Discount discount, Customer customer) { if (discount == null) throw new ArgumentNullException("discount"); var couponCodeToValidate = ""; if (customer != null) couponCodeToValidate = customer.GetAttribute<string>(SystemCustomerAttributeNames.DiscountCouponCode); return ValidateDiscount(discount, customer, couponCodeToValidate); }