init
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\PromotionPopup\Block\Adminhtml\System\Config\Form\Field;
|
||||
|
||||
use Magento\Config\Block\System\Config\Form\Field;
|
||||
use Magento\Framework\Data\Form\Element\AbstractElement;
|
||||
|
||||
class Date extends Field
|
||||
{
|
||||
/**
|
||||
* Set an explicit, locale-independent format before rendering the calendar field.
|
||||
*
|
||||
* @param AbstractElement $element
|
||||
* @return string
|
||||
*/
|
||||
protected function _getElementHtml(AbstractElement $element): string
|
||||
{
|
||||
$element->setDateFormat('yyyy-MM-dd');
|
||||
|
||||
return parent::_getElementHtml($element);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\PromotionPopup\Block;
|
||||
|
||||
use Esun\PromotionPopup\Model\Config;
|
||||
use Magento\Cms\Block\BlockByIdentifier;
|
||||
use Magento\Framework\Serialize\Serializer\Json;
|
||||
use Magento\Framework\View\Element\Template;
|
||||
use Magento\Framework\View\Element\Template\Context;
|
||||
|
||||
class Popup extends Template
|
||||
{
|
||||
public function __construct(
|
||||
Context $context,
|
||||
private readonly Config $config,
|
||||
private readonly Json $json,
|
||||
array $data = []
|
||||
) {
|
||||
parent::__construct($context, $data);
|
||||
}
|
||||
|
||||
public function isAvailable(): bool
|
||||
{
|
||||
return $this->config->canDisplay();
|
||||
}
|
||||
|
||||
public function getCmsContent(): string
|
||||
{
|
||||
$identifier = $this->config->getCmsBlockIdentifier();
|
||||
if ($identifier === '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
$content = $this->getLayout()->createBlock(
|
||||
BlockByIdentifier::class,
|
||||
'esun.promotion.popup.cms.' . sha1($identifier)
|
||||
);
|
||||
if (!$content) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $content->setData('identifier', $identifier)->toHtml();
|
||||
}
|
||||
|
||||
public function getJsonConfig(): string
|
||||
{
|
||||
return $this->json->serialize([
|
||||
'websiteId' => $this->config->getWebsiteId(),
|
||||
'campaignKey' => sha1($this->config->getCmsBlockIdentifier()),
|
||||
'campaignVersion' => $this->config->getCampaignVersion(),
|
||||
'displayDelay' => $this->config->getDisplayDelay(),
|
||||
'frequency' => $this->config->getFrequency(),
|
||||
'audience' => $this->config->getAudience(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user