Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
NotifyStock.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
16 
18 {
22  private $rssUrlBuilder;
23 
27  private $getSourceItemsCollection;
28 
35  public function __construct(
36  Context $context,
37  GetSourceItemsCollection $getSourceItemsCollection,
38  UrlBuilderInterface $rssUrlBuilder,
39  array $data = []
40  ) {
41  parent::__construct($context, $data);
42 
43  $this->rssUrlBuilder = $rssUrlBuilder;
44  $this->getSourceItemsCollection = $getSourceItemsCollection;
45  }
46 
50  protected function _construct()
51  {
52  $this->setCacheKey('rss_catalog_notifystock');
53  parent::_construct();
54  }
55 
59  public function getRssData()
60  {
61  $newUrl = $this->rssUrlBuilder->getUrl(['_secure' => true, '_nosecret' => true, 'type' => 'notifystock']);
62  $title = __('Low Stock Products');
63  $data = ['title' => $title, 'description' => $title, 'link' => $newUrl, 'charset' => 'UTF-8'];
64 
65  foreach ($this->getSourceItemsCollection->execute() as $item) {
66  $url = $this->getUrl(
67  'catalog/product/edit',
68  ['id' => $item->getId(), '_secure' => true, '_nosecret' => true]
69  );
70  $qty = (float)$item->getData('qty');
71 
72  $description = __(
73  '%1 has reached a quantity of %2 in source %3(Source Code: %4).',
74  $item->getData('name'),
75  $qty,
76  $item->getData('source_name'),
78  );
79 
80  $data['entries'][] = ['title' => $item->getData('name'), 'link' => $url, 'description' => $description];
81  }
82 
83  return $data;
84  }
85 
89  public function getCacheLifetime()
90  {
91  return 600;
92  }
93 
97  public function isAllowed()
98  {
99  return true;
100  }
101 
105  public function getFeeds()
106  {
107  return [];
108  }
109 
113  public function isAuthRequired()
114  {
115  return true;
116  }
117 }
$title
Definition: default.phtml:14
__()
Definition: __.php:13
__construct(Context $context, GetSourceItemsCollection $getSourceItemsCollection, UrlBuilderInterface $rssUrlBuilder, array $data=[])
Definition: NotifyStock.php:35