public ActionResult AskQuestion(int id)
        {
            var product = _productService.GetProductById(id);

            if (product == null || product.Deleted || product.IsSystemProduct || !product.Published || !_catalogSettings.AskQuestionEnabled)
            {
                return(HttpNotFound());
            }

            var customer = _services.WorkContext.CurrentCustomer;

            var model = new ProductAskQuestionModel();

            model.Id                 = product.Id;
            model.ProductName        = product.GetLocalized(x => x.Name);
            model.ProductSeName      = product.GetSeName();
            model.SenderEmail        = customer.Email;
            model.SenderName         = customer.GetFullName();
            model.SenderNameRequired = _privacySettings.Value.FullNameOnProductRequestRequired;
            model.SenderPhone        = customer.GetAttribute <string>(SystemCustomerAttributeNames.Phone);
            model.Question           = T("Products.AskQuestion.Question.Text").Text.FormatCurrentUI(model.ProductName);
            model.DisplayCaptcha     = _captchaSettings.Enabled && _captchaSettings.ShowOnAskQuestionPage;

            return(View(model));
        }
        public virtual async Task <IActionResult> AskQuestionOnProduct(ProductAskQuestionSimpleModel model, bool captchaValid)
        {
            var product = await _productService.GetProductById(model.Id);

            if (product == null || !product.Published || !_catalogSettings.AskQuestionOnProduct)
            {
                return(Json(new
                {
                    success = false,
                    message = "Product not found"
                }));
            }

            // validate CAPTCHA
            if (_captchaSettings.Enabled && _captchaSettings.ShowOnAskQuestionPage && !captchaValid)
            {
                return(Json(new
                {
                    success = false,
                    message = _captchaSettings.GetWrongCaptchaMessage(_localizationService)
                }));
            }

            if (ModelState.IsValid)
            {
                var productaskqestionmodel = new ProductAskQuestionModel()
                {
                    Email    = model.AskQuestionEmail,
                    FullName = model.AskQuestionFullName,
                    Phone    = model.AskQuestionPhone,
                    Message  = model.AskQuestionMessage
                };

                // email
                await _mediator.Send(new SendProductAskQuestionMessageCommand()
                {
                    Customer = _workContext.CurrentCustomer,
                    Language = _workContext.WorkingLanguage,
                    Model    = productaskqestionmodel,
                    Product  = product
                });

                //activity log
                await _customerActivityService.InsertActivity("PublicStore.AskQuestion", _workContext.CurrentCustomer.Id, _localizationService.GetResource("ActivityLog.PublicStore.AskQuestion"));

                //return Json
                return(Json(new
                {
                    success = true,
                    message = _localizationService.GetResource("Products.AskQuestion.SuccessfullySent")
                }));
            }

            // If we got this far, something failed, redisplay form
            return(Json(new
            {
                success = false,
                message = string.Join(",", ModelState.Values.SelectMany(v => v.Errors).Select(x => x.ErrorMessage))
            }));
        }
Esempio n. 3
0
        ////[GrandHttpsRequirement(SslRequirement.No)]
        public virtual IActionResult AskQuestion(string productId)
        {
            var product = _productService.GetProductById(productId);

            if (product == null || !product.Published || !_catalogSettings.AskQuestionEnabled)
            {
                //return HttpNotFound();
                return(Content("HttpNotFound()"));
            }

            var customer = _workContext.CurrentCustomer;

            var model = new ProductAskQuestionModel();

            model.Id             = product.Id;
            model.ProductName    = product.GetLocalized(x => x.Name);
            model.ProductSeName  = product.GetSeName();
            model.Email          = customer.Email;
            model.FullName       = customer.GetFullName();
            model.Phone          = customer.GetAttribute <string>(SystemCustomerAttributeNames.Phone);
            model.Message        = "";
            model.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnAskQuestionPage;

            return(View(model));
        }
Esempio n. 4
0
        public ActionResult AskQuestion(int id)
        {
            var product = _productService.GetProductById(id);

            if (product == null || product.Deleted || product.IsSystemProduct || !product.Published || !_catalogSettings.AskQuestionEnabled)
            {
                return(HttpNotFound());
            }

            var attributesXml = "";

            if (TempData.TryGetValue("AskQuestionAttributesXml-" + id, out var obj))
            {
                attributesXml = obj as string;
            }

            // Check if saved attributeXml belongs to current product id
            var attributeInfo = "";

            if (attributesXml.HasValue())
            {
                attributeInfo = _productAttributeFormatter.FormatAttributes(
                    product,
                    attributesXml,
                    null,
                    separator: ", ",
                    renderPrices: false,
                    renderGiftCardAttributes: false,
                    allowHyperlinks: false);
            }

            var customer = _services.WorkContext.CurrentCustomer;
            var model    = new ProductAskQuestionModel
            {
                Id                 = product.Id,
                ProductName        = product.GetLocalized(x => x.Name),
                ProductSeName      = product.GetSeName(),
                SenderEmail        = customer.Email,
                SenderName         = customer.GetFullName(),
                SenderNameRequired = _privacySettings.Value.FullNameOnProductRequestRequired,
                SenderPhone        = customer.GetAttribute <string>(SystemCustomerAttributeNames.Phone),
                DisplayCaptcha     = _captchaSettings.CanDisplayCaptcha && _captchaSettings.ShowOnAskQuestionPage,
                SelectedAttributes = attributeInfo,
                ProductUrl         = _productUrlHelper.GetProductUrl(id, product.GetSeName(), attributesXml),
                IsQuoteRequest     = product.CallForPrice
            };

            var questionTitle = model.IsQuoteRequest
                ? T("Products.AskQuestion.Question.QuoteRequest")
                : T("Products.AskQuestion.Question.GeneralInquiry");

            model.Question = questionTitle.Text.FormatCurrentUI(model.ProductName);

            return(View(model));
        }
Esempio n. 5
0
        public ActionResult AskQuestionButton(int id)
        {
            if (!_catalogSettings.AskQuestionEnabled)
            {
                return(Content(""));
            }
            var model = new ProductAskQuestionModel()
            {
                Id = id
            };

            return(PartialView(model));
        }
Esempio n. 6
0
        public async Task <IActionResult> AskQuestionSend(ProductAskQuestionModel model, string captchaError)
        {
            if (!_catalogSettings.AskQuestionEnabled)
            {
                return(NotFound());
            }

            var product = await _db.Products.FindByIdAsync(model.Id, false);

            if (product == null || product.IsSystemProduct || !product.Published)
            {
                return(NotFound());
            }

            if (_captchaSettings.ShowOnAskQuestionPage && captchaError.HasValue())
            {
                ModelState.AddModelError("", captchaError);
            }

            if (ModelState.IsValid)
            {
                var msg = await _messageFactory.Value.SendProductQuestionMessageAsync(
                    Services.WorkContext.CurrentCustomer,
                    product,
                    model.SenderEmail,
                    model.SenderName,
                    model.SenderPhone,
                    HtmlUtils.ConvertPlainTextToHtml(model.Question.HtmlEncode()),
                    HtmlUtils.ConvertPlainTextToHtml(model.SelectedAttributes.HtmlEncode()),
                    model.ProductUrl,
                    model.IsQuoteRequest);

                if (msg?.Email?.Id != null)
                {
                    TempData.Remove("AskQuestionAttributeSelection-" + product.Id);

                    NotifySuccess(T("Products.AskQuestion.Sent"));
                    return(RedirectToRoute("Product", new { SeName = await product.GetActiveSlugAsync() }));
                }
                else
                {
                    ModelState.AddModelError("", T("Common.Error.SendMail"));
                }
            }

            // If we got this far something failed. Redisplay form.
            model = await PrepareAskQuestionModelAsync(product);

            return(View(model));
        }
Esempio n. 7
0
        public ActionResult AskQuestionSend(ProductAskQuestionModel model, string captchaError)
        {
            var product = _productService.GetProductById(model.Id);

            if (product == null || product.Deleted || product.IsSystemProduct || !product.Published || !_catalogSettings.AskQuestionEnabled)
            {
                return(HttpNotFound());
            }

            if (_captchaSettings.ShowOnAskQuestionPage && captchaError.HasValue())
            {
                ModelState.AddModelError("", captchaError);
            }

            model.ProductUrl = _services.StoreContext.CurrentStore.Url + model.ProductUrl.Substring(1);

            if (ModelState.IsValid)
            {
                var msg = Services.MessageFactory.SendProductQuestionMessage(
                    _services.WorkContext.CurrentCustomer,
                    product,
                    model.SenderEmail,
                    model.SenderName,
                    model.SenderPhone,
                    HtmlUtils.ConvertPlainTextToHtml(model.Question.HtmlEncode()),
                    HtmlUtils.ConvertPlainTextToHtml(model.SelectedAttributes.HtmlEncode()),
                    model.ProductUrl,
                    model.IsQuoteRequest);

                if (msg?.Email?.Id != null)
                {
                    NotifySuccess(T("Products.AskQuestion.Sent"), true);
                    return(RedirectToRoute("Product", new { SeName = product.GetSeName() }));
                }
                else
                {
                    ModelState.AddModelError("", T("Common.Error.SendMail"));
                }
            }

            // If we got this far, something failed, redisplay form.
            var customer = _services.WorkContext.CurrentCustomer;

            model.Id             = product.Id;
            model.ProductName    = product.GetLocalized(x => x.Name);
            model.ProductSeName  = product.GetSeName();
            model.DisplayCaptcha = _captchaSettings.CanDisplayCaptcha && _captchaSettings.ShowOnAskQuestionPage;

            return(View(model));
        }
Esempio n. 8
0
        public ActionResult AskQuestionSend(ProductAskQuestionModel model, bool captchaValid)
        {
            var product = _productService.GetProductById(model.Id);

            if (product == null || product.Deleted || !product.Published || !_catalogSettings.AskQuestionEnabled)
            {
                return(HttpNotFound());
            }

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

            if (ModelState.IsValid)
            {
                // email
                var result = _workflowMessageService.SendProductQuestionMessage(
                    _services.WorkContext.CurrentCustomer,
                    _services.WorkContext.WorkingLanguage.Id,
                    product,
                    model.SenderEmail,
                    model.SenderName,
                    model.SenderPhone,
                    Core.Html.HtmlUtils.FormatText(model.Question, false, true, false, false, false, false));

                if (result > 0)
                {
                    this.NotifySuccess(T("Products.AskQuestion.Sent"), true);
                    return(RedirectToRoute("Product", new { SeName = product.GetSeName() }));
                }
                else
                {
                    ModelState.AddModelError("", T("Common.Error.SendMail"));
                }
            }

            // If we got this far, something failed, redisplay form
            var customer = _services.WorkContext.CurrentCustomer;

            model.Id             = product.Id;
            model.ProductName    = product.GetLocalized(x => x.Name);
            model.ProductSeName  = product.GetSeName();
            model.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnAskQuestionPage;
            return(View(model));
        }
Esempio n. 9
0
        public virtual async Task <IActionResult> AskQuestion(ProductAskQuestionModel model, bool captchaValid)
        {
            var product = await _productService.GetProductById(model.ProductId);

            if (product == null || !product.Published || !_catalogSettings.AskQuestionEnabled)
            {
                return(NotFound());
            }

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

            if (ModelState.IsValid)
            {
                // email
                await _mediator.Send(new SendProductAskQuestionMessageCommand()
                {
                    Customer = _workContext.CurrentCustomer,
                    Language = _workContext.WorkingLanguage,
                    Store    = _storeContext.CurrentStore,
                    Model    = model,
                    Product  = product
                });

                //activity log
                await _customerActivityService.InsertActivity("PublicStore.AskQuestion", _workContext.CurrentCustomer.Id, _localizationService.GetResource("ActivityLog.PublicStore.AskQuestion"));

                model.SuccessfullySent = true;
                model.ProductSeName    = product.GetSeName(_workContext.WorkingLanguage.Id);
                model.ProductName      = product.GetLocalized(x => x.Name, _workContext.WorkingLanguage.Id);
                model.Result           = _localizationService.GetResource("Products.AskQuestion.SuccessfullySent");
                return(View(model));
            }

            // If we got this far, something failed, redisplay form
            var customer = _workContext.CurrentCustomer;

            model.Id             = product.Id;
            model.ProductName    = product.GetLocalized(x => x.Name, _workContext.WorkingLanguage.Id);
            model.ProductSeName  = product.GetSeName(_workContext.WorkingLanguage.Id);
            model.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnAskQuestionPage;
            return(View(model));
        }
Esempio n. 10
0
        private async Task <ProductAskQuestionModel> PrepareAskQuestionModelAsync(Product product)
        {
            var customer      = Services.WorkContext.CurrentCustomer;
            var rawAttributes = TempData.Peek("AskQuestionAttributeSelection-" + product.Id) as string;

            // Check if saved rawAttributes belongs to current product id
            var formattedAttributes = string.Empty;
            var selection           = new ProductVariantAttributeSelection(rawAttributes);

            if (selection.AttributesMap.Any())
            {
                formattedAttributes = await _productAttributeFormatter.Value.FormatAttributesAsync(
                    selection,
                    product,
                    customer : null,
                    separator : ", ",
                    includePrices : false,
                    includeGiftCardAttributes : false,
                    includeHyperlinks : false);
            }

            var seName = await product.GetActiveSlugAsync();

            var model = new ProductAskQuestionModel
            {
                Id                 = product.Id,
                ProductName        = product.GetLocalized(x => x.Name),
                ProductSeName      = seName,
                SenderEmail        = customer.Email,
                SenderName         = customer.GetFullName(),
                SenderNameRequired = _privacySettings.FullNameOnProductRequestRequired,
                SenderPhone        = customer.GenericAttributes.Phone,
                DisplayCaptcha     = _captchaSettings.CanDisplayCaptcha && _captchaSettings.ShowOnAskQuestionPage,
                SelectedAttributes = formattedAttributes,
                ProductUrl         = await _productUrlHelper.Value.GetProductUrlAsync(product.Id, seName, selection),
                IsQuoteRequest     = product.CallForPrice
            };

            model.Question = T("Products.AskQuestion.Question." + (model.IsQuoteRequest ? "QuoteRequest" : "GeneralInquiry"), model.ProductName);

            return(model);
        }
Esempio n. 11
0
        ////[PublicAntiForgery]
        ////[CaptchaValidator]
        public virtual IActionResult AskQuestion(ProductAskQuestionModel model, bool captchaValid)
        {
            var product = _productService.GetProductById(model.ProductId);

            if (product == null || !product.Published || !_catalogSettings.AskQuestionEnabled)
            {
                //return HttpNotFound();
                throw new Exception("ProductController > AskQuestion()");
            }

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

            if (ModelState.IsValid)
            {
                // email
                _productWebService.SendProductAskQuestionMessage(product, model);

                //activity log
                _customerActivityService.InsertActivity("PublicStore.AskQuestion", _workContext.CurrentCustomer.Id, _localizationService.GetResource("ActivityLog.PublicStore.AskQuestion"));

                model.SuccessfullySent = true;
                model.ProductSeName    = product.GetSeName();
                model.ProductName      = product.GetLocalized(x => x.Name);
                model.Result           = _localizationService.GetResource("Products.AskQuestion.SuccessfullySent");
                return(View(model));
            }

            // If we got this far, something failed, redisplay form
            var customer = _workContext.CurrentCustomer;

            model.Id             = product.Id;
            model.ProductName    = product.GetLocalized(x => x.Name);
            model.ProductSeName  = product.GetSeName();
            model.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnAskQuestionPage;
            return(View(model));
        }