/**
  * {@inheritdoc}
  */
 public function getRssData()
 {
     $categoryId = $this->getRequest()->getParam('category_id');
     $storeModel = $this->storeManager->getStore($this->getStoreId());
     $newUrl = $this->rssUrlBuilder->getUrl(['store_id' => $this->getStoreId(), 'type' => 'blog_categories', 'category_id' => $categoryId]);
     $title = __('List Posts from %1', $storeModel->getFrontendName());
     $lang = $this->_scopeConfig->getValue('general/locale/code', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeModel);
     $data = ['title' => $title, 'description' => $title, 'link' => $newUrl, 'charset' => 'UTF-8', 'language' => $lang];
     $limit = 10;
     $count = 0;
     $category = $this->rssModel->create()->load($categoryId);
     $posts = $category->getSelectedPostsCollection();
     $posts->addFieldToFilter('enabled', 1)->setOrder('post_id', 'DESC');
     foreach ($posts as $item) {
         $count++;
         if ($count > $limit) {
             break;
         }
         /** @var $item \Magento\Catalog\Model\Product */
         $item->setAllowedInRss(true);
         $item->setAllowedPriceInRss(true);
         if (!$item->getAllowedInRss()) {
             continue;
         }
         $description = '
             <table><tr>
             <td style="text-decoration:none;"> %s</td>
             </tr></table>
         ';
         $description = sprintf($description, $item->getShortDescription());
         $data['entries'][] = ['title' => $item->getName(), 'link' => $this->helper->getUrlByPost($item), 'description' => $description];
     }
     return $data;
 }
Ejemplo n.º 2
0
 /**
  * Validate and Match Cms Page and modify request
  *
  * @param \Magento\Framework\App\RequestInterface $request
  * @return bool
  */
 public function match(\Magento\Framework\App\RequestInterface $request)
 {
     $helper = $this->_helper;
     if ($helper->getBlogConfig('general/enabled')) {
         $url_prefix = $helper->getBlogConfig('general/url_prefix');
         $url_suffix = $helper->getBlogConfig('general/url_suffix');
         if ($url_prefix == '') {
             return $this;
         }
         $path = trim($request->getPathInfo(), '/');
         if (strpos($path, $url_prefix) === 0) {
             $array = explode('/', $path);
             if (count($array) == 1) {
                 $request->setAlias(\Magento\Framework\UrlInterface::REWRITE_REQUEST_PATH_ALIAS, $path);
                 $request->setPathInfo('/' . 'blog/post/index');
                 return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward');
             } elseif (count($array) == 2) {
                 $url_key = $array[1];
                 $post = $this->_helper->getPostByUrl($url_key);
                 if ($post && $post->getId()) {
                     $request->setAlias(\Magento\Framework\UrlInterface::REWRITE_REQUEST_PATH_ALIAS, $url_key);
                     $request->setPathInfo('/' . 'blog/post/view/id/' . $post->getId());
                     return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward');
                 }
             } elseif (count($array) == 3) {
                 $type = $array[1];
                 if ($type == 'post' && $array[2] == 'index') {
                     if ($array[2] == 'index') {
                         $request->setAlias(\Magento\Framework\UrlInterface::REWRITE_REQUEST_PATH_ALIAS, $path);
                         $request->setPathInfo('/' . 'blog/post/index');
                         return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward');
                     } else {
                         $url_key = $array[2];
                         $post = $this->_helper->getPostByUrl($url_key);
                         if ($post && $post->getId()) {
                             $request->setAlias(\Magento\Framework\UrlInterface::REWRITE_REQUEST_PATH_ALIAS, $url_key);
                             $request->setPathInfo('/' . 'blog/post/view/id/' . $post->getId());
                             return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward');
                         }
                     }
                 }
                 if ($type == 'post' && strpos($path, 'rss') !== false) {
                     $path = str_replace($url_prefix, 'blog', $path);
                     $request->setAlias(\Magento\Framework\UrlInterface::REWRITE_REQUEST_PATH_ALIAS, $path);
                     $request->setPathInfo($path);
                     return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward');
                 }
                 if ($type == 'topic') {
                     $topicUrlKey = $array[2];
                     $topic = $this->_helper->getTopicByParam('url_key', $topicUrlKey);
                     $request->setAlias(\Magento\Framework\UrlInterface::REWRITE_REQUEST_PATH_ALIAS, $path);
                     $request->setPathInfo('/' . 'blog/topic/view/id/' . $topic->getId());
                     return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward');
                 }
                 if ($type == 'tag') {
                     $tagUrlKey = $array[2];
                     $tag = $this->_helper->getTagByParam('url_key', $tagUrlKey);
                     $request->setAlias(\Magento\Framework\UrlInterface::REWRITE_REQUEST_PATH_ALIAS, $path);
                     $request->setPathInfo('/' . 'blog/tag/view/id/' . $tag->getId());
                     return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward');
                 }
                 if ($type == 'category') {
                     $categoryName = $array[2];
                     $category = $this->_helper->getCategoryByParam('url_key', $categoryName);
                     if ($category && $category->getId()) {
                         $request->setAlias(\Magento\Framework\UrlInterface::REWRITE_REQUEST_PATH_ALIAS, $path);
                         $request->setPathInfo('/' . 'blog/category/view/id/' . $category->getId());
                         return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward');
                     }
                 }
             } elseif (count($array) > 3) {
                 if (strpos($path, 'rss') !== false) {
                     $path = str_replace($url_prefix, 'blog', $path);
                     $request->setAlias(\Magento\Framework\UrlInterface::REWRITE_REQUEST_PATH_ALIAS, $path);
                     $request->setPathInfo($path);
                     return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward');
                 }
             }
         }
     }
 }