public override ActionResult ApplyVendor() { if (!_vendorSettings.AllowCustomersToApplyForVendorAccount) { return(RedirectToRoute("HomePage")); } var model = new OneStepApplyVendorModel().ToApplyVendorModel(); model = _vendorModelFactory.PrepareApplyVendorModel(model, true, false); return(ViewApplyVendor(model)); }
private void SetCategories(OneStepApplyVendorModel model) { if (model.AvailableCategories.Count > 0) { return; } foreach (var c in _catalogModelFactory.PrepareCategorySimpleModels()) { model.AvailableCategories.Add(new SelectListItem { Text = c.Name, Value = c.Id.ToString(), Selected = false }); } }
private void SetContries(OneStepApplyVendorModel model) { if (model.AvailableCountries.Count > 0) { return; } 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 }); } }
public ActionResult OneStepApplyVendorSubmit(OneStepApplyVendorModel model, bool captchaValid, HttpPostedFileBase uploadedFile) { if (!_vendorSettings.AllowCustomersToApplyForVendorAccount) { return(RedirectToRoute("HomePage")); } //validate CAPTCHA if (_captchaSettings.Enabled && _captchaSettings.ShowOnApplyVendorPage && !captchaValid) { ModelState.AddModelError("", _captchaSettings.GetWrongCaptchaMessage(_localizationService)); } if (!_workContext.CurrentCustomer.IsRegistered()) { //TODO: validate and create Customer } var applyVendorModel = model.ToApplyVendorModel(); if (ModelState.IsValid) { var sbDescription = new StringBuilder(); sbDescription.AppendFormat("{0}: {1} \n<br>", GetFieldDisplayName(nameof(OneStepApplyVendorModel.Company)), model.Company); sbDescription.AppendFormat("{0}: {1} \n<br>", GetFieldDisplayName(nameof(OneStepApplyVendorModel.CountryId)), GetCountryName(model.CountryId)); sbDescription.AppendFormat("{0}: {1} \n<br>", GetFieldDisplayName(nameof(OneStepApplyVendorModel.Phone)), model.Phone); sbDescription.AppendFormat("{0}: {1} \n<br>", GetFieldDisplayName(nameof(OneStepApplyVendorModel.Mail)), model.Mail); sbDescription.AppendFormat("{0}: {1} \n<br>", GetFieldDisplayName(nameof(OneStepApplyVendorModel.FirstName)), model.FirstName); sbDescription.AppendFormat("{0}: {1} \n<br>", GetFieldDisplayName(nameof(OneStepApplyVendorModel.LastName)), model.LastName); sbDescription.AppendFormat("{0}: {1} \n<br>", GetFieldDisplayName(nameof(OneStepApplyVendorModel.WebSite)), model.WebSite); sbDescription.AppendFormat("{0}: {1} \n<br>", GetFieldDisplayName(nameof(OneStepApplyVendorModel.Categories)), GetCategoriesNames(model.Categories)); sbDescription.AppendFormat("{0}: {1} \n<br>", GetFieldDisplayName(nameof(OneStepApplyVendorModel.Brands)), model.Brands); sbDescription.AppendFormat("{0}: {1} \n<br>", GetFieldDisplayName(nameof(OneStepApplyVendorModel.AdditionalInfo)), model.AdditionalInfo); var description = Core.Html.HtmlHelper.FormatText(sbDescription.ToString(), false, false, true, false, false, false); //disabled by default var vendor = new Vendor { Name = applyVendorModel.Name, Email = applyVendorModel.Email, //some default settings PageSize = 6, AllowCustomersToSelectPageSize = true, PageSizeOptions = _vendorSettings.DefaultVendorPageSizeOptions, PictureId = 0, Description = description // TODO: add custom fields }; _vendorService.InsertVendor(vendor); //search engine name (the same as vendor name) var seName = vendor.ValidateSeName(vendor.Name, vendor.Name, true); _urlRecordService.SaveSlug(vendor, seName, 0); if (_workContext.CurrentCustomer.IsRegistered()) { //associate to the current customer //but a store owner will have to manually add this customer role to "Vendors" role //if he wants to grant access to admin area _workContext.CurrentCustomer.VendorId = vendor.Id; _customerService.UpdateCustomer(_workContext.CurrentCustomer); } //notify store owner here (email) _workflowMessageService.SendNewVendorAccountApplyStoreOwnerNotification(_workContext.CurrentCustomer, vendor, _localizationSettings.DefaultAdminLanguageId); applyVendorModel.DisableFormInput = true; applyVendorModel.Result = _localizationService.GetResource("Vendors.ApplyAccount.Submitted"); return(ViewApplyVendor(applyVendorModel)); } //If we got this far, something failed, redisplay form applyVendorModel = _vendorModelFactory.PrepareApplyVendorModel(applyVendorModel, false, true); return(ViewApplyVendor(applyVendorModel)); }
/// <summary> /// Maps OneStepApplyVendorModel to ApplyVendorModel /// </summary> public static ApplyVendorModel ToApplyVendorModel(this OneStepApplyVendorModel model) { return(model.CopyApplyVendorModel <OneStepApplyVendorModel, ApplyVendorModel>()); }