132 \
Magento\Framework\Mail\Template\TransportBuilder $transportBuilder,
133 \
Magento\Catalog\Helper\Image $catalogImage,
135 \
Magento\Framework\Escaper $escaper,
140 \
Magento\Framework\Data\Collection\AbstractDb $resourceCollection =
null,
144 $this->_transportBuilder = $transportBuilder;
145 $this->_catalogImage = $catalogImage;
146 $this->_sendfriendData = $sendfriendData;
147 $this->_escaper = $escaper;
171 throw new \Magento\Framework\Exception\LocalizedException(
176 $this->inlineTranslation->suspend();
180 'name' => $this->_escaper->escapeHtml($this->
getSender()->getName()),
181 'email' => $this->_escaper->escapeHtml($this->
getSender()->getEmail()),
186 $this->_transportBuilder->setTemplateIdentifier(
187 $this->_sendfriendData->getEmailTemplate()
188 )->setTemplateOptions(
190 'area' => \
Magento\Framework\
App\Area::AREA_FRONTEND,
191 'store' => $this->_storeManager->getStore()->getId(),
199 'product_name' => $this->
getProduct()->getName(),
200 'product_url' => $this->
getProduct()->getUrlInStore(),
202 'sender_name' => $sender[
'name'],
203 'sender_email' => $sender[
'email'],
204 'product_image' => $this->_catalogImage->init($this->getProduct(),
'sendfriend_small_image')
211 $transport = $this->_transportBuilder->getTransport();
212 $transport->sendMessage();
215 $this->inlineTranslation->resume();
235 $errors[] =
__(
'Please enter a sender name.');
245 $errors[] =
__(
'Please enter a message.');
249 $errors[] =
__(
'Please specify at least one recipient.');
255 $errors[] =
__(
'Please enter a correct recipient email address.');
261 if (count($this->
getRecipients()->getEmails()) > $maxRecipients) {
299 foreach ($recipients[
'email'] as $k =>
$email) {
300 if (!isset($emails[
$email]) && isset($recipients[
'name'][$k])) {
302 $names[] = $recipients[
'name'][$k];
307 $emails = array_keys($emails);
312 new \
Magento\Framework\DataObject([
'emails' => $emails,
'names' => $names])
323 $recipients = $this->
_getData(
'_recipients');
324 if (!$recipients instanceof \
Magento\Framework\DataObject) {
325 $recipients = new \Magento\Framework\DataObject([
'emails' => [],
'names' => []]);
326 $this->
setData(
'_recipients', $recipients);
352 throw new \Magento\Framework\Exception\LocalizedException(
__(
'Please define a correct product instance.'));
365 if (!is_array($sender)) {
366 __(
'Invalid Sender Information');
369 return $this->
setData(
'_sender',
new \
Magento\Framework\DataObject($sender));
380 $sender = $this->
_getData(
'_sender');
381 if (!$sender instanceof \
Magento\Framework\DataObject) {
382 throw new \Magento\Framework\Exception\LocalizedException(
383 __(
'Please define the correct sender information.')
396 return $this->_sendfriendData->getMaxEmailPerPeriod();
406 return $this->_sendfriendData->getMaxRecipients();
416 return $this->_sendfriendData->isEnabled();
437 if ($useCache && $this->_sentCount !==
null) {
441 switch ($this->_sendfriendData->getLimitBy()) {
442 case \Magento\SendFriend\Helper\Data::CHECK_COOKIE:
444 case \Magento\SendFriend\Helper\Data::CHECK_IP:
458 switch ($this->_sendfriendData->getLimitBy()) {
459 case \Magento\SendFriend\Helper\Data::CHECK_COOKIE:
461 case \Magento\SendFriend\Helper\Data::CHECK_IP:
476 $cookieName = $this->_sendfriendData->getCookieName();
480 if (isset($this->_lastCookieValue[$cookieName])) {
481 $oldTimes = $this->_lastCookieValue[$cookieName];
483 $oldTimes = $this->cookieManager->getCookie($cookieName);
487 $oldTimes = explode(
',', $oldTimes);
488 foreach ($oldTimes as $oldTime) {
489 $periodTime = $time - $this->_sendfriendData->getPeriod();
490 if (is_numeric($oldTime) and $oldTime >= $periodTime) {
491 $newTimes[] = $oldTime;
498 $newValue = implode(
',', $newTimes);
499 $this->cookieManager->setSensitiveCookie($cookieName, $newValue);
500 $this->_lastCookieValue[$cookieName] = $newValue;
503 return count($newTimes);
515 $period = $this->_sendfriendData->getPeriod();
516 $websiteId = $this->_storeManager->getStore()->getWebsiteId();
520 $this->
_getResource()->deleteLogsBefore($time - $period);
527 $this->remoteAddress->getRemoteAddress(
true),
setData($key, $value=null)
__construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\Mail\Template\TransportBuilder $transportBuilder, \Magento\Catalog\Helper\Image $catalogImage, \Magento\SendFriend\Helper\Data $sendfriendData, \Magento\Framework\Escaper $escaper, \Magento\Framework\HTTP\PhpEnvironment\RemoteAddress $remoteAddress, \Magento\Framework\Stdlib\CookieManagerInterface $cookieManager, \Magento\Framework\Translate\Inline\StateInterface $inlineTranslation, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
setRecipients($recipients)
getSentCount($useCache=true)
_sentCountByCookies($increment=false)
_sentCountByIp($increment=false)
static is($value, $classBaseName, array $args=array(), $namespaces=array())
if(!isset($_GET['name'])) $name