87 lines
1.9 KiB
PHP
87 lines
1.9 KiB
PHP
<?php
|
|
/**
|
|
* Shopkeeper FreeShippingMessage Block
|
|
*/
|
|
namespace Shopkeeper\FreeShippingMessage\Block\Product\View;
|
|
|
|
use Magento\Framework\View\Element\Template;
|
|
use Magento\Framework\View\Element\Template\Context;
|
|
use Magento\Cms\Model\BlockFactory;
|
|
use Magento\Cms\Model\Template\FilterProvider;
|
|
|
|
class Message extends Template
|
|
{
|
|
/**
|
|
* @var BlockFactory
|
|
*/
|
|
protected $blockFactory;
|
|
|
|
/**
|
|
* @var FilterProvider
|
|
*/
|
|
protected $filterProvider;
|
|
|
|
/**
|
|
* @param Context $context
|
|
* @param BlockFactory $blockFactory
|
|
* @param FilterProvider $filterProvider
|
|
* @param array $data
|
|
*/
|
|
public function __construct(
|
|
Context $context,
|
|
BlockFactory $blockFactory,
|
|
FilterProvider $filterProvider,
|
|
array $data = []
|
|
) {
|
|
$this->blockFactory = $blockFactory;
|
|
$this->filterProvider = $filterProvider;
|
|
parent::__construct($context, $data);
|
|
}
|
|
|
|
/**
|
|
* Get CMS block HTML content
|
|
*
|
|
* @return string
|
|
*/
|
|
public function getCmsBlockHtml()
|
|
{
|
|
$blockId = $this->getData('cms_block_id');
|
|
|
|
if (!$blockId) {
|
|
return '';
|
|
}
|
|
|
|
$block = $this->blockFactory->create();
|
|
$block->load($blockId, 'identifier');
|
|
|
|
if (!$block->getId() || !$block->isActive()) {
|
|
return '';
|
|
}
|
|
|
|
$html = $this->filterProvider->getBlockFilter()
|
|
->setStoreId($this->_storeManager->getStore()->getId())
|
|
->filter($block->getContent());
|
|
|
|
return $html;
|
|
}
|
|
|
|
/**
|
|
* Check if CMS block exists and is active
|
|
*
|
|
* @return bool
|
|
*/
|
|
public function hasCmsBlock()
|
|
{
|
|
$blockId = $this->getData('cms_block_id');
|
|
|
|
if (!$blockId) {
|
|
return false;
|
|
}
|
|
|
|
$block = $this->blockFactory->create();
|
|
$block->load($blockId, 'identifier');
|
|
|
|
return $block->getId() && $block->isActive();
|
|
}
|
|
}
|