orderFactory = $orderFactory; $this->urlBuilder = $urlBuilder; $this->localeDate = $localeDate; $this->dateTime = $dateTime; $this->eventManager = $eventManager; $this->layout = $layout; $this->rssUrlBuilder = $rssUrlBuilder; } /** * Check if RSS feed allowed * * @return mixed */ public function isAllowed() { return true; } /** * Get RSS feed items * * @return array */ public function getRssData() { $dateTime = new \DateTime('now', new \DateTimeZone('UTC')); $interval = new \DateInterval('P7D'); $dateTime->sub($interval); $fromDate = $this->dateTime->formatDate($dateTime->getTimestamp()); $newUrl = $this->rssUrlBuilder->getUrl(['_secure' => true, '_nosecret' => true, 'type' => 'new_order']); $title = __('New Orders'); $data = ['title' => $title, 'description' => $title, 'link' => $newUrl, 'charset' => 'UTF-8']; /** @var $order \Magento\Sales\Model\Order */ $order = $this->orderFactory->create(); /** @var $collection \Magento\Sales\Model\ResourceModel\Order\Collection */ $collection = $order->getResourceCollection(); $collection->addAttributeToFilter('created_at', ['date' => true, 'from' => $fromDate]) ->addAttributeToSort('created_at', 'desc'); $this->eventManager->dispatch('rss_order_new_collection_select', ['collection' => $collection]); $detailBlock = $this->layout->getBlockSingleton('Magento\Sales\Block\Adminhtml\Order\Details'); foreach ($collection as $item) { $title = __('Order #%1 created at %2', $item->getIncrementId(), $this->localeDate->formatDate( $item->getCreatedAt() )); $url = $this->urlBuilder->getUrl( 'sales/order/view', ['_secure' => true, 'order_id' => $item->getId(), '_nosecret' => true] ); $detailBlock->setOrder($item); $data['entries'][] = (['title' => $title, 'link' => $url, 'description' => $detailBlock->toHtml()]); } return $data; } /** * @return string */ public function getCacheKey() { return 'rss_new_orders_data'; } /** * @return int */ public function getCacheLifetime() { return 60; } /** * @return array */ public function getFeeds() { return []; } /** * {@inheritdoc} */ public function isAuthRequired() { return true; } }