本文整理汇总了C#中Nop.Core.Domain.Customers.Customer.GetAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# Customer.GetAttribute方法的具体用法?C# Customer.GetAttribute怎么用?C# Customer.GetAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nop.Core.Domain.Customers.Customer
的用法示例。
在下文中一共展示了Customer.GetAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddVendorTokens
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);
}
示例2: MigrateShoppingCart
/// <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);
}
}
示例3: PrepareCustomerInfoModel
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;
//.........这里部分代码省略.........
示例4: PrepareCustomCustomerAttributes
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;
}
示例5: IsDiscountValid
/// <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);
}
示例6: PrepareCustomerModel
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) });
}
}
//.........这里部分代码省略.........
示例7: PrepareCustomerAttributeModel
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);
}
}
示例8: AddAttribute
private static void AddAttribute(MergeVar myMergeVars, Customer customer, string attribute, string mailchimpField)
{
var value = customer.GetAttribute<string>(attribute);
myMergeVars.Add(mailchimpField, value);
}
示例9: GetCustomerTimeZone
/// <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;
}
示例10: AddCustomerTokens
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);
}
示例11: PrepareCustomerModel
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))
//.........这里部分代码省略.........
示例12: PrepareModel
//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");
//.........这里部分代码省略.........
示例13: PrepareCustomerInfoModel
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;
//.........这里部分代码省略.........
示例14: AddCustomerTokens
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));
}
示例15: IsVatExempt
/// <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;
}