Index.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. *
  4. * Copyright © Magento, Inc. All rights reserved.
  5. * See COPYING.txt for license details.
  6. */
  7. namespace Magento\Rss\Controller\Feed;
  8. use Magento\Framework\Exception\NotFoundException;
  9. /**
  10. * Class Index
  11. * @package Magento\Rss\Controller\Feed
  12. */
  13. class Index extends \Magento\Rss\Controller\Feed
  14. {
  15. /**
  16. * Index action
  17. *
  18. * @return void
  19. * @throws NotFoundException
  20. */
  21. public function execute()
  22. {
  23. if (!$this->scopeConfig->getValue('rss/config/active', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)) {
  24. throw new NotFoundException(__('Page not found.'));
  25. }
  26. $type = $this->getRequest()->getParam('type');
  27. try {
  28. $provider = $this->rssManager->getProvider($type);
  29. } catch (\InvalidArgumentException $e) {
  30. throw new NotFoundException(__($e->getMessage()));
  31. }
  32. if ($provider->isAuthRequired() && !$this->auth()) {
  33. return;
  34. }
  35. if (!$provider->isAllowed()) {
  36. throw new NotFoundException(__('Page not found.'));
  37. }
  38. /** @var $rss \Magento\Rss\Model\Rss */
  39. $rss = $this->rssFactory->create();
  40. $rss->setDataProvider($provider);
  41. $this->getResponse()->setHeader('Content-type', 'text/xml; charset=UTF-8');
  42. $this->getResponse()->setBody($rss->createRssXml());
  43. }
  44. }