35 \
Magento\Framework\Registry $coreRegistry,
56 $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
58 if (!$this->_formKeyValidator->validate($this->getRequest())) {
59 $resultRedirect->setPath(
'sendfriend/product/send', [
'_current' =>
true]);
60 return $resultRedirect;
68 $resultForward = $this->resultFactory->create(ResultFactory::TYPE_FORWARD);
69 $resultForward->forward(
'noroute');
70 return $resultForward;
73 $categoryId = $this->
getRequest()->getParam(
'cat_id',
null);
76 $category = $this->categoryRepository->get($categoryId);
77 }
catch (NoSuchEntityException $noEntityException) {
82 $this->_coreRegistry->register(
'current_category',
$category);
86 $this->sendFriend->setSender($this->
getRequest()->getPost(
'sender'));
87 $this->sendFriend->setRecipients($this->
getRequest()->getPost(
'recipients'));
88 $this->sendFriend->setProduct(
$product);
91 $validate = $this->sendFriend->validate();
92 if ($validate ===
true) {
93 $this->sendFriend->send();
94 $this->messageManager->addSuccess(
__(
'The link to a friend was sent.'));
97 return $resultRedirect;
99 if (is_array($validate)) {
100 foreach ($validate as $errorMessage) {
101 $this->messageManager->addError($errorMessage);
104 $this->messageManager->addError(
__(
'We found some problems with the data.'));
107 }
catch (\
Magento\Framework\Exception\LocalizedException $e) {
108 $this->messageManager->addError($e->getMessage());
109 }
catch (\Exception $e) {
110 $this->messageManager->addException($e,
__(
'Some emails were not sent.'));
114 $this->catalogSession->setSendfriendFormData(
$data);
116 $url = $this->_url->getUrl(
'sendfriend/product/send', [
'_current' =>
true]);
118 return $resultRedirect;
_redirect($path, $arguments=[])
__construct(\Magento\Framework\App\Action\Context $context, \Magento\Framework\Registry $coreRegistry, \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator, \Magento\SendFriend\Model\SendFriend $sendFriend, \Magento\Catalog\Api\ProductRepositoryInterface $productRepository, \Magento\Catalog\Api\CategoryRepositoryInterface $categoryRepository, \Magento\Catalog\Model\Session $catalogSession)