Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Send.php
Go to the documentation of this file.
1 <?php
7 
9 
11 {
15  protected $catalogSession;
16 
25  public function __construct(
26  \Magento\Framework\App\Action\Context $context,
27  \Magento\Framework\Registry $coreRegistry,
28  \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator,
29  \Magento\SendFriend\Model\SendFriend $sendFriend,
30  \Magento\Catalog\Api\ProductRepositoryInterface $productRepository,
31  \Magento\Catalog\Model\Session $catalogSession
32  ) {
33  $this->catalogSession = $catalogSession;
34  parent::__construct(
35  $context,
36  $coreRegistry,
37  $formKeyValidator,
40  );
41  }
42 
48  public function execute()
49  {
50  $product = $this->_initProduct();
51 
52  if (!$product) {
54  $resultForward = $this->resultFactory->create(ResultFactory::TYPE_FORWARD);
55  $resultForward->forward('noroute');
56  return $resultForward;
57  }
58 
59  if ($this->sendFriend->getMaxSendsToFriend() && $this->sendFriend->isExceedLimit()) {
60  $this->messageManager->addNotice(
61  __('You can\'t send messages more than %1 times an hour.', $this->sendFriend->getMaxSendsToFriend())
62  );
63  }
64 
66  $resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
67 
68  $this->_eventManager->dispatch('sendfriend_product', ['product' => $product]);
69  $data = $this->catalogSession->getSendfriendFormData();
70  if ($data) {
71  $this->catalogSession->setSendfriendFormData(true);
72  $block = $resultPage->getLayout()->getBlock('sendfriend.send');
73  if ($block) {
75  $block->setFormData($data);
76  }
77  }
78 
79  return $resultPage;
80  }
81 }
__()
Definition: __.php:13
$block
Definition: block.php:8
__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\Model\Session $catalogSession)
Definition: Send.php:25