Initial commit: Free Shipping Message module
This commit is contained in:
86
Block/Product/View/Message.php
Normal file
86
Block/Product/View/Message.php
Normal file
@@ -0,0 +1,86 @@
|
||||
<?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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user