Exemple #1
0
 /**
  * @return \Magento\Framework\Controller\Result\Forward|\Magento\Framework\View\Result\Page
  */
 public function execute()
 {
     $authorId = (int) $this->getRequest()->getParam('id');
     $author = $this->authorFactory->create();
     $author->load($authorId);
     if (!$author->isActive()) {
         $resultForward = $this->resultForwardFactory->create();
         $resultForward->forward('noroute');
         return $resultForward;
     }
     $this->coreRegistry->register('current_author', $author);
     $resultPage = $this->resultPageFactory->create();
     $title = $author->getMetaTitle() ?: $author->getName();
     $resultPage->getConfig()->getTitle()->set($title);
     $resultPage->getConfig()->setDescription($author->getMetaDescription());
     $resultPage->getConfig()->setKeywords($author->getMetaKeywords());
     if ($this->scopeConfig->isSetFlag(self::BREADCRUMBS_CONFIG_PATH, ScopeInterface::SCOPE_STORE)) {
         /** @var \Magento\Theme\Block\Html\Breadcrumbs $breadcrumbsBlock */
         $breadcrumbsBlock = $resultPage->getLayout()->getBlock('breadcrumbs');
         if ($breadcrumbsBlock) {
             $breadcrumbsBlock->addCrumb('home', ['label' => __('Home'), 'link' => $this->_url->getUrl('')]);
             $breadcrumbsBlock->addCrumb('authors', ['label' => __('Authors'), 'link' => $this->urlModel->getListUrl()]);
             $breadcrumbsBlock->addCrumb('author-' . $author->getId(), ['label' => $author->getName()]);
         }
     }
     return $resultPage;
 }
Exemple #2
0
 /**
  * @return \Sample\News\Model\Author
  */
 protected function initAuthor()
 {
     $authorId = (int) $this->getRequest()->getParam('author_id');
     /** @var \Sample\News\Model\Author $author */
     $author = $this->authorFactory->create();
     if ($authorId) {
         $author->load($authorId);
     }
     $this->coreRegistry->register('sample_news_author', $author);
     return $author;
 }
Exemple #3
0
 /**
  * prepare collection
  * @return $this
  */
 protected function _prepareCollection()
 {
     $collection = $this->authorCollectionFactory->create();
     if ($this->getCategory()->getId()) {
         $constraint = 'related.category_id=' . $this->getCategory()->getId();
     } else {
         $constraint = 'related.category_id=0';
     }
     $collection->getSelect()->joinLeft(['related' => $collection->getTable('sample_news_author_category')], 'related.author_id=main_table.author_id AND ' . $constraint, ['position']);
     $this->setCollection($collection);
     return parent::_prepareCollection();
 }
 /**
  * @access public
  * @param \Magento\Catalog\Model\Category $category
  * @return \Sample\News\Model\ResourceModel\Author\Collection
  */
 public function getSelectedAuthorsCollection(CategoryModel $category)
 {
     $collection = $this->authorCollectionFactory->create()->addCategoryFilter($category);
     return $collection;
 }
Exemple #5
0
 /**
  * @access public
  * @param \Magento\Catalog\Model\Product $product
  * @return \Sample\News\Model\ResourceModel\Author\Collection
  */
 public function getSelectedAuthorsCollection(ProductModel $product)
 {
     $collection = $this->authorCollectionFactory->create()->addProductFilter($product);
     return $collection;
 }