public void Should_have_error_when_yourEmailAddress_is_null_or_empty()
 {
     var model = new ProductEmailAFriendModel();
     model.YourEmailAddress = null;
     _validator.ShouldHaveValidationErrorFor(x => x.YourEmailAddress, model);
     model.YourEmailAddress = "";
     _validator.ShouldHaveValidationErrorFor(x => x.YourEmailAddress, model);
 }
 public void Should_have_error_when_friendEmail_is_null_or_empty()
 {
     var model = new ProductEmailAFriendModel();
     model.FriendEmail = null;
     _validator.ShouldHaveValidationErrorFor(x => x.FriendEmail, model);
     model.FriendEmail = "";
     _validator.ShouldHaveValidationErrorFor(x => x.FriendEmail, model);
 }
 public void Should_not_have_error_when_yourEmailAddress_is_correct_format()
 {
     var model = new ProductEmailAFriendModel();
     model.YourEmailAddress = "*****@*****.**";
     _validator.ShouldNotHaveValidationErrorFor(x => x.YourEmailAddress, model);
 }
 public void Should_have_error_when_friendEmail_is_wrong_format()
 {
     var model = new ProductEmailAFriendModel();
     model.FriendEmail = "adminexample.com";
     _validator.ShouldHaveValidationErrorFor(x => x.FriendEmail, model);
 }
예제 #5
0
        public ActionResult ProductEmailAFriendSend(ProductEmailAFriendModel model, bool captchaValid)
        {
            var product = _productService.GetProductById(model.ProductId);
            if (product == null || product.Deleted || !product.Published || !_catalogSettings.EmailAFriendEnabled)
                return RedirectToRoute("HomePage");

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

            //check whether the current customer is guest and ia allowed to email a friend
            if (_workContext.CurrentCustomer.IsGuest() && !_catalogSettings.AllowAnonymousUsersToEmailAFriend)
            {
                ModelState.AddModelError("", _localizationService.GetResource("Products.EmailAFriend.OnlyRegisteredUsers"));
            }

            if (ModelState.IsValid)
            {
                //email
                _workflowMessageService.SendProductEmailAFriendMessage(_workContext.CurrentCustomer,
                        _workContext.WorkingLanguage.Id, product,
                        model.YourEmailAddress, model.FriendEmail,
                        Core.Html.HtmlHelper.FormatText(model.PersonalMessage, false, true, false, false, false, false));

                model.ProductId = product.Id;
                model.ProductName = product.GetLocalized(x => x.Name);
                model.ProductSeName = product.GetSeName();

                model.SuccessfullySent = true;
                model.Result = _localizationService.GetResource("Products.EmailAFriend.SuccessfullySent");

                return View(model);
            }

            //If we got this far, something failed, redisplay form
            model.ProductId = product.Id;
            model.ProductName = product.GetLocalized(x => x.Name);
            model.ProductSeName = product.GetSeName();
            model.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnEmailProductToFriendPage;
            return View(model);
        }
예제 #6
0
        public ActionResult ProductEmailAFriendButton(int productId)
        {
            if (!_catalogSettings.EmailAFriendEnabled)
                return Content("");
            var model = new ProductEmailAFriendModel()
            {
                ProductId = productId
            };

            return PartialView("ProductEmailAFriendButton", model);
        }
예제 #7
0
        public ActionResult ProductEmailAFriend(int productId)
        {
            var product = _productService.GetProductById(productId);
            if (product == null || product.Deleted || !product.Published || !_catalogSettings.EmailAFriendEnabled)
                return RedirectToRoute("HomePage");

            var model = new ProductEmailAFriendModel();
            model.ProductId = product.Id;
            model.ProductName = product.GetLocalized(x => x.Name);
            model.ProductSeName = product.GetSeName();
            model.YourEmailAddress = _workContext.CurrentCustomer.Email;
            model.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnEmailProductToFriendPage;
            return View(model);
        }