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 
18 {
24  protected $_sendfriendData = null;
25 
31  protected $_coreRegistry = null;
32 
36  protected $_customerSession;
37 
41  protected $httpContext;
42 
47 
51  protected $sendfriend;
52 
63  public function __construct(
64  \Magento\Framework\View\Element\Template\Context $context,
65  \Magento\Customer\Model\Session $customerSession,
66  \Magento\SendFriend\Helper\Data $sendfriendData,
67  \Magento\Framework\Registry $registry,
68  \Magento\Customer\Helper\View $customerViewHelper,
69  \Magento\Framework\App\Http\Context $httpContext,
70  \Magento\SendFriend\Model\SendFriend $sendfriend,
71  array $data = []
72  ) {
73  $this->_customerSession = $customerSession;
74  $this->_coreRegistry = $registry;
75  $this->_sendfriendData = $sendfriendData;
76  $this->sendfriend = $sendfriend;
77  parent::__construct($context, $data);
78  $this->_isScopePrivate = true;
79  $this->httpContext = $httpContext;
80  $this->_customerViewHelper = $customerViewHelper;
81  }
82 
88  public function getUserName()
89  {
90  $name = $this->getFormData()->getData('sender/name');
91  if (!empty($name)) {
92  return trim($name);
93  }
94 
95  /* @var $session \Magento\Customer\Model\Session */
97 
98  if ($this->httpContext->getValue(Context::CONTEXT_AUTH)) {
99  return $this->_customerViewHelper->getCustomerName(
100  $session->getCustomerDataObject()
101  );
102  }
103 
104  return '';
105  }
106 
112  public function getEmail()
113  {
114  $email = $this->getFormData()->getData('sender/email');
115  if (!empty($email)) {
116  return trim($email);
117  }
118 
119  /* @var $session \Magento\Customer\Model\Session */
121 
122  if ($this->httpContext->getValue(Context::CONTEXT_AUTH)) {
123  return $session->getCustomerDataObject()->getEmail();
124  }
125 
126  return '';
127  }
128 
134  public function getMessage()
135  {
136  return $this->getFormData()->getData('sender/message');
137  }
138 
144  public function getFormData()
145  {
146  $data = $this->getData('form_data');
147  if (!$data instanceof \Magento\Framework\DataObject) {
148  $data = new \Magento\Framework\DataObject();
149  $this->setData('form_data', $data);
150  }
151 
152  return $data;
153  }
154 
161  public function setFormData($data)
162  {
163  if (is_array($data)) {
164  $this->setData('form_data', new \Magento\Framework\DataObject($data));
165  }
166 
167  return $this;
168  }
169 
175  public function getProductId()
176  {
177  return $this->getRequest()->getParam('id', null);
178  }
179 
185  public function getCategoryId()
186  {
187  return $this->getRequest()->getParam('cat_id', null);
188  }
189 
195  public function getMaxRecipients()
196  {
197  return $this->_sendfriendData->getMaxRecipients();
198  }
199 
205  public function getSendUrl()
206  {
207  return $this->getUrl(
208  'sendfriend/product/sendmail',
209  [
210  'id' => $this->getProductId(),
211  'cat_id' => $this->getCategoryId(),
212  ]
213  );
214  }
215 
221  public function canSend()
222  {
223  return !$this->sendfriend->isExceedLimit();
224  }
225 }
getData($key='', $index=null)
Definition: DataObject.php:119
$email
Definition: details.phtml:13
__construct(\Magento\Framework\View\Element\Template\Context $context, \Magento\Customer\Model\Session $customerSession, \Magento\SendFriend\Helper\Data $sendfriendData, \Magento\Framework\Registry $registry, \Magento\Customer\Helper\View $customerViewHelper, \Magento\Framework\App\Http\Context $httpContext, \Magento\SendFriend\Model\SendFriend $sendfriend, array $data=[])
Definition: Send.php:63
setData($key, $value=null)
Definition: DataObject.php:72
if(!isset($_GET['name'])) $name
Definition: log.php:14