Skip to content

Instantly share code, notes, and snippets.

@NazarenkoDenis
Created March 26, 2020 17:08
Show Gist options
  • Save NazarenkoDenis/e6f40eae22b4404f3fd6fa8cb2a5da16 to your computer and use it in GitHub Desktop.
Save NazarenkoDenis/e6f40eae22b4404f3fd6fa8cb2a5da16 to your computer and use it in GitHub Desktop.
vendor/mirasvit/module-seo/src/SeoSitemap/Repository/Provider/FishPig/BlogProvider.php
<?php
namespace Mirasvit\SeoSitemap\Repository\Provider\FishPig;
use Magento\Framework\DataObject;
use Magento\Framework\ObjectManagerInterface;
use Magento\Sitemap\Helper\Data as DataHelper;
use Mirasvit\SeoSitemap\Api\Repository\ProviderInterface;
class BlogProvider implements ProviderInterface
{
private $objectManager;
private $dataHelper;
public function __construct(
ObjectManagerInterface $objectManager,
DataHelper $dataHelper
) {
$this->objectManager = $objectManager;
$this->dataHelper = $dataHelper;
}
public function getModuleName()
{
return 'FishPig_WordPress';
}
public function isApplicable()
{
return true;
}
public function getTitle()
{
return __('Blog');
}
public function initSitemapItem($storeId)
{
$result = [];
$result[] = new DataObject([
'changefreq' => $this->dataHelper->getPageChangefreq($storeId),
'priority' => $this->dataHelper->getPagePriority($storeId),
'collection' => $this->getItems($storeId),
]);
return $result;
}
public function getItems($storeId)
{
$items = [];
try {
$emulation = $this->objectManager->create('Magento\Store\Model\App\Emulation');
$emulation->startEnvironmentEmulation($storeId, 'frontend', true);
$collection = $this->objectManager->get('FishPig\WordPress\Model\ResourceModel\Post\Collection');
$collection->addIsViewableFilter();
$emulation->stopEnvironmentEmulation();
foreach ($collection as $key => $post) {
$url = $post->getUrl();
$url = parse_url($url, PHP_URL_PATH);
$url = ltrim($url, '/');
$items[] = new DataObject([
'id' => $post->getId(),
'url' => $url,
'title' => $post->getName(),
'updated_at' => $post->getPostModifiedDate(),
]);
}
} catch (\Exception $e) {
}
return $items;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment