0

I'm trying to find if a page is used on more than one website on a multi-website Magento installation.

I have sucessfully return data of the page, but PageInterface has nothing like getStores() or getWebsites().

Here is my code:

public function getPageData($identifier){
        $searchCriteria = $this->_searchCriteriaBuilder->addFilter('identifier', $identifier,'eq')->create();
        $pages = $this->_pageRepositoryInterface->getList($searchCriteria)->getItems();
        return $pages;
    }

Thanks and Greetings!

2
  • You can add store id in to the searchCriteria then count the result to verify it exists
    – Jimmy
    Commented Mar 23, 2021 at 3:44
  • how would that be? have identifier of page and also store id? Commented Mar 23, 2021 at 15:36

1 Answer 1

0

I found the answer by myself.

In Magento\Cms\Model\Page;There is a method called getStores()

So this is how I made it work:

use Magento\Cms\Model\Page;

use Magento\Framework\View\Element\Template;
use Magento\Cms\Model\Page;

class Main extends Template
{
    protected $_page;

    public function __construct(
        \Magento\Framework\View\Element\Template\Context $context,
        Page $page,

    ) {
        parent::__construct($context);

        $this->_page = $page;
        
    }

    public function getStores(){
        $stores = $this->_page->getStores();
        return $stores;
    }

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.