Rss.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Sales\Block\Order\Info\Buttons;
  7. /**
  8. * Block of links in Order view page
  9. *
  10. * @api
  11. * @since 100.0.2
  12. */
  13. class Rss extends \Magento\Framework\View\Element\Template
  14. {
  15. /**
  16. * @var string
  17. */
  18. protected $_template = 'Magento_Sales::order/info/buttons/rss.phtml';
  19. /**
  20. * @var \Magento\Sales\Model\OrderFactory
  21. */
  22. protected $orderFactory;
  23. /**
  24. * @var \Magento\Framework\App\Rss\UrlBuilderInterface
  25. */
  26. protected $rssUrlBuilder;
  27. /**
  28. * @param \Magento\Framework\View\Element\Template\Context $context
  29. * @param \Magento\Sales\Model\OrderFactory $orderFactory
  30. * @param \Magento\Framework\App\Rss\UrlBuilderInterface $rssUrlBuilder
  31. * @param array $data
  32. */
  33. public function __construct(
  34. \Magento\Framework\View\Element\Template\Context $context,
  35. \Magento\Sales\Model\OrderFactory $orderFactory,
  36. \Magento\Framework\App\Rss\UrlBuilderInterface $rssUrlBuilder,
  37. array $data = []
  38. ) {
  39. $this->orderFactory = $orderFactory;
  40. $this->rssUrlBuilder = $rssUrlBuilder;
  41. parent::__construct($context, $data);
  42. }
  43. /**
  44. * Get link url.
  45. *
  46. * @return string
  47. */
  48. public function getLink()
  49. {
  50. return $this->rssUrlBuilder->getUrl($this->getLinkParams());
  51. }
  52. /**
  53. * Get translatable label for url.
  54. *
  55. * @return \Magento\Framework\Phrase
  56. */
  57. public function getLabel()
  58. {
  59. return __('Subscribe to Order Status');
  60. }
  61. /**
  62. * Check whether status notification is allowed
  63. *
  64. * @return bool
  65. */
  66. public function isRssAllowed()
  67. {
  68. return $this->_scopeConfig->isSetFlag(
  69. 'rss/order/status',
  70. \Magento\Store\Model\ScopeInterface::SCOPE_STORE
  71. );
  72. }
  73. /**
  74. * Retrieve order status url key
  75. *
  76. * @param \Magento\Sales\Model\Order $order
  77. * @return string
  78. */
  79. protected function getUrlKey($order)
  80. {
  81. $data = [
  82. 'order_id' => $order->getId(),
  83. 'increment_id' => $order->getIncrementId(),
  84. 'customer_id' => $order->getCustomerId(),
  85. ];
  86. return base64_encode(json_encode($data));
  87. }
  88. /**
  89. * Get type, secure and query params for link.
  90. *
  91. * @return array
  92. * @SuppressWarnings(PHPMD.RequestAwareBlockMethod)
  93. */
  94. protected function getLinkParams()
  95. {
  96. $order = $this->orderFactory->create()->load($this->_request->getParam('order_id'));
  97. return [
  98. 'type' => 'order_status',
  99. '_secure' => true,
  100. '_query' => ['data' => $this->getUrlKey($order)]
  101. ];
  102. }
  103. }