-
Notifications
You must be signed in to change notification settings - Fork 4
/
News.php
68 lines (58 loc) · 2.02 KB
/
News.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
namespace BDC\SimpleNews\Helper;
use \Magento\Framework\App\Helper\Context;
use \Magento\Store\Model\StoreManagerInterface;
use \Magento\Framework\App\State;
use \BDC\SimpleNews\Model\NewsFactory;
use \Symfony\Component\Console\Input\Input;
use \Psr\Log\LoggerInterface;
use \Magento\Framework\Event\ManagerInterface;
class News extends \Magento\Framework\App\Helper\AbstractHelper {
const KEY_TITLE = 'news-title';
const KEY_SUMMARY = 'news-summary';
const KEY_DESC = 'news-description';
protected $storeManager;
protected $state;
protected $newsFactory;
protected $data;
protected $newsId;
protected $logger;
protected $eventManager;
// $eventManager
public function __construct(
Context $context,
StoreManagerInterface $storeManager,
State $state,
NewsFactory $newsFactory,
LoggerInterface $logger,
ManagerInterface $eventManager) {
$this->storeManager = $storeManager;
$this->state = $state;
$this->logger = $logger;
$this->eventManager = $eventManager;
$this->newsFactory = $newsFactory;
parent::__construct($context);
}
public function setData(Input $input){
$this->data = $input;
return $this;
}
public function execute() {
$this->state->setAreaCode('frontend');
$news = $this->newsFactory->create();
$news->setTitle($this->data->getOption(self::KEY_TITLE))
->setSummary($this->data->getOption(self::KEY_SUMMARY))
->setDescription($this->data->getOption(self::KEY_DESC));
$news->save();
$this->logger->debug('DI: '.$news->getTitle());
// EventCode...
$this->eventManager->dispatch('bdc_simplenews_save_after', ['object' => $news]);
$this->newsId = $news->getId();
// if($this->data->getOption(self::KEY_SENDEMAIL)) {
// $news->sendNewAccountEmail();
// }
}
public function getNewsId(){
return (int)$this->newsId;
}
}