예제 #1
0
        public ActionResult ApplyVendor()
        {
            if (!_vendorSettings.AllowCustomersToApplyForVendorAccount)
            {
                return(RedirectToRoute("HomePage"));
            }

            if (!_workContext.CurrentCustomer.IsRegistered())
            {
                return(new HttpUnauthorizedResult());
            }

            var model = new ApplyVendorModel();

            if (_workContext.CurrentCustomer.VendorId > 0)
            {
                //already applied for vendor account
                model.DisableFormInput = true;
                model.Result           = _localizationService.GetResource("Vendors.ApplyAccount.AlreadyApplied");
                return(View(model));
            }

            model.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnApplyVendorPage;
            model.Email          = _workContext.CurrentCustomer.Email;
            return(View(model));
        }
예제 #2
0
        /// <summary>
        /// Prepare the apply vendor model
        /// </summary>
        /// <param name="model">The apply vendor model</param>
        /// <param name="validateVendor">Whether to validate that the customer is already a vendor</param>
        /// <param name="excludeProperties">Whether to exclude populating of model properties from the entity</param>
        /// <param name="vendorAttributesXml">Vendor attributes in XML format</param>
        /// <returns>The apply vendor model</returns>
        public virtual async Task <ApplyVendorModel> PrepareApplyVendorModelAsync(ApplyVendorModel model,
                                                                                  bool validateVendor, bool excludeProperties, string vendorAttributesXml)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            if (validateVendor && (await _workContext.GetCurrentCustomerAsync()).VendorId > 0)
            {
                //already applied for vendor account
                model.DisableFormInput = true;
                model.Result           = await _localizationService.GetResourceAsync("Vendors.ApplyAccount.AlreadyApplied");
            }

            model.DisplayCaptcha        = _captchaSettings.Enabled && _captchaSettings.ShowOnApplyVendorPage;
            model.TermsOfServiceEnabled = _vendorSettings.TermsOfServiceEnabled;
            model.TermsOfServicePopup   = _commonSettings.PopupForTermsOfServiceLinks;

            if (!excludeProperties)
            {
                model.Email = (await _workContext.GetCurrentCustomerAsync()).Email;
            }

            //vendor attributes
            model.VendorAttributes = await PrepareVendorAttributesAsync(vendorAttributesXml);

            return(model);
        }
예제 #3
0
        /// <summary>
        /// Prepare the apply vendor model
        /// </summary>
        /// <param name="model">The apply vendor model</param>
        /// <param name="validateVendor">Whether to validate that the customer is already a vendor</param>
        /// <param name="excludeProperties">Whether to exclude populating of model properties from the entity</param>
        /// <returns>The apply vendor model</returns>
        public virtual ApplyVendorModel PrepareApplyVendorModel(ApplyVendorModel model, bool validateVendor, bool excludeProperties)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            if (validateVendor && _workContext.CurrentCustomer.VendorId > 0)
            {
                //already applied for vendor account
                model.DisableFormInput = true;
                model.Result           = _localizationService.GetResource("Vendors.ApplyAccount.AlreadyApplied");
            }

            model.DisplayCaptcha        = _captchaSettings.Enabled && _captchaSettings.ShowOnApplyVendorPage;
            model.TermsOfServiceEnabled = _vendorSettings.TermsOfServiceEnabled;
            model.TermsOfServicePopup   = _commonSettings.PopupForTermsOfServiceLinks;

            if (!excludeProperties)
            {
                model.Email = _workContext.CurrentCustomer.Email;
            }

            return(model);
        }
        private ActionResult ViewApplyVendor(ApplyVendorModel applyVendorModel)
        {
            var model = applyVendorModel.ToOneStepApplyVendorModel();

            SetContries(model);
            SetCategories(model);
            return(View("OneStepApplyVendor", model));
        }
예제 #5
0
        public ActionResult ApplyVendorSubmit(ApplyVendorModel model, bool captchaValid)
        {
            if (!_vendorSettings.AllowCustomersToApplyForVendorAccount)
            {
                return(RedirectToRoute("HomePage"));
            }

            if (!_workContext.CurrentCustomer.IsRegistered())
            {
                return(new HttpUnauthorizedResult());
            }

            //validate CAPTCHA
            if (_captchaSettings.Enabled && _captchaSettings.ShowOnApplyVendorPage && !captchaValid)
            {
                ModelState.AddModelError("", _localizationService.GetResource("Common.WrongCaptcha"));
            }

            if (ModelState.IsValid)
            {
                //disabled by default
                var vendor = new Vendor
                {
                    Name  = model.Name,
                    Email = model.Email,
                    //some default settings
                    PageSize = 6,
                    AllowCustomersToSelectPageSize = true,
                    PageSizeOptions = _vendorSettings.DefaultVendorPageSizeOptions
                };
                _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);

                //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);

                model.DisableFormInput = true;
                model.Result           = _localizationService.GetResource("Vendors.ApplyAccount.Submitted");
                return(View(model));
            }

            //If we got this far, something failed, redisplay form
            model.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnApplyVendorPage;
            return(View(model));
        }
예제 #6
0
        public virtual IActionResult ApplyVendor()
        {
            if (!_vendorSettings.AllowCustomersToApplyForVendorAccount)
            {
                return(RedirectToRoute("HomePage"));
            }

            if (!_workContext.CurrentCustomer.IsRegistered())
            {
                return(Challenge());
            }

            var model = new ApplyVendorModel();

            model = _vendorModelFactory.PrepareApplyVendorModel(model, true, false, null);
            return(View(model));
        }
        /// <summary>
        /// Prepare the apply vendor model
        /// </summary>
        /// <param name="model">The apply vendor model</param>
        /// <param name="validateVendor">Whether to validate that the customer is already a vendor</param>
        /// <param name="excludeProperties">Whether to exclude populating of model properties from the entity</param>
        /// <returns>The apply vendor model</returns>
        public virtual ApplyVendorModel PrepareApplyVendorModel(ApplyVendorModel model, bool validateVendor, bool excludeProperties)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }
            model.DisplayCaptcha        = _captchaSettings.Enabled && _captchaSettings.ShowOnApplyVendorPage;
            model.TermsOfServiceEnabled = _vendorSettings.TermsOfServiceEnabled;
            model.TermsOfServicePopup   = _commonSettings.PopupForTermsOfServiceLinks;

            if (!excludeProperties)
            {
                model.Email = _workContext.CurrentCustomer.Email;
            }

            return(model);
        }
예제 #8
0
        /// <returns>A task that represents the asynchronous operation</returns>
        public virtual async Task <IActionResult> ApplyVendor()
        {
            if (!_vendorSettings.AllowCustomersToApplyForVendorAccount)
            {
                return(RedirectToRoute("Homepage"));
            }

            if (!await _customerService.IsRegisteredAsync(await _workContext.GetCurrentCustomerAsync()))
            {
                return(Challenge());
            }

            var model = new ApplyVendorModel();

            model = await _vendorModelFactory.PrepareApplyVendorModelAsync(model, true, false, null);

            return(View(model));
        }
예제 #9
0
        public virtual async Task <IActionResult> ApplyVendor()
        {
            if (!_vendorSettings.AllowCustomersToApplyForVendorAccount)
            {
                return(RedirectToRoute("HomePage"));
            }

            if (!_workContext.CurrentCustomer.IsRegistered())
            {
                return(Challenge());
            }

            var model = new ApplyVendorModel();

            if (!String.IsNullOrEmpty(_workContext.CurrentCustomer.VendorId))
            {
                //already applied for vendor account
                model.DisableFormInput = true;
                model.Result           = _localizationService.GetResource("Vendors.ApplyAccount.AlreadyApplied");
                return(View(model));
            }

            model.DisplayCaptcha        = _captchaSettings.Enabled && _captchaSettings.ShowOnApplyVendorPage;
            model.Email                 = _workContext.CurrentCustomer.Email;
            model.TermsOfServiceEnabled = _vendorSettings.TermsOfServiceEnabled;
            model.TermsOfServicePopup   = _commonSettings.PopupForTermsOfServiceLinks;
            var countries = await _countryService.GetAllCountries(_workContext.WorkingLanguage.Id);

            model.Address = await _mediator.Send(new GetVendorAddress()
            {
                Language                      = _workContext.WorkingLanguage,
                Address                       = null,
                ExcludeProperties             = false,
                PrePopulateWithCustomerFields = true,
                Customer                      = _workContext.CurrentCustomer,
                LoadCountries                 = () => countries,
            });

            return(View(model));
        }
        public virtual IActionResult ApplyVendor()
        {
            if (!_vendorSettings.AllowCustomersToApplyForVendorAccount)
            {
                return(RedirectToRoute("HomePage"));
            }

            if (!_workContext.CurrentCustomer.IsRegistered())
            {
                return(Challenge());
            }

            var model = new ApplyVendorModel();

            if (!String.IsNullOrEmpty(_workContext.CurrentCustomer.VendorId))
            {
                //already applied for vendor account
                model.DisableFormInput = true;
                model.Result           = _localizationService.GetResource("Vendors.ApplyAccount.AlreadyApplied");
                return(View(model));
            }

            model.DisplayCaptcha        = _captchaSettings.Enabled && _captchaSettings.ShowOnApplyVendorPage;
            model.Email                 = _workContext.CurrentCustomer.Email;
            model.TermsOfServiceEnabled = _vendorSettings.TermsOfServiceEnabled;
            model.TermsOfServicePopup   = _commonSettings.PopupForTermsOfServiceLinks;

            _addressViewModelService.PrepareVendorAddressModel(model: model.Address,
                                                               address: null,
                                                               excludeProperties: false,
                                                               prePopulateWithCustomerFields: true,
                                                               customer: _workContext.CurrentCustomer,
                                                               loadCountries: () => _countryService.GetAllCountries(_workContext.WorkingLanguage.Id),
                                                               vendorSettings: _vendorSettings);

            return(View(model));
        }
예제 #11
0
        public virtual async Task <IActionResult> ApplyVendorSubmit(ApplyVendorModel model, bool captchaValid, IFormFile uploadedFile)
        {
            if (!_vendorSettings.AllowCustomersToApplyForVendorAccount)
            {
                return(RedirectToRoute("HomePage"));
            }

            if (!_workContext.CurrentCustomer.IsRegistered())
            {
                return(Challenge());
            }

            //validate CAPTCHA
            if (_captchaSettings.Enabled && _captchaSettings.ShowOnApplyVendorPage && !captchaValid)
            {
                ModelState.AddModelError("", _captchaSettings.GetWrongCaptchaMessage(_localizationService));
            }

            string pictureId   = string.Empty;
            string contentType = string.Empty;

            byte[] vendorPictureBinary = null;

            if (uploadedFile != null && !string.IsNullOrEmpty(uploadedFile.FileName))
            {
                try
                {
                    contentType = uploadedFile.ContentType;
                    if (string.IsNullOrEmpty(contentType))
                    {
                        ModelState.AddModelError("", "Empty content type");
                    }
                    else
                    if (!contentType.StartsWith("image"))
                    {
                        ModelState.AddModelError("", "Only image content type is allowed");
                    }

                    vendorPictureBinary = uploadedFile.GetPictureBits();
                }
                catch (Exception)
                {
                    ModelState.AddModelError("", _localizationService.GetResource("Vendors.ApplyAccount.Picture.ErrorMessage"));
                }
            }

            if (ModelState.IsValid)
            {
                if (vendorPictureBinary != null && !string.IsNullOrEmpty(contentType))
                {
                    var picture = await _pictureService.InsertPicture(vendorPictureBinary, contentType, null);

                    if (picture != null)
                    {
                        pictureId = picture.Id;
                    }
                }

                var description = Core.Html.HtmlHelper.FormatText(model.Description, false, false, true, false, false, false);
                var address     = new Address();
                //disabled by default
                var vendor = new Vendor {
                    Name        = model.Name,
                    Email       = model.Email,
                    Description = description,
                    PageSize    = 6,
                    PictureId   = pictureId,
                    AllowCustomersToSelectPageSize = true,
                    PageSizeOptions      = _vendorSettings.DefaultVendorPageSizeOptions,
                    AllowCustomerReviews = _vendorSettings.DefaultAllowCustomerReview,
                };
                model.Address.ToEntity(vendor.Address, true);
                await _vendorService.InsertVendor(vendor);

                //search engine name (the same as vendor name)
                var seName = await vendor.ValidateSeName(vendor.Name, vendor.Name, true, HttpContext.RequestServices.GetRequiredService <SeoSettings>(),
                                                         HttpContext.RequestServices.GetRequiredService <IUrlRecordService>(), HttpContext.RequestServices.GetRequiredService <ILanguageService>());

                await _urlRecordService.SaveSlug(vendor, seName, "");

                //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;
                await _customerService.UpdateCustomerVendor(_workContext.CurrentCustomer);

                //notify store owner here (email)
                await _workflowMessageService.SendNewVendorAccountApplyStoreOwnerNotification(_workContext.CurrentCustomer,
                                                                                              vendor, _storeContext.CurrentStore, _localizationSettings.DefaultAdminLanguageId);

                model.DisableFormInput = true;
                model.Result           = _localizationService.GetResource("Vendors.ApplyAccount.Submitted");
                return(View(model));
            }

            //If we got this far, something failed, redisplay form
            model.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnApplyVendorPage;
            var countries = await _countryService.GetAllCountries(_workContext.WorkingLanguage.Id);

            model.Address = await _mediator.Send(new GetVendorAddress()
            {
                Language                      = _workContext.WorkingLanguage,
                Address                       = null,
                Model                         = model.Address,
                ExcludeProperties             = false,
                PrePopulateWithCustomerFields = true,
                Customer                      = _workContext.CurrentCustomer,
                LoadCountries                 = () => countries,
            });

            return(View(model));
        }
예제 #12
0
        public virtual IActionResult ApplyVendorSubmit(ApplyVendorModel model, bool captchaValid, IFormFile uploadedFile)
        {
            if (!_vendorSettings.AllowCustomersToApplyForVendorAccount)
            {
                return(RedirectToRoute("HomePage"));
            }

            if (!_workContext.CurrentCustomer.IsRegistered())
            {
                return(Challenge());
            }

            //validate CAPTCHA
            if (_captchaSettings.Enabled && _captchaSettings.ShowOnApplyVendorPage && !captchaValid)
            {
                ModelState.AddModelError("", _captchaSettings.GetWrongCaptchaMessage(_localizationService));
            }

            var pictureId = 0;

            if (uploadedFile != null && !string.IsNullOrEmpty(uploadedFile.FileName))
            {
                try
                {
                    var contentType         = uploadedFile.ContentType;
                    var vendorPictureBinary = _downloadService.GetDownloadBits(uploadedFile);
                    var picture             = _pictureService.InsertPicture(vendorPictureBinary, contentType, null);

                    if (picture != null)
                    {
                        pictureId = picture.Id;
                    }
                }
                catch (Exception)
                {
                    ModelState.AddModelError("", _localizationService.GetResource("Vendors.ApplyAccount.Picture.ErrorMessage"));
                }
            }

            //vendor attributes
            var vendorAttributesXml = ParseVendorAttributes(model.Form);

            _vendorAttributeParser.GetAttributeWarnings(vendorAttributesXml).ToList()
            .ForEach(warning => ModelState.AddModelError(string.Empty, warning));

            if (ModelState.IsValid)
            {
                var description = Core.Html.HtmlHelper.FormatText(model.Description, false, false, true, false, false, false);
                //disabled by default
                var vendor = new Vendor
                {
                    Name  = model.Name,
                    Email = model.Email,
                    //some default settings
                    PageSize = 6,
                    AllowCustomersToSelectPageSize = true,
                    PageSizeOptions = _vendorSettings.DefaultVendorPageSizeOptions,
                    PictureId       = pictureId,
                    Description     = description
                };
                _vendorService.InsertVendor(vendor);
                //search engine name (the same as vendor name)
                var seName = _urlRecordService.ValidateSeName(vendor, vendor.Name, vendor.Name, true);
                _urlRecordService.SaveSlug(vendor, seName, 0);

                //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);

                //update picture seo file name
                UpdatePictureSeoNames(vendor);

                //save vendor attributes
                _genericAttributeService.SaveAttribute(vendor, GSVendorDefaults.VendorAttributes, vendorAttributesXml);

                //notify store owner here (email)
                _workflowMessageService.SendNewVendorAccountApplyStoreOwnerNotification(_workContext.CurrentCustomer,
                                                                                        vendor, _localizationSettings.DefaultAdminLanguageId);

                model.DisableFormInput = true;
                model.Result           = _localizationService.GetResource("Vendors.ApplyAccount.Submitted");
                return(View(model));
            }

            //If we got this far, something failed, redisplay form
            model = _vendorModelFactory.PrepareApplyVendorModel(model, false, true, vendorAttributesXml);
            return(View(model));
        }
        public virtual IActionResult ApplyVendorSubmit(ApplyVendorModel model, bool captchaValid, IFormFile uploadedFile)
        {
            if (!_vendorSettings.AllowCustomersToApplyForVendorAccount)
            {
                return(RedirectToRoute("HomePage"));
            }

            if (!_workContext.CurrentCustomer.IsRegistered())
            {
                return(Challenge());
            }

            //validate CAPTCHA
            if (_captchaSettings.Enabled && _captchaSettings.ShowOnApplyVendorPage && !captchaValid)
            {
                ModelState.AddModelError("", _captchaSettings.GetWrongCaptchaMessage(_localizationService));
            }

            string pictureId = "";

            if (uploadedFile != null && !string.IsNullOrEmpty(uploadedFile.FileName))
            {
                try
                {
                    var contentType         = uploadedFile.ContentType;
                    var vendorPictureBinary = uploadedFile.GetPictureBits();
                    var picture             = _pictureService.InsertPicture(vendorPictureBinary, contentType, null);

                    if (picture != null)
                    {
                        pictureId = picture.Id;
                    }
                }
                catch (Exception)
                {
                    ModelState.AddModelError("", _localizationService.GetResource("Vendors.ApplyAccount.Picture.ErrorMessage"));
                }
            }

            if (ModelState.IsValid)
            {
                var description = Core.Html.HtmlHelper.FormatText(model.Description, false, false, true, false, false, false);
                var address     = new Address();
                //disabled by default
                var vendor = new Vendor
                {
                    Name        = model.Name,
                    Email       = model.Email,
                    Description = description,
                    PageSize    = 6,
                    PictureId   = pictureId,
                    AllowCustomersToSelectPageSize = true,
                    PageSizeOptions      = _vendorSettings.DefaultVendorPageSizeOptions,
                    AllowCustomerReviews = _vendorSettings.DefaultAllowCustomerReview,
                };
                model.Address.ToEntity(vendor.Address, true);
                _vendorService.InsertVendor(vendor);
                //search engine name (the same as vendor name)
                var seName = vendor.ValidateSeName(vendor.Name, vendor.Name, true);
                _urlRecordService.SaveSlug(vendor, seName, "");

                //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.UpdateCustomerVendor(_workContext.CurrentCustomer);

                //notify store owner here (email)
                _workflowMessageService.SendNewVendorAccountApplyStoreOwnerNotification(_workContext.CurrentCustomer,
                                                                                        vendor, _localizationSettings.DefaultAdminLanguageId);

                model.DisableFormInput = true;
                model.Result           = _localizationService.GetResource("Vendors.ApplyAccount.Submitted");
                return(View(model));
            }

            //If we got this far, something failed, redisplay form
            model.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnApplyVendorPage;

            _addressViewModelService.PrepareVendorAddressModel(model: model.Address,
                                                               address: null,
                                                               excludeProperties: false,
                                                               prePopulateWithCustomerFields: true,
                                                               customer: _workContext.CurrentCustomer,
                                                               loadCountries: () => _countryService.GetAllCountries(_workContext.WorkingLanguage.Id),
                                                               vendorSettings: _vendorSettings);

            return(View(model));
        }
 public override ActionResult ApplyVendorSubmit(ApplyVendorModel model, bool captchaValid, HttpPostedFileBase uploadedFile)
 {
     return(base.ApplyVendorSubmit(model, captchaValid, uploadedFile));
 }
예제 #15
0
 /// <summary>
 /// Maps ApplyVendorModel to OneStepApplyVendorModel
 /// </summary>
 public static OneStepApplyVendorModel ToOneStepApplyVendorModel(this ApplyVendorModel model)
 {
     return(model.CopyApplyVendorModel <ApplyVendorModel, OneStepApplyVendorModel>());
 }