public void SetDefaultShippingAddress(int addressId) { var customer = ECommerceContext.CurrentCustomer; if (customer != null) { customer.SetValue(CustomerDefaultShippingAddresIDFieldName, addressId); CustomerInfoProvider.SetCustomerInfo(customer); } }
/// <summary> /// Saves customer data and returns customer ID. /// </summary> public int Save() { if (!IsValid()) { return(0); } // Create customer CustomerInfo customer = new CustomerInfo() { CustomerSiteID = CMSContext.CurrentSiteID, CustomerFirstName = txtCustomerFirstName.Text.Trim().Truncate(100), CustomerLastName = txtCustomerLastName.Text.Trim().Truncate(100), CustomerCompany = txtCustomerCompany.Text.Trim(), CustomerOrganizationID = txtOrganizationID.Text.Trim(), CustomerTaxRegistrationID = txtTaxRegistrationID.Text.Trim(), CustomerCountryID = drpCountry.CountryID, CustomerStateID = drpCountry.StateID, CustomerEmail = txtCustomerEmail.Text.Trim().Truncate(100), CustomerPhone = txtCustomerPhone.Text.Trim(), CustomerFax = txtCustomerFax.Text.Trim(), CustomerEnabled = true }; // Save data in transaction using (CMSTransactionScope tr = new CMSTransactionScope()) { CustomerInfoProvider.SetCustomerInfo(customer); if (chkCreateLogin.Checked) { // Create user UserInfo user = new UserInfo() { UserName = txtUserName.Text.Trim(), FullName = customer.CustomerFirstName + " " + customer.CustomerLastName, IsGlobalAdministrator = false }; user.SetValue("UserEnabled", true); UserInfoProvider.SetPassword(user, passStrength.Text); UserInfoProvider.AddUserToSite(user.UserName, CMSContext.CurrentSiteName); customer.CustomerUserID = user.UserID; CustomerInfoProvider.SetCustomerInfo(customer); } tr.Commit(); } return(customer.CustomerID); }
/// <summary> /// Saves the customer into the database. /// </summary> /// <param name="validate">Specifies whether the validation should be performed.</param> public void Save(bool validate = true) { if (validate) { var result = Validate(); if (result.CheckFailed) { throw new InvalidOperationException(); } } CustomerInfoProvider.SetCustomerInfo(OriginalCustomer); }
private static CustomerInfo GenerateCustomer(string fullName, int siteID) { var strArray = fullName.Trim().Split(' '); var str1 = strArray[0]; var str2 = strArray[1]; var customerObj = new CustomerInfo(); customerObj.CustomerEmail = str1.ToLowerInvariant() + "@" + str2.ToLowerInvariant() + ".local"; customerObj.CustomerFirstName = str1; customerObj.CustomerLastName = str2; customerObj.CustomerSiteID = siteID; CustomerInfoProvider.SetCustomerInfo(customerObj); return(customerObj); }
private bool EnsureCartCustomer(ShoppingCartInfo shoppingCart) { CustomerInfo customer = shoppingCart.Customer; customer.CustomerSiteID = shoppingCart.ShoppingCartSiteID; customer.CustomerUserID = shoppingCart.ShoppingCartUserID; CustomerInfoProvider.SetCustomerInfo(customer); shoppingCart.ShoppingCartCustomerID = customer.CustomerID; if (customer.CustomerID == 0) { LogError("Save customer action failed", EVENT_CODE_SAVING); return(false); } return(true); }
private CustomerInfo CreateCustomer(int userID, int siteID, UserDto userDto) { var newCustomer = new CustomerInfo { CustomerFirstName = userDto.FirstName, CustomerLastName = userDto.LastName, CustomerEmail = userDto.Email, CustomerSiteID = siteID, CustomerUserID = userID, CustomerCompany = userDto.Company ?? "", CustomerOrganizationID = userDto.OrganizationID, CustomerPhone = userDto.PhoneNumber ?? "", CustomerTaxRegistrationID = userDto.TaxRegistrationID ?? "", CustomerCountryID = FindCountry(userDto.Country)?.CountryID ?? 0 }; CustomerInfoProvider.SetCustomerInfo(newCustomer); return(newCustomer); }
/// <summary> /// Create cusotmer based on logged in user details /// </summary> /// <returns>Customer id</returns> private int CreateCustomer() { try { CustomerInfo objCustomer = new CustomerInfo(); objCustomer.CustomerUserID = CurrentUser.UserID; objCustomer.CustomerEmail = CurrentUser.Email; objCustomer.CustomerFirstName = CurrentUser.FirstName; objCustomer.CustomerLastName = CurrentUser.LastName; objCustomer.CustomerSiteID = CurrentSite.SiteID; CustomerInfoProvider.SetCustomerInfo(objCustomer); CacheHelper.ClearCache(); return(objCustomer != null ? objCustomer.CustomerID : default(int)); } catch (Exception ex) { EventLogProvider.LogException("CreateAddress.ascx.cs", "CreateCustomer()", ex); } return(default(int)); }
private bool EnsureCartCustomer(ShoppingCartInfo shoppingCart) { CustomerInfo customer = shoppingCart.Customer; customer.CustomerSiteID = shoppingCart.ShoppingCartSiteID; customer.CustomerUserID = shoppingCart.ShoppingCartUserID; CustomerInfoProvider.SetCustomerInfo(customer); shoppingCart.ShoppingCartCustomerID = customer.CustomerID; if (customer.CustomerID > 0) { // Track successful registration conversion string name = ECommerceSettings.RegistrationConversionName(shoppingCart.SiteName); ECommerceHelper.TrackRegistrationConversion(shoppingCart.SiteName, name); // Log customer registration activity var activityCustomerRegistration = new ActivityCustomerRegistration(customer, MembershipContext.AuthenticatedUser, AnalyticsContext.ActivityEnvironmentVariables); if (activityCustomerRegistration.Data != null) { if ((ContactID <= 0) && (customer.CustomerUser != null)) { activityCustomerRegistration.Data.ContactID = ModuleCommands.OnlineMarketingGetUserLoginContactID(customer.CustomerUser); } else { activityCustomerRegistration.Data.ContactID = ContactID; } activityCustomerRegistration.Log(); } return(true); } else { LogError("Save customer action failed", EVENT_CODE_SAVING); return(false); } }
public override bool ProcessStep() { string siteName = SiteContext.CurrentSiteName; if (IsExistingAccount()) { // Sign in customer with existing account // Authenticate user //UserInfo ui = UserInfoProvider.GetUserInfo(txtLogin.Text); UserInfo ui = AuthenticationHelper.AuthenticateUser(txtLogin.Text.Trim(), txtMotDePasse.Text, SiteContext.CurrentSiteName); if (ui == null) { // ShowError(ResHelper.GetString("ShoppingCartCheckRegistration.LoginFailed")); return(false); } // Set current user MembershipContext.AuthenticatedUser = new CurrentUserInfo(ui, true); UserInfoProvider.SetPreferredCultures(ui); // Sign in FormsAuthentication.SetAuthCookie(ui.UserName, false); // Registered user has already started shopping as anonymous user -> Drop his stored shopping cart ShoppingCartInfoProvider.DeleteShoppingCartInfo(ui.UserID, siteName); // Assign current user to the current shopping cart ShoppingCart.User = ui; // Save changes to database // Already done in the end of this method if (!this.ShoppingCartControl.IsInternalOrder) { ShoppingCartInfoProvider.SetShoppingCartInfo(this.ShoppingCartInfObj); } //Create a customer for the user if do not yet exist CustomerInfo ci = CustomerInfoProvider.GetCustomerInfoByUserID(this.ShoppingCartControl.UserInfo.UserID); if (ci == null) { ci = new CustomerInfo(); ci.CustomerUserID = this.ShoppingCartControl.UserInfo.UserID; ci.CustomerEnabled = true; } // Old email address //string oldEmail = ci.CustomerEmail.ToLower(); ; ci.CustomerFirstName = ui.FirstName; ci.CustomerLastName = ui.LastName; ci.CustomerEmail = ui.Email; ci.CustomerCompany = ""; ci.CustomerOrganizationID = ""; ci.CustomerTaxRegistrationID = ""; // Update customer data CustomerInfoProvider.SetCustomerInfo(ci); // Set the shopping cart customer ID this.ShoppingCart.ShoppingCartCustomerID = ci.CustomerID; } else if (IsNewAccount()) { txtEmail2.Text = txtEmail2.Text.Trim(); pnlCompanyAccount1.Visible = chkCorporateBody.Checked; // Check if user exists UserInfo ui = UserInfoProvider.GetUserInfo(txtEmail2.Text); if (ui != null) { lblError.Visible = true; lblError.Text = GetString("ShoppingCartUserRegistration.ErrorUserExists"); return(false); } // Check all sites where user will be assigned string checkSites = (String.IsNullOrEmpty(ShoppingCartControl.AssignToSites)) ? SiteContext.CurrentSiteName : ShoppingCartControl.AssignToSites; if (!UserInfoProvider.IsEmailUnique(txtEmail2.Text.Trim(), checkSites, 0)) { lblError.Visible = true; lblError.Text = GetString("UserInfo.EmailAlreadyExist"); return(false); } // Create new customer and user account and sign in // User ui = new UserInfo(); ui.UserName = txtEmailRegistration.Text.Trim(); ui.Email = txtEmailRegistration.Text.Trim(); ui.FirstName = txtFirstName.Text.Trim(); ui.FullName = UserInfoProvider.GetFullName(txtFirstName.Text.Trim(), String.Empty, txtLastName.Text.Trim()); ui.LastName = txtLastName.Text.Trim(); ui.Enabled = true; ui.UserIsGlobalAdministrator = false; ui.UserURLReferrer = MembershipContext.AuthenticatedUser.URLReferrer; ui.UserCampaign = AnalyticsHelper.Campaign; ui.UserSettings.UserRegistrationInfo.IPAddress = RequestContext.UserHostAddress; ui.UserSettings.UserRegistrationInfo.Agent = HttpContext.Current.Request.UserAgent; try { UserInfoProvider.SetPassword(ui, txtMotDePasseRegistration.Text); string[] siteList; // If AssignToSites field set if (!String.IsNullOrEmpty(ShoppingCartControl.AssignToSites)) { siteList = ShoppingCartControl.AssignToSites.Split(';'); } else // If not set user current site { siteList = new string[] { siteName }; } foreach (string site in siteList) { UserInfoProvider.AddUserToSite(ui.UserName, site); // Add user to roles if (ShoppingCartControl.AssignToRoles != "") { AssignUserToRoles(ui.UserName, ShoppingCartControl.AssignToRoles, site); } } // Log registered user AnalyticsHelper.LogRegisteredUser(siteName, ui); Activity activity = new ActivityRegistration(ui, DocumentContext.CurrentDocument, AnalyticsContext.ActivityEnvironmentVariables); if (activity.Data != null) { activity.Data.ContactID = ModuleCommands.OnlineMarketingGetUserLoginContactID(ui); activity.Log(); } } catch (Exception ex) { lblError.Visible = true; lblError.Text = ex.Message; return(false); } // Customer CustomerInfo ci = new CustomerInfo(); ci.CustomerFirstName = txtFirstName.Text.Trim(); ci.CustomerLastName = txtLastName.Text.Trim(); ci.CustomerEmail = txtEmailRegistration.Text.Trim(); ci.CustomerCompany = ""; ci.CustomerOrganizationID = ""; ci.CustomerTaxRegistrationID = ""; if (chkCorporateBody.Checked) { ci.CustomerCompany = txtCompany1.Text.Trim(); if (mShowOrganizationIDField) { ci.CustomerOrganizationID = txtOrganizationID.Text.Trim(); } if (mShowTaxRegistrationIDField) { ci.CustomerTaxRegistrationID = txtTaxRegistrationID.Text.Trim(); } } ci.CustomerUserID = ui.UserID; ci.CustomerSiteID = 0; ci.CustomerEnabled = true; ci.CustomerCreated = DateTime.Now; CustomerInfoProvider.SetCustomerInfo(ci); // Track successful registration conversion string name = ShoppingCartControl.RegistrationTrackConversionName; ECommerceHelper.TrackRegistrationConversion(ShoppingCart.SiteName, name); // Log "customer registration" activity and update profile var activityCustomerRegistration = new ActivityCustomerRegistration(ci, MembershipContext.AuthenticatedUser, AnalyticsContext.ActivityEnvironmentVariables); if (activityCustomerRegistration.Data != null) { if (ContactID <= 0) { activityCustomerRegistration.Data.ContactID = ModuleCommands.OnlineMarketingGetUserLoginContactID(ui); } activityCustomerRegistration.Log(); } // Sign in if (ui.UserEnabled) { CMSContext.AuthenticateUser(ui.UserName, false); ShoppingCart.User = ui; ContactID = ModuleCommands.OnlineMarketingGetUserLoginContactID(ui); Activity activity = new ActivityUserLogin(ContactID, ui, DocumentContext.CurrentDocument, AnalyticsContext.ActivityEnvironmentVariables); activity.Log(); } ShoppingCart.ShoppingCartCustomerID = ci.CustomerID; // Send new registration notification email if (ShoppingCartControl.SendNewRegistrationNotificationToAddress != "") { SendRegistrationNotification(ui); } /**aadrresse*/ // Process billing address //------------------------ int CountryID = ValidationHelper.GetInteger(ddlShippingCountry.SelectedValue, 0); AddressInfo ai = null; bool newAddress = true; ai = new AddressInfo(); string mCustomerName = ci.CustomerFirstName + " " + ci.CustomerLastName; // newAddress.AddressName = mCustomerName + " , " + txtAdresse.Text + " - " + txtCodePostale.Text + " " + txtVille.Text; ai.AddressPersonalName = mCustomerName + " , " + txtAdresse.Text + " - " + txtCodePostale.Text + " " + txtVille.Text; ai.AddressLine1 = txtAdresse.Text.Trim(); ai.AddressLine2 = txtAdresse.Text.Trim(); ai.AddressCity = txtVille.Text.Trim(); ai.AddressZip = txtCodePostale.Text.Trim(); ai.AddressCountryID = CountryID; if (newAddress) { ai.AddressIsBilling = true; ai.AddressIsShipping = !chkShippingAddr.Checked; ai.AddressEnabled = true; } ai.AddressCustomerID = ci.CustomerID; ai.AddressName = AddressInfoProvider.GetAddressName(ai); // Save address and set it's ID to ShoppingCartInfoObj AddressInfoProvider.SetAddressInfo(ai); // Update current contact's address ModuleCommands.OnlineMarketingMapAddress(ai, ContactID); ShoppingCart.ShoppingCartBillingAddressID = ai.AddressID; // If shopping cart does not need shipping if (!ShippingOptionInfoProvider.IsShippingNeeded(ShoppingCart)) { ShoppingCart.ShoppingCartShippingAddressID = 0; } // If shipping address is different from billing address else if (chkShippingAddr.Checked) { //// Check country presence //if (CountrySelector2.CountryID <= 0) //{ // lblError.Visible = true; // lblError.Text = GetString("countryselector.selectedcountryerr"); // return false; //} //if (!CountrySelector2.StateSelectionIsValid) //{ // lblError.Visible = true; // lblError.Text = GetString("countryselector.selectedstateerr"); // return false; //} //newAddress = false; //// Process shipping address ////------------------------- //ai = AddressInfoProvider.GetAddressInfo(Convert.ToInt32(drpShippingAddr.SelectedValue)); //if (ai == null) //{ // ai = new AddressInfo(); // newAddress = true; //} ai.AddressPersonalName = txtadresseshipping.Text.Trim(); ai.AddressLine1 = txtadresseshipping.Text.Trim(); ai.AddressLine2 = txtadresseshipping.Text.Trim(); ai.AddressCity = txtvilleshipping.Text.Trim(); ai.AddressZip = txtcpshipping.Text.Trim(); ai.AddressCountryID = CountryID; if (newAddress) { ai.AddressIsShipping = true; ai.AddressEnabled = true; ai.AddressIsBilling = false; ai.AddressIsCompany = false; ai.AddressEnabled = true; } ai.AddressCustomerID = ci.CustomerID; ai.AddressName = AddressInfoProvider.GetAddressName(ai); // Save address and set it's ID to ShoppingCartInfoObj AddressInfoProvider.SetAddressInfo(ai); ShoppingCart.ShoppingCartShippingAddressID = ai.AddressID; } // Shipping address is the same as billing address else { ShoppingCart.ShoppingCartShippingAddressID = ShoppingCart.ShoppingCartBillingAddressID; } /**finadrress*/ this.ShoppingCartControl.ButtonNextClickAction(); } try { if (!this.ShoppingCartControl.IsInternalOrder) { ShoppingCartInfoProvider.SetShoppingCartInfo(this.ShoppingCart); } return(true); } catch { return(false); } }
/// <summary> /// Process valid values of this step. /// </summary> public override bool ProcessStep() { if (plcAccount.Visible) { string siteName = SiteContext.CurrentSiteName; // Existing account if (radSignIn.Checked) { // Authenticate user UserInfo ui = AuthenticationHelper.AuthenticateUser(txtUsername.Text.Trim(), txtPsswd1.Text, SiteContext.CurrentSiteName, false); if (ui == null) { lblError.Text = GetString("ShoppingCartCheckRegistration.LoginFailed"); lblError.Visible = true; return(false); } // Sign in customer with existing account AuthenticationHelper.AuthenticateUser(ui.UserName, false); // Registered user has already started shopping as anonymous user -> Drop his stored shopping cart ShoppingCartInfoProvider.DeleteShoppingCartInfo(ui.UserID, siteName); // Assign current user to the current shopping cart ShoppingCart.User = ui; // Save changes to database if (!ShoppingCartControl.IsInternalOrder) { ShoppingCartInfoProvider.SetShoppingCartInfo(ShoppingCart); } // Log "login" activity MembershipActivityLogger.LogLogin(ui.UserName, DocumentContext.CurrentDocument); LoadStep(true); // Return false to get to Edit customer page return(false); } // New registration else if (radNewReg.Checked) { txtEmail2.Text = txtEmail2.Text.Trim(); pnlCompanyAccount1.Visible = chkCorporateBody.Checked; string[] siteList = { siteName }; // If AssignToSites field set if (!String.IsNullOrEmpty(ShoppingCartControl.AssignToSites)) { siteList = ShoppingCartControl.AssignToSites.Split(';'); } // Check if user exists UserInfo ui = UserInfoProvider.GetUserInfo(txtEmail2.Text); if (ui != null) { lblError.Visible = true; lblError.Text = GetString("ShoppingCartUserRegistration.ErrorUserExists"); return(false); } // Check all sites where user will be assigned if (!UserInfoProvider.IsEmailUnique(txtEmail2.Text.Trim(), siteList, 0)) { lblError.Visible = true; lblError.Text = GetString("UserInfo.EmailAlreadyExist"); return(false); } // Create new customer and user account and sign in // User ui = new UserInfo(); ui.UserName = txtEmail2.Text.Trim(); ui.Email = txtEmail2.Text.Trim(); ui.FirstName = txtFirstName1.Text.Trim(); ui.LastName = txtLastName1.Text.Trim(); ui.FullName = ui.FirstName + " " + ui.LastName; ui.Enabled = true; ui.SiteIndependentPrivilegeLevel = UserPrivilegeLevelEnum.None; ui.UserURLReferrer = CookieHelper.GetValue(CookieName.UrlReferrer); ui.UserCampaign = Service <ICampaignService> .Entry().CampaignCode; ui.UserSettings.UserRegistrationInfo.IPAddress = RequestContext.UserHostAddress; ui.UserSettings.UserRegistrationInfo.Agent = HttpContext.Current.Request.UserAgent; try { UserInfoProvider.SetPassword(ui, passStrength.Text); foreach (string site in siteList) { UserInfoProvider.AddUserToSite(ui.UserName, site); // Add user to roles if (ShoppingCartControl.AssignToRoles != "") { AssignUserToRoles(ui.UserName, ShoppingCartControl.AssignToRoles, site); } } // Log registered user AnalyticsHelper.LogRegisteredUser(siteName, ui); MembershipActivityLogger.LogRegistration(ui.UserName, DocumentContext.CurrentDocument); } catch (Exception ex) { lblError.Visible = true; lblError.Text = ex.Message; return(false); } // Customer CustomerInfo ci = new CustomerInfo(); ci.CustomerFirstName = txtFirstName1.Text.Trim(); ci.CustomerLastName = txtLastName1.Text.Trim(); ci.CustomerEmail = txtEmail2.Text.Trim(); ci.CustomerCompany = ""; ci.CustomerOrganizationID = ""; ci.CustomerTaxRegistrationID = ""; if (chkCorporateBody.Checked) { ci.CustomerCompany = txtCompany1.Text.Trim(); if (mShowOrganizationIDField) { ci.CustomerOrganizationID = txtOrganizationID.Text.Trim(); } if (mShowTaxRegistrationIDField) { ci.CustomerTaxRegistrationID = txtTaxRegistrationID.Text.Trim(); } } ci.CustomerUserID = ui.UserID; ci.CustomerSiteID = 0; ci.CustomerCreated = DateTime.Now; CustomerInfoProvider.SetCustomerInfo(ci); // Track successful registration conversion string name = ShoppingCartControl.RegistrationTrackConversionName; ECommerceHelper.TrackRegistrationConversion(ShoppingCart.SiteName, name); CreateContactRelation(ci); // Sign in if (ui.Enabled) { AuthenticationHelper.AuthenticateUser(ui.UserName, false); ShoppingCart.User = ui; MembershipActivityLogger.LogLogin(ui.UserName, DocumentContext.CurrentDocument); } ShoppingCart.ShoppingCartCustomerID = ci.CustomerID; // Send new registration notification email if (ShoppingCartControl.SendNewRegistrationNotificationToAddress != "") { SendRegistrationNotification(ui); } } // Anonymous customer else if (radAnonymous.Checked) { CustomerInfo ci = null; if (ShoppingCart.ShoppingCartCustomerID > 0) { // Update existing customer account ci = CustomerInfoProvider.GetCustomerInfo(ShoppingCart.ShoppingCartCustomerID); } if (ci == null) { // Create new customer account ci = new CustomerInfo(); } ci.CustomerFirstName = txtFirstName2.Text.Trim(); ci.CustomerLastName = txtLastName2.Text.Trim(); ci.CustomerEmail = txtEmail3.Text.Trim(); ci.CustomerCompany = ""; ci.CustomerOrganizationID = ""; ci.CustomerTaxRegistrationID = ""; if (chkCorporateBody2.Checked) { ci.CustomerCompany = txtCompany2.Text.Trim(); if (mShowOrganizationIDField) { ci.CustomerOrganizationID = txtOrganizationID2.Text.Trim(); } if (mShowTaxRegistrationIDField) { ci.CustomerTaxRegistrationID = txtTaxRegistrationID2.Text.Trim(); } } ci.CustomerCreated = DateTime.Now; ci.CustomerSiteID = SiteContext.CurrentSiteID; CustomerInfoProvider.SetCustomerInfo(ci); CreateContactRelation(ci); // Assign customer to shoppingcart ShoppingCart.ShoppingCartCustomerID = ci.CustomerID; } else { return(false); } } else { // Save the customer data bool newCustomer = false; CustomerInfo ci = CustomerInfoProvider.GetCustomerInfoByUserID(ShoppingCartControl.UserInfo.UserID); if (ci == null) { ci = new CustomerInfo(); ci.CustomerUserID = ShoppingCartControl.UserInfo.UserID; ci.CustomerSiteID = 0; newCustomer = true; } // Old email address string oldEmail = ci.CustomerEmail.ToLowerCSafe(); ci.CustomerFirstName = txtEditFirst.Text.Trim(); ci.CustomerLastName = txtEditLast.Text.Trim(); ci.CustomerEmail = txtEditEmail.Text.Trim(); pnlCompanyAccount2.Visible = chkEditCorpBody.Checked; ci.CustomerCompany = ""; ci.CustomerOrganizationID = ""; ci.CustomerTaxRegistrationID = ""; if (chkEditCorpBody.Checked) { ci.CustomerCompany = txtEditCompany.Text.Trim(); if (mShowOrganizationIDField) { ci.CustomerOrganizationID = txtEditOrgID.Text.Trim(); } if (mShowTaxRegistrationIDField) { ci.CustomerTaxRegistrationID = txtEditTaxRegID.Text.Trim(); } } // Update customer data CustomerInfoProvider.SetCustomerInfo(ci); // Update corresponding user email when required if (oldEmail != ci.CustomerEmail.ToLowerCSafe()) { UserInfo user = UserInfoProvider.GetUserInfo(ci.CustomerUserID); if (user != null) { user.Email = ci.CustomerEmail; UserInfoProvider.SetUserInfo(user); } } if (newCustomer) { CreateContactRelation(ci); } // Set the shopping cart customer ID ShoppingCart.ShoppingCartCustomerID = ci.CustomerID; } try { if (!ShoppingCartControl.IsInternalOrder) { ShoppingCartInfoProvider.SetShoppingCartInfo(ShoppingCart); } ShoppingCart.InvalidateCalculations(); return(true); } catch { return(false); } }
/// <summary> /// Sets data to database. /// </summary> protected void btnOK_Click(object sender, EventArgs e) { string errorMessage = ""; string siteName = SiteContext.CurrentSiteName; if ((txtCustomerCompany.Text.Trim() == "" || !IsBusiness) && ((txtCustomerFirstName.Text.Trim() == "") || (txtCustomerLastName.Text.Trim() == ""))) { errorMessage = GetString("Customers_Edit.errorInsert"); } // At least company name has to be filled when company account is selected if (errorMessage == "" && IsBusiness) { errorMessage = new Validator().NotEmpty(txtCustomerCompany.Text, GetString("customers_edit.errorCompany")).Result; } // Check the following items if complete company info is required for company account if (errorMessage == "" && ECommerceSettings.RequireCompanyInfo(siteName) && IsBusiness) { errorMessage = new Validator().NotEmpty(txtOraganizationID.Text, GetString("customers_edit.errorOrganizationID")) .NotEmpty(txtTaxRegistrationID.Text, GetString("customers_edit.errorTaxRegID")).Result; } if (errorMessage == "") { errorMessage = new Validator().IsEmail(txtCustomerEmail.Text.Trim(), GetString("customers_edit.erroremailformat"), true) .MatchesCondition(txtCustomerPhone.Text.Trim(), k => k.Length < 50, GetString("customers_edit.errorphoneformat")).Result; } plcCompanyInfo.Visible = IsBusiness; if (errorMessage == "") { // If customer doesn't already exist, create new one if (mCustomer == null) { mCustomer = new CustomerInfo(); mCustomer.CustomerUserID = MembershipContext.AuthenticatedUser.UserID; } mCustomer.CustomerEmail = txtCustomerEmail.Text.Trim(); mCustomer.CustomerLastName = txtCustomerLastName.Text.Trim(); mCustomer.CustomerPhone = txtCustomerPhone.Text.Trim(); mCustomer.CustomerFirstName = txtCustomerFirstName.Text.Trim(); mCustomer.CustomerCreated = DateTime.Now; if (IsBusiness) { mCustomer.CustomerCompany = txtCustomerCompany.Text.Trim(); mCustomer.CustomerOrganizationID = txtOraganizationID.Text.Trim(); mCustomer.CustomerTaxRegistrationID = txtTaxRegistrationID.Text.Trim(); } else { mCustomer.CustomerCompany = ""; mCustomer.CustomerOrganizationID = ""; mCustomer.CustomerTaxRegistrationID = ""; } // Update customer data CustomerInfoProvider.SetCustomerInfo(mCustomer); // Update corresponding contact data int currentContactId = ModuleCommands.OnlineMarketingGetCurrentContactID(); ModuleCommands.OnlineMarketingCreateRelation(mCustomer.CustomerID, MembershipType.ECOMMERCE_CUSTOMER, currentContactId); ContactInfoProvider.UpdateContactFromExternalData( mCustomer, DataClassInfoProvider.GetDataClassInfo(CustomerInfo.TYPEINFO.ObjectClassName).ClassContactOverwriteEnabled, currentContactId); // Let others now that customer was created if (OnCustomerCrated != null) { OnCustomerCrated(); ShowChangesSaved(); } else { URLHelper.Redirect(URLHelper.AddParameterToUrl(RequestContext.CurrentURL, "saved", "1")); } } else { //Show error ShowError(errorMessage); } }
/// <summary> /// Process valid values of this step. /// </summary> public override bool ProcessStep() { if (plcAccount.Visible) { string siteName = CMSContext.CurrentSiteName; // Existing account if (radSignIn.Checked) { // Authenticate user UserInfo ui = AuthenticationHelper.AuthenticateUser(txtUsername.Text.Trim(), txtPsswd1.Text, CMSContext.CurrentSiteName, false); if (ui == null) { lblError.Text = GetString("ShoppingCartCheckRegistration.LoginFailed"); lblError.Visible = true; return(false); } // Sign in customer with existing account CMSContext.AuthenticateUser(ui.UserName, false); // Registered user has already started shopping as anonymous user -> Drop his stored shopping cart ShoppingCartInfoProvider.DeleteShoppingCartInfo(ui.UserID, siteName); // Assign current user to the current shopping cart ShoppingCart.User = ui; // Save changes to database if (!ShoppingCartControl.IsInternalOrder) { ShoppingCartInfoProvider.SetShoppingCartInfo(ShoppingCart); } // Log "login" activity ContactID = ModuleCommands.OnlineMarketingGetUserLoginContactID(ui); Activity activity = new ActivityUserLogin(ContactID, ui, CMSContext.CurrentDocument, CMSContext.ActivityEnvironmentVariables); activity.Log(); LoadStep(true); // Return false to get to Edit customer page return(false); } // New registration else if (radNewReg.Checked) { txtEmail2.Text = txtEmail2.Text.Trim(); pnlCompanyAccount1.Visible = chkCorporateBody.Checked; // Check if user exists UserInfo ui = UserInfoProvider.GetUserInfo(txtEmail2.Text); if (ui != null) { lblError.Visible = true; lblError.Text = GetString("ShoppingCartUserRegistration.ErrorUserExists"); return(false); } // Check all sites where user will be assigned string checkSites = (String.IsNullOrEmpty(ShoppingCartControl.AssignToSites)) ? CMSContext.CurrentSiteName : ShoppingCartControl.AssignToSites; if (!UserInfoProvider.IsEmailUnique(txtEmail2.Text.Trim(), checkSites, 0)) { lblError.Visible = true; lblError.Text = GetString("UserInfo.EmailAlreadyExist"); return(false); } // Create new customer and user account and sign in // User ui = new UserInfo(); ui.UserName = txtEmail2.Text.Trim(); ui.Email = txtEmail2.Text.Trim(); ui.FirstName = txtFirstName1.Text.Trim(); ui.LastName = txtLastName1.Text.Trim(); ui.FullName = ui.FirstName + " " + ui.LastName; ui.Enabled = true; ui.UserIsGlobalAdministrator = false; ui.UserURLReferrer = CMSContext.CurrentUser.URLReferrer; ui.UserCampaign = CMSContext.Campaign; ui.UserSettings.UserRegistrationInfo.IPAddress = HTTPHelper.UserHostAddress; ui.UserSettings.UserRegistrationInfo.Agent = HttpContext.Current.Request.UserAgent; try { UserInfoProvider.SetPassword(ui, passStrength.Text); string[] siteList; // If AssignToSites field set if (!String.IsNullOrEmpty(ShoppingCartControl.AssignToSites)) { siteList = ShoppingCartControl.AssignToSites.Split(';'); } else // If not set user current site { siteList = new string[] { siteName }; } foreach (string site in siteList) { UserInfoProvider.AddUserToSite(ui.UserName, site); // Add user to roles if (ShoppingCartControl.AssignToRoles != "") { AssignUserToRoles(ui.UserName, ShoppingCartControl.AssignToRoles, site); } } // Log registered user AnalyticsHelper.LogRegisteredUser(siteName, ui); Activity activity = new ActivityRegistration(ui, CMSContext.CurrentDocument, CMSContext.ActivityEnvironmentVariables); if (activity.Data != null) { activity.Data.ContactID = ModuleCommands.OnlineMarketingGetUserLoginContactID(ui); activity.Log(); } } catch (Exception ex) { lblError.Visible = true; lblError.Text = ex.Message; return(false); } // Customer CustomerInfo ci = new CustomerInfo(); ci.CustomerFirstName = txtFirstName1.Text.Trim(); ci.CustomerLastName = txtLastName1.Text.Trim(); ci.CustomerEmail = txtEmail2.Text.Trim(); ci.CustomerCompany = ""; ci.CustomerOrganizationID = ""; ci.CustomerTaxRegistrationID = ""; if (chkCorporateBody.Checked) { ci.CustomerCompany = txtCompany1.Text.Trim(); if (mShowOrganizationIDField) { ci.CustomerOrganizationID = txtOrganizationID.Text.Trim(); } if (mShowTaxRegistrationIDField) { ci.CustomerTaxRegistrationID = txtTaxRegistrationID.Text.Trim(); } } ci.CustomerUserID = ui.UserID; ci.CustomerSiteID = 0; ci.CustomerEnabled = true; ci.CustomerCreated = DateTime.Now; CustomerInfoProvider.SetCustomerInfo(ci); // Track successful registration conversion string name = ShoppingCartControl.RegistrationTrackConversionName; ECommerceHelper.TrackRegistrationConversion(ShoppingCart.SiteName, name); // Log "customer registration" activity and update profile var activityCustomerRegistration = new ActivityCustomerRegistration(ci, CMSContext.CurrentUser, CMSContext.ActivityEnvironmentVariables); if (activityCustomerRegistration.Data != null) { if (ContactID <= 0) { activityCustomerRegistration.Data.ContactID = ModuleCommands.OnlineMarketingGetUserLoginContactID(ui); } activityCustomerRegistration.Log(); } // Sign in if (ui.UserEnabled) { CMSContext.AuthenticateUser(ui.UserName, false); ShoppingCart.User = ui; ContactID = ModuleCommands.OnlineMarketingGetUserLoginContactID(ui); Activity activity = new ActivityUserLogin(ContactID, ui, CMSContext.CurrentDocument, CMSContext.ActivityEnvironmentVariables); activity.Log(); } ShoppingCart.ShoppingCartCustomerID = ci.CustomerID; // Send new registration notification email if (ShoppingCartControl.SendNewRegistrationNotificationToAddress != "") { SendRegistrationNotification(ui); } } // Anonymous customer else if (radAnonymous.Checked) { CustomerInfo ci = null; if (ShoppingCart.ShoppingCartCustomerID > 0) { // Update existing customer account ci = CustomerInfoProvider.GetCustomerInfo(ShoppingCart.ShoppingCartCustomerID); } if (ci == null) { // Create new customer account ci = new CustomerInfo(); } ci.CustomerFirstName = txtFirstName2.Text.Trim(); ci.CustomerLastName = txtLastName2.Text.Trim(); ci.CustomerEmail = txtEmail3.Text.Trim(); ci.CustomerCompany = ""; ci.CustomerOrganizationID = ""; ci.CustomerTaxRegistrationID = ""; if (chkCorporateBody2.Checked) { ci.CustomerCompany = txtCompany2.Text.Trim(); if (mShowOrganizationIDField) { ci.CustomerOrganizationID = txtOrganizationID2.Text.Trim(); } if (mShowTaxRegistrationIDField) { ci.CustomerTaxRegistrationID = txtTaxRegistrationID2.Text.Trim(); } } ci.CustomerEnabled = true; ci.CustomerCreated = DateTime.Now; ci.CustomerSiteID = CMSContext.CurrentSiteID; CustomerInfoProvider.SetCustomerInfo(ci); // Log "customer registration" activity var activity = new ActivityCustomerRegistration(ci, CMSContext.CurrentUser, CMSContext.ActivityEnvironmentVariables); if (activity.Data != null) { ContactID = ModuleCommands.OnlineMarketingGetCurrentContactID(); activity.Data.ContactID = ContactID; activity.Log(); } // Assign customer to shoppingcart ShoppingCart.ShoppingCartCustomerID = ci.CustomerID; } else { return(false); } } else { // Save the customer data bool newCustomer = false; CustomerInfo ci = CustomerInfoProvider.GetCustomerInfoByUserID(ShoppingCartControl.UserInfo.UserID); if (ci == null) { ci = new CustomerInfo(); ci.CustomerUserID = ShoppingCartControl.UserInfo.UserID; ci.CustomerSiteID = 0; ci.CustomerEnabled = true; newCustomer = true; } // Old email address string oldEmail = ci.CustomerEmail.ToLowerCSafe(); ci.CustomerFirstName = txtEditFirst.Text.Trim(); ci.CustomerLastName = txtEditLast.Text.Trim(); ci.CustomerEmail = txtEditEmail.Text.Trim(); pnlCompanyAccount2.Visible = chkEditCorpBody.Checked; ci.CustomerCompany = ""; ci.CustomerOrganizationID = ""; ci.CustomerTaxRegistrationID = ""; if (chkEditCorpBody.Checked) { ci.CustomerCompany = txtEditCompany.Text.Trim(); if (mShowOrganizationIDField) { ci.CustomerOrganizationID = txtEditOrgID.Text.Trim(); } if (mShowTaxRegistrationIDField) { ci.CustomerTaxRegistrationID = txtEditTaxRegID.Text.Trim(); } } // Update customer data CustomerInfoProvider.SetCustomerInfo(ci); // Update corresponding user email when required if (oldEmail != ci.CustomerEmail.ToLowerCSafe()) { UserInfo user = UserInfoProvider.GetUserInfo(ci.CustomerUserID); if (user != null) { user.Email = ci.CustomerEmail; UserInfoProvider.SetUserInfo(user); } } // Log "customer registration" activity and update contact profile if (newCustomer) { var activity = new ActivityCustomerRegistration(ci, CMSContext.CurrentUser, CMSContext.ActivityEnvironmentVariables); activity.Log(); } // Set the shopping cart customer ID ShoppingCart.ShoppingCartCustomerID = ci.CustomerID; } try { if (!ShoppingCartControl.IsInternalOrder) { ShoppingCartInfoProvider.SetShoppingCartInfo(ShoppingCart); } return(true); } catch { return(false); } }
/// <summary> /// Saves data to DB without validation and permissions check. /// </summary> private void SaveData() { // If customer does not already exist, create new one if (Customer == null) { Customer = new CustomerInfo(); Customer.CustomerSiteID = currentSiteId; Customer.CustomerEnabled = true; } Customer.CustomerEmail = txtCustomerEmail.Text.Trim().Truncate(100); Customer.CustomerFax = txtCustomerFax.Text.Trim(); Customer.CustomerLastName = txtCustomerLastName.Text.Trim(); Customer.CustomerPhone = txtCustomerPhone.Text.Trim(); Customer.CustomerFirstName = txtCustomerFirstName.Text.Trim(); Customer.CustomerCompany = txtCustomerCompany.Text.Trim(); Customer.CustomerCountryID = drpCountry.CountryID; Customer.CustomerStateID = drpCountry.StateID; Customer.CustomerOrganizationID = txtOraganizationID.Text.Trim(); Customer.CustomerTaxRegistrationID = txtTaxRegistrationID.Text.Trim(); // Set customer's preferences Customer.CustomerPreferredCurrencyID = drpCurrency.CurrencyID; Customer.CustomerPreferredPaymentOptionID = drpPayment.PaymentID; Customer.CustomerPreferredShippingOptionID = drpShipping.ShippingID; if (plcDiscounts.Visible && plcGlobalDiscount.Visible) { Customer.CustomerDiscountLevelID = drpGlobalDiscountLevel.DiscountLevel; } // Only registered customer can be enabled/disabled if (Customer.CustomerIsRegistered) { Customer.CustomerEnabled = chkCustomerEnabled.Checked; } using (CMSTransactionScope tr = new CMSTransactionScope()) { bool newUserCreated = false; // Create user for customer if (chkHasLogin.Checked) { UserInfo ui = new UserInfo(); ui.UserName = txtUserName.Text.Trim(); ui.FullName = Customer.CustomerFirstName + " " + Customer.CustomerLastName; ui.IsGlobalAdministrator = false; ui.UserEnabled = true; UserInfoProvider.SetPassword(ui, passStrength.Text); UserInfoProvider.AddUserToSite(ui.UserName, CMSContext.CurrentSiteName); Customer.CustomerEnabled = true; Customer.CustomerUserID = ui.UserID; chkCustomerEnabled.Checked = Customer.CustomerEnabled; newUserCreated = true; // Show fields requiring registered customer pnlEdit.Visible = false; pnlStatic.Visible = true; plcDiscounts.Visible = true; plcPreferences.Visible = true; chkHasLogin.Checked = false; plcSiteDiscount.Visible = true; lblUserNameStaticValue.Text = HTMLHelper.HTMLEncode(Functions.GetFormattedUserName(ui.UserName)); if (AllowEditUser) { btnEditUser.OnClientClick = "modalDialog('" + CMSContext.ResolveDialogUrl("~/CMSModules/Membership/Pages/Users/User_Edit_Frameset.aspx") + "?userid=" + Customer.CustomerUserID + "', 'UserEdit', 950, 700); return false;"; btnEditUser.Visible = true; } // Hide global discount level selector when global levels not allowed plcGlobalDiscount.Visible = allowGlobalDiscountLevels; } // Save customer CustomerInfoProvider.SetCustomerInfo(Customer); // Enable/disable corresponding registered user if (Customer.CustomerIsRegistered && !newUserCreated) { UserInfo ui = UserInfoProvider.GetUserInfo(Customer.CustomerUserID); // If the customer already has the record in the CMS_User table, update email if (ui != null) { ui.Email = Customer.CustomerEmail; UserInfoProvider.SetUserInfo(ui); } // Save site specific values UserSiteInfo userSite = UserSiteInfoProvider.GetUserSiteInfo(Customer.CustomerUserID, currentSiteId); if (userSite != null) { userSite.UserPreferredCurrencyID = drpCurrency.CurrencyID; userSite.UserPreferredPaymentOptionID = drpPayment.PaymentID; userSite.UserPreferredShippingOptionID = drpShipping.ShippingID; userSite.UserDiscountLevelID = drpDiscountLevel.DiscountLevel; UserSiteInfoProvider.SetUserSiteInfo(userSite); } } // Commit transaction tr.Commit(); // Raise OnSaved event RaiseOnSaved(); } }
/// <summary> /// Sets data to database. /// </summary> protected void btnOK_Click(object sender, EventArgs e) { // Check module permissions if (!ECommerceContext.IsUserAuthorizedToModifyCustomer()) { RedirectToAccessDenied("CMS.Ecommerce", "EcommerceModify OR ModifyCustomers"); } string errorMessage = ""; if ((txtCustomerCompany.Text.Trim() == "") && ((txtCustomerFirstName.Text.Trim() == "") || (txtCustomerLastName.Text.Trim() == ""))) { errorMessage = GetString("Customers_Edit.errorInsert"); } else if (ECommerceSettings.RequireCompanyInfo(CMSContext.CurrentSite.SiteName) && (txtCustomerCompany.Text.Trim() != "" || txtOraganizationID.Text.Trim() != "" || txtTaxRegistrationID.Text.Trim() != "")) { errorMessage = new Validator().NotEmpty(txtCustomerCompany.Text.Trim(), GetString("customers_edit.errorcompany")) .NotEmpty(txtOraganizationID.Text.Trim(), GetString("customers_edit.errororganizationid")) .NotEmpty(txtTaxRegistrationID.Text.Trim(), GetString("customers_edit.errortaxregid")).Result; } else if ((txtCustomerEmail.Text.Trim() != "") && !ValidationHelper.IsEmail(txtCustomerEmail.Text)) { errorMessage = GetString("Customers_Edit.errorEmail"); } if (chkHasLogin.Checked) { if (errorMessage == "") { errorMessage = new Validator().NotEmpty(txtUserName.Text.Trim(), GetString("Customer_Edit_Login_Edit.rqvUserName")) .NotEmpty(passStrength.Text, GetString("Customer_Edit_Login_Edit.rqvPassword1")) .NotEmpty(txtPassword2.Text, GetString("Customer_Edit_Login_Edit.rqvPassword2")).Result; } if ((errorMessage == "") && (passStrength.Text != txtPassword2.Text)) { errorMessage = GetString("Customer_Edit_Login_Edit.DifferentPasswords"); } // Check policy if ((errorMessage == "") && !passStrength.IsValid()) { errorMessage = UserInfoProvider.GetPolicyViolationMessage(CMSContext.CurrentSiteName); } // Check if user name is unique if (errorMessage == "") { UserInfo existingUser = UserInfoProvider.GetUserInfo(txtUserName.Text.Trim()); if (existingUser != null) { errorMessage = GetString("Customer_Edit_Login_Edit.UserExist"); } } } if (errorMessage == "") { CustomerInfo customerObj = CustomerInfoProvider.GetCustomerInfo(customerid); // If customer does not already exist, create new one if (customerObj == null) { customerObj = new CustomerInfo(); customerObj.CustomerSiteID = currentSiteId; customerObj.CustomerEnabled = true; } customerObj.CustomerEmail = txtCustomerEmail.Text.Trim(); customerObj.CustomerFax = txtCustomerFax.Text.Trim(); customerObj.CustomerLastName = txtCustomerLastName.Text.Trim(); customerObj.CustomerPhone = txtCustomerPhone.Text.Trim(); customerObj.CustomerFirstName = txtCustomerFirstName.Text.Trim(); customerObj.CustomerCompany = txtCustomerCompany.Text.Trim(); customerObj.CustomerCountryID = drpCountry.CountryID; customerObj.CustomerStateID = drpCountry.StateID; customerObj.CustomerOrganizationID = txtOraganizationID.Text.Trim(); customerObj.CustomerTaxRegistrationID = txtTaxRegistrationID.Text.Trim(); // Set customer's preferences customerObj.CustomerPreferredCurrencyID = drpCurrency.CurrencyID; customerObj.CustomerPreferredPaymentOptionID = drpPayment.PaymentID; customerObj.CustomerPreferredShippingOptionID = drpShipping.ShippingID; if (plcDiscounts.Visible && plcGlobalDiscount.Visible) { customerObj.CustomerDiscountLevelID = drpGlobalDiscountLevel.DiscountLevel; } // Only registered customer can be enabled/diabled if (customerObj.CustomerIsRegistered) { customerObj.CustomerEnabled = chkCustomerEnabled.Checked; } bool refreshHeader = true; using (CMSTransactionScope tr = new CMSTransactionScope()) { // Create user for customer if (chkHasLogin.Checked) { UserInfo ui = new UserInfo(); ui.UserName = txtUserName.Text.Trim(); ui.FullName = customerObj.CustomerFirstName + " " + customerObj.CustomerLastName; ui.IsGlobalAdministrator = false; ui.UserEnabled = true; UserInfoProvider.SetPassword(ui, passStrength.Text); UserInfoProvider.AddUserToSite(ui.UserName, CMSContext.CurrentSiteName); customerObj.CustomerEnabled = true; customerObj.CustomerUserID = ui.UserID; refreshHeader = true; } // Save customer CustomerInfoProvider.SetCustomerInfo(customerObj); // Enable/disable coresponding registered user if (customerObj.CustomerIsRegistered && !chkHasLogin.Checked) { UserInfo ui = UserInfoProvider.GetUserInfo(customerObj.CustomerUserID); // If the customer already has the record in the CMS_User table, update email if (ui != null) { ui.Email = customerObj.CustomerEmail; UserInfoProvider.SetUserInfo(ui); } // Save site specific values UserSiteInfo userSite = UserSiteInfoProvider.GetUserSiteInfo(customerObj.CustomerUserID, CMSContext.CurrentSiteID); if (userSite != null) { userSite.UserPreferredCurrencyID = drpCurrency.CurrencyID; userSite.UserPreferredPaymentOptionID = drpPayment.PaymentID; userSite.UserPreferredShippingOptionID = drpShipping.ShippingID; userSite.UserDiscountLevelID = drpDiscountLevel.DiscountLevel; UserSiteInfoProvider.SetUserSiteInfo(userSite); } } // Commit transaction tr.Commit(); } URLHelper.Redirect("Customer_Edit_General.aspx?customerid=" + Convert.ToString(customerObj.CustomerID) + "&saved=1&hidebreadcrumbs=" + QueryHelper.GetInteger("hidebreadcrumbs", 0) + "&siteId=" + SiteID + (refreshHeader ? "&refreshHeader=1" : "")); } else { lblError.Visible = true; lblError.Text = errorMessage; } }
/// <summary> /// Sets data to database. /// </summary> protected void btnOK_Click(object sender, EventArgs e) { string errorMessage = ""; string siteName = CMSContext.CurrentSiteName; if ((txtCustomerCompany.Text.Trim() == "" || !chkCompanyAccount.Checked) && ((txtCustomerFirstName.Text.Trim() == "") || (txtCustomerLastName.Text.Trim() == ""))) { errorMessage = GetString("Customers_Edit.errorInsert"); } // Check the following items if complete company info is required for company account if (errorMessage == "" && ECommerceSettings.RequireCompanyInfo(siteName) && chkCompanyAccount.Checked) { errorMessage = new Validator().NotEmpty(txtCustomerCompany.Text, GetString("customers_edit.errorCompany")) .NotEmpty(txtOraganizationID.Text, GetString("customers_edit.errorOrganizationID")) .NotEmpty(txtTaxRegistrationID.Text, GetString("customers_edit.errorTaxRegID")).Result; } if (errorMessage == "") { errorMessage = new Validator().IsEmail(txtCustomerEmail.Text.Trim(), GetString("customers_edit.erroremailformat")).Result; } plcCompanyInfo.Visible = chkCompanyAccount.Checked; if (errorMessage == "") { // If customer doesn't already exist, create new one if (mCustomer == null) { mCustomer = new CustomerInfo(); mCustomer.CustomerEnabled = true; mCustomer.CustomerUserID = CMSContext.CurrentUser.UserID; } int currencyId = selectCurrency.CurrencyID; if (ECommerceContext.CurrentShoppingCart != null) { ECommerceContext.CurrentShoppingCart.ShoppingCartCurrencyID = currencyId; } mCustomer.CustomerEmail = txtCustomerEmail.Text.Trim(); mCustomer.CustomerFax = txtCustomerFax.Text.Trim(); mCustomer.CustomerLastName = txtCustomerLastName.Text.Trim(); mCustomer.CustomerPhone = txtCustomerPhone.Text.Trim(); mCustomer.CustomerFirstName = txtCustomerFirstName.Text.Trim(); mCustomer.CustomerCountryID = drpCountry.CountryID; mCustomer.CustomerStateID = drpCountry.StateID; mCustomer.CustomerCreated = DateTime.Now; // Set customers's preferences mCustomer.CustomerPreferredCurrencyID = (currencyId > 0) ? currencyId : 0; mCustomer.CustomerPreferredPaymentOptionID = drpPayment.PaymentID; mCustomer.CustomerPreferredShippingOptionID = drpShipping.ShippingID; // Check if customer is registered if (mCustomer.CustomerIsRegistered) { // Find user-site binding UserSiteInfo userSite = UserSiteInfoProvider.GetUserSiteInfo(Customer.CustomerUserID, CMSContext.CurrentSiteID); if (userSite != null) { // Set user's preferences userSite.UserPreferredCurrencyID = mCustomer.CustomerPreferredCurrencyID; userSite.UserPreferredPaymentOptionID = mCustomer.CustomerPreferredPaymentOptionID; userSite.UserPreferredShippingOptionID = mCustomer.CustomerPreferredShippingOptionID; UserSiteInfoProvider.SetUserSiteInfo(userSite); } } if (chkCompanyAccount.Checked) { mCustomer.CustomerCompany = txtCustomerCompany.Text.Trim(); if (ECommerceSettings.ShowOrganizationID(siteName)) { mCustomer.CustomerOrganizationID = txtOraganizationID.Text.Trim(); } if (ECommerceSettings.ShowTaxRegistrationID(siteName)) { mCustomer.CustomerTaxRegistrationID = txtTaxRegistrationID.Text.Trim(); } } else { mCustomer.CustomerCompany = ""; mCustomer.CustomerOrganizationID = ""; mCustomer.CustomerTaxRegistrationID = ""; } // Update customer data CustomerInfoProvider.SetCustomerInfo(mCustomer); // Update corresponding user email UserInfo user = mCustomer.CustomerUser; if (user != null) { user.Email = mCustomer.CustomerEmail; UserInfoProvider.SetUserInfo(user); } // Update corresponding contact data ModuleCommands.OnlineMarketingUpdateContactFromExternalData(mCustomer, DataClassInfoProvider.GetDataClass(CustomerInfo.TYPEINFO.ObjectClassName).ClassContactOverwriteEnabled, ModuleCommands.OnlineMarketingGetCurrentContactID()); // Let others now that customer was created if (OnCustomerCrated != null) { OnCustomerCrated(); ShowChangesSaved(); } else { URLHelper.Redirect(URLHelper.AddParameterToUrl(URLRewriter.CurrentURL, "saved", "1")); } } else { //Show error ShowError(errorMessage); } }
/// <summary> /// OK click handler (Proceed registration). /// </summary> protected void btnOK_Click(object sender, EventArgs e) { System.Globalization.CultureInfo currentUI = System.Globalization.CultureInfo.CurrentUICulture; if ((PageManager.ViewMode == ViewModeEnum.Design) || (HideOnCurrentPage) || (!IsVisible)) { // Do not process } else { String siteName = SiteContext.CurrentSiteName; #region "Banned IPs" // Ban IP addresses which are blocked for registration if (!BannedIPInfoProvider.IsAllowed(siteName, BanControlEnum.Registration)) { lblError.Visible = true; lblError.Text = GetString("banip.ipisbannedregistration"); return; } #endregion #region "Pr�nom" if (string.IsNullOrEmpty(txtFirstName.Text) || (txtFirstName.Text.ToLower() == "firstname") || (txtFirstName.Text.ToLower() == "pr�nom") || (txtFirstName.Text.ToLower() == "prenom")) { lblError.Visible = true; lblError.Text = GetString("errornom"); return; } #endregion #region "Nom" if (string.IsNullOrEmpty(txtLastName.Text) || (txtLastName.Text.ToLower() == "nom") || (txtLastName.Text.ToLower() == "lastname")) { lblError.Visible = true; lblError.Text = GetString("errorprenom"); return; } #endregion #region "T�l�phone" if (string.IsNullOrEmpty(txtTelephone.Text) || (txtTelephone.Text.ToLower() == "telephone")) { lblError.Visible = true; lblError.Text = GetString("errortelephone"); return; } #endregion #region Soci�t� if (rboui.Checked) { if ((txtnomsociete.Text == "") || (txtnomsociete.Text == "Nom soci�t�") || (txtnomsociete.Text == "Company Name")) { lblError.Visible = true; lblError.Text = GetString("errornomsociete "); return; } //if ((txtTva.Text == "") || (txtTva.Text == "TVA") || (txtTva.Text == "VAT")) //{ // lblError.Visible = true; // lblError.Text = GetString("errortva "); // return; //} //if (!EUVatChecker.Check(txtTva.Text)) //{ // lblError.Visible = true; // lblError.Text = GetString("errortva2 "); // return; //} } #endregion #region "Captcha" // Check if captcha is required if (DisplayCaptcha) { // Verifiy captcha text if (!scCaptcha.IsValid()) { // Display error message if catcha text is not valid lblError.Visible = true; lblError.Text = GetString("Webparts_Membership_RegistrationForm.captchaError"); return; } else { // Generate new captcha scCaptcha.GenerateNew(); } } #endregion // Set password //UserInfoProvider.SetPassword(ui, passStrength.Text); // UserInfoProvider.SetPassword(ui, txtPassword.Text.Trim()); if (!CurrentUser.IsAuthenticated()) { // Set password // UserInfoProvider.SetPassword(ui, txtPassword.Text.Trim()); } else { #region "Modif User" //Update User UserInfo updateUser = CurrentUser; updateUser.PreferredCultureCode = ""; updateUser.FirstName = txtFirstName.Text.Trim(); updateUser.FullName = UserInfoProvider.GetFullName(txtFirstName.Text.Trim(), String.Empty, txtLastName.Text.Trim()); updateUser.LastName = txtLastName.Text.Trim(); updateUser.MiddleName = ""; if (payement_option.SelectedValue != "0") { updateUser.SetValue("Civilite", payement_option.SelectedValue); } //updateUser.SetValue("Telephone", txtTelephone.Text); updateUser.SetValue("Telephone", txtTelephone.Text); /*if ((txtPassword.Text != "Mot de passe") && (txtPassword.Text != "Password")) * { * UserInfoProvider.SetPassword(updateUser, txtPassword.Text); * //updateUser.SetValue("UserPassword",txtPassword.Text); * }*/ UserInfoProvider.SetUserInfo(updateUser); //Update Customer CustomerInfo updateCustomer = ECommerceContext.CurrentCustomer; updateCustomer.CustomerUserID = updateUser.UserID; updateCustomer.CustomerLastName = txtLastName.Text.Trim(); updateCustomer.CustomerFirstName = txtFirstName.Text.Trim(); updateCustomer.CustomerEmail = txtEmail.Text.Trim(); //add update phone updateCustomer.CustomerPhone = txtTelephone.Text.Trim(); updateCustomer.CustomerEnabled = true; updateCustomer.CustomerLastModified = DateTime.Now; updateCustomer.CustomerSiteID = CMSContext.CurrentSiteID; updateCustomer.CustomerOrganizationID = ""; if (rboui.Checked) { updateCustomer.CustomerCompany = txtnomsociete.Text.Trim(); updateCustomer.CustomerTaxRegistrationID = txtTva.Text; } else { updateCustomer.CustomerCompany = string.Empty; updateCustomer.CustomerTaxRegistrationID = string.Empty; } if ((rboui.Checked) && (txtTva.Text.Trim() != "TVA") && (txtTva.Text.Trim() != "VAT")) { updateCustomer.CustomerTaxRegistrationID = txtTva.Text; updateCustomer.CustomerCompany = txtnomsociete.Text.ToString(); } else { updateCustomer.CustomerTaxRegistrationID = ""; updateCustomer.CustomerCompany = ""; } CustomerInfoProvider.SetCustomerInfo(updateCustomer); #endregion #region "Insert new adress / Update selected adress" //if (chkNewAddress.Checked) //{ #region "n�" if ((txtnumero.Text == "") || (txtnumero.Text == "Numero") || (txtnumero.Text == "Number")) { lblErrorAdress.Visible = true; lblErrorAdress.Text = GetString("errornumerorue"); return; } #endregion #region "adresse 1" if ((txtadresse1.Text == "") || (txtadresse1.Text == "Adresse 1") || (txtadresse1.Text == "Address 1")) { lblErrorAdress.Visible = true; lblErrorAdress.Text = GetString("erroradresse1"); return; } #endregion #region "adresse 2" if ((txtadresse2.Text == "") || (txtadresse2.Text == "Adresse 2") || (txtadresse2.Text == "Address 2")) { lblErrorAdress.Visible = true; lblErrorAdress.Text = GetString("erroradresse2"); return; } #endregion #region "CP" if ((txtcp.Text == "") || (txtcp.Text == "CP") || (txtcp.Text == "ZIP")) { lblErrorAdress.Visible = true; lblErrorAdress.Text = GetString("errorcp"); return; } #endregion #region "Ville" if ((txtville.Text == "") || (txtville.Text == "Ville") || (txtville.Text == "City")) { lblErrorAdress.Visible = true; lblErrorAdress.Text = GetString("errorville"); return; } #endregion #region "Pays" if ((ddlShippingCountry.Text == "Choose your country") || (ddlShippingCountry.Text == "Choisissez votre pays")) { lblErrorAdress.Visible = true; lblErrorAdress.Text = GetString("errorchoixpays "); return; } #endregion #region "Adresse" if ((chkShippingAddr.Checked == false) && (chkBillingAddr.Checked == false)) { lblErrorAdress.Visible = true; lblErrorAdress.Text = GetString("erroradressechek"); return; } #endregion if (txtIdAdresse.Text == "") { #region "New adress" // Create new address object AddressInfo newAddress = new AddressInfo(); int CountryID = ValidationHelper.GetInteger(ddlShippingCountry.SelectedValue, 0); CustomerInfo uc = ECommerceContext.CurrentCustomer; mCustomerId = uc.CustomerID; string mCustomerName = uc.CustomerFirstName + " " + uc.CustomerLastName; // Set the properties newAddress.AddressName = mCustomerName + " , " + txtnumero.Text + " " + txtadresse1.Text + " - " + txtcp.Text + " " + txtville.Text; newAddress.AddressLine1 = txtadresse1.Text; newAddress.AddressLine2 = txtadresse2.Text; newAddress.AddressCity = txtville.Text; newAddress.AddressZip = txtcp.Text; if (chkBillingAddr.Checked) { newAddress.AddressIsBilling = true; } else { newAddress.AddressIsBilling = false; } if (chkShippingAddr.Checked) { newAddress.AddressIsShipping = true; } else { newAddress.AddressIsShipping = false; } newAddress.AddressEnabled = true; newAddress.AddressPersonalName = mCustomerName; newAddress.AddressCustomerID = mCustomerId; newAddress.AddressCountryID = CountryID; newAddress.SetValue("AddressNumber", txtnumero.Text); // Create the address AddressInfoProvider.SetAddressInfo(newAddress); txtnumero.Text = string.Empty; txtadresse1.Text = string.Empty; txtadresse2.Text = string.Empty; txtcp.Text = string.Empty; txtville.Text = string.Empty; // PnlInsertAdress.Visible = false; if (newAddress != null && newAddress.AddressIsShipping == true) { Session["newAddress"] = newAddress.AddressID; //EventLogProvider eve = new EventLogProvider(); //eve.LogEvent("I", DateTime.Now, "id new address= " + Session["newAddress"], "code"); } #endregion } else { #region "Update selected adress" /* * // Udpate selected adress object * int CountryID = ValidationHelper.GetInteger(ddlShippingCountry.SelectedValue, 0); * int AddressId = Convert.ToInt32(txtIdAdresse.Text); * AddressInfo UpdateAdress = AddressInfoProvider.GetAddressInfo(AddressId); * CustomerInfo uc = ECommerceContext.CurrentCustomer; * mCustomerId = uc.CustomerID; * string mCustomerName = uc.CustomerFirstName + " " + uc.CustomerLastName; * // Set the properties * UpdateAdress.AddressName = mCustomerName + " , " + txtnumero.Text + " " + txtadresse1.Text + " - " + txtcp.Text + " " + txtville.Text; * UpdateAdress.SetValue("AddressNumber", txtnumero.Text); * UpdateAdress.AddressLine1 = txtadresse1.Text; * UpdateAdress.AddressLine2 = txtadresse2.Text; * UpdateAdress.AddressCity = txtville.Text; * UpdateAdress.AddressZip = txtcp.Text; * UpdateAdress.AddressIsBilling = chkBillingAddr.Checked; * UpdateAdress.AddressIsShipping = chkShippingAddr.Checked; * UpdateAdress.AddressEnabled = true; * UpdateAdress.AddressPersonalName = mCustomerName; * UpdateAdress.AddressCustomerID = mCustomerId; * UpdateAdress.AddressCountryID = CountryID; * * // Save addressinfo * AddressInfoProvider.SetAddressInfo(UpdateAdress); * AddressId = UpdateAdress.AddressID; */ #endregion } ReloadDataAdress(); //} #endregion } lblError.Visible = false; // PnlInsertAdress.Visible = false; } }
private void GenerateEcommerceData(int siteID) { var siteName = SiteInfoProvider.GetSiteName(siteID); var currencyInfo = CurrencyInfoProvider.GetCurrencies(siteID) .Where("CurrencyIsMain", QueryOperator.Equals, 1).TopN(1).FirstOrDefault(); var list1 = PaymentOptionInfoProvider.GetPaymentOptions(siteID).ToList(); var list2 = ShippingOptionInfoProvider.GetShippingOptions(siteID).ToList(); var orderStatusList = OrderStatusInfoProvider.GetOrderStatuses(siteID).ToDictionary(status => status.StatusName); var manufacturerExceptionList = new List <int> { ManufacturerInfoProvider.GetManufacturerInfo("Aerobie", siteName).ManufacturerID, //ManufacturerInfoProvider.GetManufacturerInfo("Chemex", siteName).ManufacturerID, //ManufacturerInfoProvider.GetManufacturerInfo("Espro", siteName).ManufacturerID }; var list3 = SKUInfoProvider.GetSKUs(siteID).ToList().Where(sku => { if (sku.IsProduct) { return(!manufacturerExceptionList.Contains(sku.SKUManufacturerID)); } return(false); }).ToList(); int num1; IList <int> intList; if (CustomerInfoProvider.GetCustomers().WhereEquals("CustomerSiteID", siteID).Count < 50) { num1 = customerNames.Length; intList = new List <int>(); for (var index = 0; index < num1; ++index) { intList.Add(GenerateCustomer(customerNames[index], siteID).CustomerID); } } else { intList = DataHelper.GetIntegerValues(CustomerInfoProvider.GetCustomers().Column("CustomerID") .WhereEquals("CustomerSiteID", siteID).WhereNotEquals("CustomerEmail", "alex").Tables[0], "CustomerID"); num1 = intList.Count; } var num2 = 0; var num3 = 0; for (var index1 = 0; index1 <= 30; ++index1) { ++num2; var num4 = 0; if (index1 > 5) { num4 = rand.Next(-1, 2); } for (var index2 = 0; index2 < num2 / 2 + num4; ++index2) { var orderStatusInfo = index1 >= 25 ? index1 >= 29 ? orderStatusList["New"] : orderStatusList["InProgress"] : orderStatusList["Completed"]; var orderInfo = new OrderInfo { OrderCustomerID = intList[num3 % num1], OrderCurrencyID = currencyInfo.CurrencyID, OrderSiteID = siteID, OrderStatusID = orderStatusInfo.StatusID, OrderIsPaid = "Completed".Equals(orderStatusInfo.StatusName, StringComparison.Ordinal) || (uint)rand.Next(0, 2) > 0U, OrderShippingOptionID = list2[rand.Next(list2.Count)].ShippingOptionID, OrderPaymentOptionID = list1[rand.Next(list1.Count)].PaymentOptionID, OrderGrandTotal = decimal.Zero, OrderGrandTotalInMainCurrency = decimal.Zero, OrderTotalPrice = decimal.Zero, OrderTotalPriceInMainCurrency = decimal.Zero, OrderTotalShipping = new decimal(10), OrderTotalTax = new decimal(10) }; OrderInfoProvider.SetOrderInfo(orderInfo); var orderItems = GenerateOrderItems(orderInfo, list3); GenerateOrderAddress(orderInfo.OrderID, GetRandomCountryId(), AddressType.Billing); GenerateOrderAddress(orderInfo.OrderID, GetRandomCountryId(), AddressType.Shipping); orderInfo.OrderDate = DateTime.Now.AddDays(index1 - 30); orderInfo.OrderTotalPrice = orderItems; orderInfo.OrderTotalPriceInMainCurrency = orderItems; orderInfo.OrderGrandTotal = orderItems; orderInfo.OrderGrandTotalInMainCurrency = orderItems; var cartInfoFromOrder = ShoppingCartInfoProvider.GetShoppingCartInfoFromOrder(orderInfo.OrderID); orderInfo.OrderInvoiceNumber = OrderInfoProvider.GenerateInvoiceNumber(cartInfoFromOrder); orderInfo.OrderInvoice = ShoppingCartInfoProvider.GetOrderInvoice(cartInfoFromOrder); OrderInfoProvider.SetOrderInfo(orderInfo); ++num3; } } if (UserInfoProvider.GetUserInfo("alex") != null) { return; } var customerInfo = new CustomerInfo { CustomerEmail = "*****@*****.**", CustomerFirstName = "Alexander", CustomerLastName = "Adams", CustomerSiteID = siteID, CustomerCompany = "Alex & Co. Ltd", CustomerTaxRegistrationID = "12S379BDF798", CustomerOrganizationID = "WRQ7987VRG79" }; CustomerInfoProvider.SetCustomerInfo(customerInfo); var userInfo = CustomerInfoProvider.RegisterCustomer(customerInfo, "", "alex"); var roleInfo = RoleInfoProvider.GetRoleInfo("SilverPartner", siteID); if (roleInfo != null) { UserInfoProvider.AddUserToRole(userInfo.UserID, roleInfo.RoleID); } for (var index = 0; index < 5; ++index) { var cart = new ShoppingCartInfo(); cart.ShoppingCartCulture = CultureHelper.GetDefaultCultureCode(siteName); cart.ShoppingCartCurrencyID = currencyInfo.CurrencyID; cart.ShoppingCartSiteID = siteID; cart.ShoppingCartCustomerID = customerInfo.CustomerID; cart.ShoppingCartBillingAddress = GenerateAddress(GetRandomCountryId(), customerInfo.CustomerID); cart.ShoppingCartShippingAddress = GenerateAddress(GetRandomCountryId(), customerInfo.CustomerID); cart.User = userInfo; ShoppingCartInfoProvider.SetShoppingCartInfo(cart); ShoppingCartInfoProvider.SetShoppingCartItem(cart, new ShoppingCartItemParameters(list3.ElementAt(rand.Next(list3.Count)).SKUID, rand.Next(5))); cart.Evaluate(); ShoppingCartInfoProvider.SetOrder(cart); } }
/// <summary> /// Sets data to database. /// </summary> protected void btnOK_Click(object sender, EventArgs e) { if (!ECommerceContext.IsUserAuthorizedToModifyCustomer()) { RedirectToAccessDenied("CMS.Ecommerce", "EcommerceModify OR ModifyCustomers"); } string errorMessage = ""; if ((txtCustomerCompany.Text == null || txtCustomerCompany.Text.Trim() == "") && ((txtCustomerFirstName.Text == null || txtCustomerFirstName.Text.Trim() == "") || (txtCustomerLastName.Text == null || txtCustomerLastName.Text.Trim() == ""))) { errorMessage = GetString("Customers_Edit.errorInsert"); } if (errorMessage == "") { if (this.chkCreateLogin.Checked) { errorMessage = new Validator().NotEmpty(txtUserName.Text.Trim(), GetString("Customer_Edit_Login_Edit.rqvUserName")) .NotEmpty(passStrength.Text.Trim(), GetString("Customer_Edit_Login_Edit.rqvPassword1")) .NotEmpty(txtPassword2.Text.Trim(), GetString("Customer_Edit_Login_Edit.rqvPassword2")).Result; // Check policy if ((errorMessage == "") && !passStrength.IsValid()) { errorMessage = UserInfoProvider.GetPolicyViolationMessage(CMSContext.CurrentSiteName); } // Compare passwords if ((errorMessage == "") && (passStrength.Text != txtPassword2.Text)) { errorMessage = GetString("Customer_Edit_Login_Edit.DifferentPasswords"); } } } if (errorMessage == "") { if (this.chkCreateLogin.Checked) { // If user already has the record in the CMS_User table UserInfo existingUser = UserInfoProvider.GetUserInfo(txtUserName.Text.Trim()); if (existingUser != null) { errorMessage = GetString("Customer_Edit_Login_Edit.UserExist"); } } } if (errorMessage == "") { CustomerInfo customerObj = CustomerInfoProvider.GetCustomerInfo(customerid); // If customer doesn't already exist, create new one if (customerObj == null) { customerObj = new CustomerInfo(); customerObj.CustomerSiteID = CMSContext.CurrentSiteID; } customerObj.CustomerLastName = txtCustomerLastName.Text.Trim(); customerObj.CustomerFirstName = txtCustomerFirstName.Text.Trim(); customerObj.CustomerCompany = txtCustomerCompany.Text.Trim(); customerObj.CustomerCountryID = drpCountry.CountryID; customerObj.CustomerStateID = drpCountry.StateID; customerObj.CustomerEnabled = true; //customerObj.CustomerCreated = ucCustomerCreated.SelectedDateTime; using (CMSTransactionScope tr = new CMSTransactionScope()) { CustomerInfoProvider.SetCustomerInfo(customerObj); // If create login checked if (this.chkCreateLogin.Checked) { UserInfo ui = new UserInfo(); ui.UserName = txtUserName.Text.Trim(); ui.FullName = customerObj.CustomerFirstName + " " + customerObj.CustomerLastName; ui.IsGlobalAdministrator = false; ui.SetValue("UserEnabled", true); UserInfoProvider.SetPassword(ui, passStrength.Text); // Add user to current site UserInfoProvider.AddUserToSite(ui.UserName, CMSContext.CurrentSiteName); customerObj.CustomerUserID = ui.UserID; CustomerInfoProvider.SetCustomerInfo(customerObj); } // Commit transaction tr.Commit(); } URLHelper.Redirect("Customer_Edit_Frameset.aspx?customerid=" + Convert.ToString(customerObj.CustomerID) + "&saved=1"); } else { lblError.Visible = true; lblError.Text = errorMessage; } }