123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Catalog\Block\Adminhtml\Rss;
- use Magento\Framework\App\Rss\DataProviderInterface;
- /**
- * Class NotifyStock
- *
- * @package Magento\Catalog\Block\Adminhtml\Rss
- */
- class NotifyStock extends \Magento\Backend\Block\AbstractBlock implements DataProviderInterface
- {
- /**
- * @var \Magento\Framework\App\Rss\UrlBuilderInterface
- */
- protected $rssUrlBuilder;
- /**
- * @var \Magento\Catalog\Model\Rss\Product\NotifyStock
- */
- protected $rssModel;
- /**
- * @param \Magento\Backend\Block\Context $context
- * @param \Magento\Catalog\Model\Rss\Product\NotifyStock $rssModel
- * @param \Magento\Framework\App\Rss\UrlBuilderInterface $rssUrlBuilder
- * @param array $data
- */
- public function __construct(
- \Magento\Backend\Block\Context $context,
- \Magento\Catalog\Model\Rss\Product\NotifyStock $rssModel,
- \Magento\Framework\App\Rss\UrlBuilderInterface $rssUrlBuilder,
- array $data = []
- ) {
- $this->rssUrlBuilder = $rssUrlBuilder;
- $this->rssModel = $rssModel;
- parent::__construct($context, $data);
- }
- /**
- * @inheritdoc
- */
- protected function _construct()
- {
- $this->setCacheKey('rss_catalog_notifystock');
- parent::_construct();
- }
- /**
- * @inheritdoc
- */
- public function getRssData()
- {
- $newUrl = $this->rssUrlBuilder->getUrl(['_secure' => true, '_nosecret' => true, 'type' => 'notifystock']);
- $title = __('Low Stock Products')->render();
- $data = ['title' => $title, 'description' => $title, 'link' => $newUrl, 'charset' => 'UTF-8'];
- foreach ($this->rssModel->getProductsCollection() as $item) {
- /* @var $item \Magento\Catalog\Model\Product */
- $url = $this->getUrl(
- 'catalog/product/edit',
- ['id' => $item->getId(), '_secure' => true, '_nosecret' => true]
- );
- $qty = 1 * $item->getQty();
- $description = __('%1 has reached a quantity of %2.', $item->getName(), $qty)->render();
- $data['entries'][] = ['title' => $item->getName(), 'link' => $url, 'description' => $description];
- }
- return $data;
- }
- /**
- * @inheritdoc
- */
- public function getCacheLifetime()
- {
- return 600;
- }
- /**
- * @inheritdoc
- */
- public function isAllowed()
- {
- return true;
- }
- /**
- * @inheritdoc
- */
- public function getFeeds()
- {
- return [];
- }
- /**
- * @inheritdoc
- */
- public function isAuthRequired()
- {
- return true;
- }
- }
|