ltsecurityinc安防产品在线商城代码
This commit is contained in:
+50
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
* Plumrocket Inc.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the End-user License Agreement
|
||||
* that is available through the world-wide-web at this URL:
|
||||
* http://wiki.plumrocket.net/wiki/EULA
|
||||
* If you are unable to obtain it through the world-wide-web, please
|
||||
* send an email to support@plumrocket.com so we can send you a copy immediately.
|
||||
*
|
||||
* @package Plumrocket_CookieConsent
|
||||
* @copyright Copyright (c) 2020 Plumrocket Inc. (http://www.plumrocket.com)
|
||||
* @license http://wiki.plumrocket.net/wiki/EULA End-user License Agreement
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Plumrocket\CookieConsent\Block\Adminhtml\Cookie\Category\Edit\Button;
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Back extends Generic
|
||||
{
|
||||
/**
|
||||
* Get Button Data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getButtonData(): array
|
||||
{
|
||||
return [
|
||||
'label' => __('Back'),
|
||||
'on_click' => sprintf("location.href = '%s';", $this->getBackUrl()),
|
||||
'class' => 'back',
|
||||
'sort_order' => 10
|
||||
];
|
||||
}
|
||||
/**
|
||||
* Get URL for back
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getBackUrl(): string
|
||||
{
|
||||
return $this->getUrl('*/*/');
|
||||
}
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
/**
|
||||
* Plumrocket Inc.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the End-user License Agreement
|
||||
* that is available through the world-wide-web at this URL:
|
||||
* http://wiki.plumrocket.net/wiki/EULA
|
||||
* If you are unable to obtain it through the world-wide-web, please
|
||||
* send an email to support@plumrocket.com so we can send you a copy immediately.
|
||||
*
|
||||
* @package Plumrocket_CookieConsent
|
||||
* @copyright Copyright (c) 2020 Plumrocket Inc. (http://www.plumrocket.com)
|
||||
* @license http://wiki.plumrocket.net/wiki/EULA End-user License Agreement
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Plumrocket\CookieConsent\Block\Adminhtml\Cookie\Category\Edit\Button;
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Delete extends Generic
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getButtonData()
|
||||
{
|
||||
$data = [];
|
||||
if ($this->getCategory()->getId()) {
|
||||
$data = [
|
||||
'label' => __('Delete'),
|
||||
'class' => 'delete',
|
||||
'on_click' => 'deleteConfirm(\'' . __('Are you sure you want to do this?')
|
||||
. '\', \'' . $this->getDeleteUrl() . '\', {"data": {}})',
|
||||
'sort_order' => 20,
|
||||
];
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get URL for delete
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getDeleteUrl(): string
|
||||
{
|
||||
return $this->getUrl('*/*/delete', ['id' => $this->getCategory()->getId()]);
|
||||
}
|
||||
}
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
/**
|
||||
* Plumrocket Inc.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the End-user License Agreement
|
||||
* that is available through the world-wide-web at this URL:
|
||||
* http://wiki.plumrocket.net/wiki/EULA
|
||||
* If you are unable to obtain it through the world-wide-web, please
|
||||
* send an email to support@plumrocket.com so we can send you a copy immediately.
|
||||
*
|
||||
* @package Plumrocket_CookieConsent
|
||||
* @copyright Copyright (c) 2020 Plumrocket Inc. (http://www.plumrocket.com)
|
||||
* @license http://wiki.plumrocket.net/wiki/EULA End-user License Agreement
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Plumrocket\CookieConsent\Block\Adminhtml\Cookie\Category\Edit\Button;
|
||||
|
||||
use Magento\Framework\View\Element\UiComponent\Context;
|
||||
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
|
||||
use Plumrocket\CookieConsent\Api\Data\CategoryInterface;
|
||||
use Plumrocket\CookieConsent\Ui\Locator\CategoryLocatorInterface;
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Generic implements ButtonProviderInterface
|
||||
{
|
||||
/**
|
||||
* Url Builder
|
||||
*
|
||||
* @var Context
|
||||
*/
|
||||
protected $context;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Ui\Locator\CategoryLocatorInterface
|
||||
*/
|
||||
private $categoryLocator;
|
||||
|
||||
/**
|
||||
* Generic constructor
|
||||
*
|
||||
* @param Context $context
|
||||
* @param \Plumrocket\CookieConsent\Ui\Locator\CategoryLocatorInterface $categoryLocator
|
||||
*/
|
||||
public function __construct(
|
||||
Context $context,
|
||||
CategoryLocatorInterface $categoryLocator
|
||||
) {
|
||||
$this->context = $context;
|
||||
$this->categoryLocator = $categoryLocator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate url by route and parameters
|
||||
*
|
||||
* @param string $route
|
||||
* @param array $params
|
||||
* @return string
|
||||
*/
|
||||
public function getUrl($route = '', $params = [])
|
||||
{
|
||||
return $this->context->getUrl($route, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Plumrocket\CookieConsent\Api\Data\CategoryInterface
|
||||
* @throws \Magento\Framework\Exception\NotFoundException
|
||||
*/
|
||||
public function getCategory(): CategoryInterface
|
||||
{
|
||||
return $this->categoryLocator->getCategory();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getButtonData()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
/**
|
||||
* Plumrocket Inc.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the End-user License Agreement
|
||||
* that is available through the world-wide-web at this URL:
|
||||
* http://wiki.plumrocket.net/wiki/EULA
|
||||
* If you are unable to obtain it through the world-wide-web, please
|
||||
* send an email to support@plumrocket.com so we can send you a copy immediately.
|
||||
*
|
||||
* @package Plumrocket_CookieConsent
|
||||
* @copyright Copyright (c) 2020 Plumrocket Inc. (http://www.plumrocket.com)
|
||||
* @license http://wiki.plumrocket.net/wiki/EULA End-user License Agreement
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Plumrocket\CookieConsent\Block\Adminhtml\Cookie\Category\Edit\Button;
|
||||
|
||||
use Magento\Ui\Component\Control\Container;
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Save extends Generic
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getButtonData(): array
|
||||
{
|
||||
return [
|
||||
'label' => __('Save'),
|
||||
'class' => 'save primary',
|
||||
'data_attribute' => [
|
||||
'mage-init' => [
|
||||
'buttonAdapter' => [
|
||||
'actions' => [
|
||||
[
|
||||
'targetName' => 'pr_cookie_category_form.pr_cookie_category_form',
|
||||
'actionName' => 'save',
|
||||
'params' => [
|
||||
false
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
],
|
||||
'class_name' => Container::SPLIT_BUTTON,
|
||||
'options' => $this->getOptions(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve options
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getOptions(): array
|
||||
{
|
||||
$options[] = [
|
||||
'id_hard' => 'save_and_close',
|
||||
'label' => __('Save & Close'),
|
||||
'data_attribute' => [
|
||||
'mage-init' => [
|
||||
'buttonAdapter' => [
|
||||
'actions' => [
|
||||
[
|
||||
'targetName' => 'pr_cookie_category_form.pr_cookie_category_form',
|
||||
'actionName' => 'save',
|
||||
'params' => [
|
||||
true
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
],
|
||||
];
|
||||
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
* Plumrocket Inc.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the End-user License Agreement
|
||||
* that is available through the world-wide-web at this URL:
|
||||
* http://wiki.plumrocket.net/wiki/EULA
|
||||
* If you are unable to obtain it through the world-wide-web, please
|
||||
* send an email to support@plumrocket.com so we can send you a copy immediately.
|
||||
*
|
||||
* @package Plumrocket_CookieConsent
|
||||
* @copyright Copyright (c) 2020 Plumrocket Inc. (http://www.plumrocket.com)
|
||||
* @license http://wiki.plumrocket.net/wiki/EULA End-user License Agreement
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Plumrocket\CookieConsent\Block\Adminhtml\Cookie\Item\Edit\Button;
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Back extends Generic
|
||||
{
|
||||
/**
|
||||
* Get Button Data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getButtonData(): array
|
||||
{
|
||||
return [
|
||||
'label' => __('Back'),
|
||||
'on_click' => sprintf("location.href = '%s';", $this->getBackUrl()),
|
||||
'class' => 'back',
|
||||
'sort_order' => 10
|
||||
];
|
||||
}
|
||||
/**
|
||||
* Get URL for back
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getBackUrl(): string
|
||||
{
|
||||
return $this->getUrl('*/*/');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
/**
|
||||
* Plumrocket Inc.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the End-user License Agreement
|
||||
* that is available through the world-wide-web at this URL:
|
||||
* http://wiki.plumrocket.net/wiki/EULA
|
||||
* If you are unable to obtain it through the world-wide-web, please
|
||||
* send an email to support@plumrocket.com so we can send you a copy immediately.
|
||||
*
|
||||
* @package Plumrocket_CookieConsent
|
||||
* @copyright Copyright (c) 2020 Plumrocket Inc. (http://www.plumrocket.com)
|
||||
* @license http://wiki.plumrocket.net/wiki/EULA End-user License Agreement
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Plumrocket\CookieConsent\Block\Adminhtml\Cookie\Item\Edit\Button;
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Delete extends Generic
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getButtonData()
|
||||
{
|
||||
$data = [];
|
||||
if ($this->getCookie()->getId()) {
|
||||
$data = [
|
||||
'label' => __('Delete'),
|
||||
'class' => 'delete',
|
||||
'on_click' => 'deleteConfirm(\'' . __('Are you sure you want to do this?')
|
||||
. '\', \'' . $this->getDeleteUrl() . '\', {"data": {}})',
|
||||
'sort_order' => 20,
|
||||
];
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get URL for delete
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getDeleteUrl(): string
|
||||
{
|
||||
return $this->getUrl('*/*/delete', ['id' => $this->getCookie()->getId()]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
/**
|
||||
* Plumrocket Inc.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the End-user License Agreement
|
||||
* that is available through the world-wide-web at this URL:
|
||||
* http://wiki.plumrocket.net/wiki/EULA
|
||||
* If you are unable to obtain it through the world-wide-web, please
|
||||
* send an email to support@plumrocket.com so we can send you a copy immediately.
|
||||
*
|
||||
* @package Plumrocket_CookieConsent
|
||||
* @copyright Copyright (c) 2020 Plumrocket Inc. (http://www.plumrocket.com)
|
||||
* @license http://wiki.plumrocket.net/wiki/EULA End-user License Agreement
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Plumrocket\CookieConsent\Block\Adminhtml\Cookie\Item\Edit\Button;
|
||||
|
||||
use Magento\Framework\View\Element\UiComponent\Context;
|
||||
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
|
||||
use Plumrocket\CookieConsent\Api\Data\CookieInterface;
|
||||
use Plumrocket\CookieConsent\Ui\Locator\CookieLocatorInterface;
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Generic implements ButtonProviderInterface
|
||||
{
|
||||
/**W
|
||||
* Url Builder
|
||||
*
|
||||
* @var Context
|
||||
*/
|
||||
protected $context;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Ui\Locator\CookieLocatorInterface
|
||||
*/
|
||||
private $cookieLocator;
|
||||
|
||||
/**
|
||||
* Generic constructor
|
||||
*
|
||||
* @param Context $context
|
||||
* @param \Plumrocket\CookieConsent\Ui\Locator\CookieLocatorInterface $cookieLocator
|
||||
*/
|
||||
public function __construct(
|
||||
Context $context,
|
||||
CookieLocatorInterface $cookieLocator
|
||||
) {
|
||||
$this->context = $context;
|
||||
$this->cookieLocator = $cookieLocator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate url by route and parameters
|
||||
*
|
||||
* @param string $route
|
||||
* @param array $params
|
||||
* @return string
|
||||
*/
|
||||
public function getUrl($route = '', $params = [])
|
||||
{
|
||||
return $this->context->getUrl($route, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Plumrocket\CookieConsent\Api\Data\CookieInterface
|
||||
* @throws \Magento\Framework\Exception\NotFoundException
|
||||
*/
|
||||
public function getCookie(): CookieInterface
|
||||
{
|
||||
return $this->cookieLocator->getCookie();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getButtonData()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
/**
|
||||
* Plumrocket Inc.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the End-user License Agreement
|
||||
* that is available through the world-wide-web at this URL:
|
||||
* http://wiki.plumrocket.net/wiki/EULA
|
||||
* If you are unable to obtain it through the world-wide-web, please
|
||||
* send an email to support@plumrocket.com so we can send you a copy immediately.
|
||||
*
|
||||
* @package Plumrocket_CookieConsent
|
||||
* @copyright Copyright (c) 2020 Plumrocket Inc. (http://www.plumrocket.com)
|
||||
* @license http://wiki.plumrocket.net/wiki/EULA End-user License Agreement
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Plumrocket\CookieConsent\Block\Adminhtml\Cookie\Item\Edit\Button;
|
||||
|
||||
use Magento\Ui\Component\Control\Container;
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Save extends Generic
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getButtonData(): array
|
||||
{
|
||||
return [
|
||||
'label' => __('Save'),
|
||||
'class' => 'save primary',
|
||||
'data_attribute' => [
|
||||
'mage-init' => [
|
||||
'buttonAdapter' => [
|
||||
'actions' => [
|
||||
[
|
||||
'targetName' => 'pr_cookie_item_form.pr_cookie_item_form',
|
||||
'actionName' => 'save',
|
||||
'params' => [
|
||||
false
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
],
|
||||
'class_name' => Container::SPLIT_BUTTON,
|
||||
'options' => $this->getOptions(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve options
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getOptions(): array
|
||||
{
|
||||
$options[] = [
|
||||
'id_hard' => 'save_and_close',
|
||||
'label' => __('Save & Close'),
|
||||
'data_attribute' => [
|
||||
'mage-init' => [
|
||||
'buttonAdapter' => [
|
||||
'actions' => [
|
||||
[
|
||||
'targetName' => 'pr_cookie_item_form.pr_cookie_item_form',
|
||||
'actionName' => 'save',
|
||||
'params' => [
|
||||
true
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
],
|
||||
];
|
||||
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Plumrocket_CookieConsent
|
||||
* @copyright Copyright (c) 2025 Plumrocket Inc. (https://plumrocket.com)
|
||||
* @license https://plumrocket.com/license End-user License Agreement
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Plumrocket\CookieConsent\Block\Adminhtml\System\Config\Form\ConsentTypes;
|
||||
|
||||
use Magento\Framework\View\Element\Context;
|
||||
use Magento\Framework\View\Element\Html\Select;
|
||||
use Plumrocket\CookieConsent\Model\Cookie\Attribute\Source\CategoryKey;
|
||||
|
||||
/**
|
||||
* @since 2.0.5
|
||||
*/
|
||||
class CookieCategorySelect extends Select
|
||||
{
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Model\Cookie\Attribute\Source\CategoryKey
|
||||
*/
|
||||
private $cookieCategory;
|
||||
|
||||
/**
|
||||
* @param \Magento\Framework\View\Element\Context $context
|
||||
* @param \Plumrocket\CookieConsent\Model\Cookie\Attribute\Source\CategoryKey $cookieCategory
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(
|
||||
Context $context,
|
||||
CategoryKey $cookieCategory,
|
||||
array $data = []
|
||||
) {
|
||||
$this->cookieCategory = $cookieCategory;
|
||||
parent::__construct($context, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set "name" for <select> element
|
||||
*
|
||||
* @param string $value
|
||||
* @return $this
|
||||
*/
|
||||
public function setInputName($value)
|
||||
{
|
||||
return $this->setName($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set "id" for <select> element
|
||||
*
|
||||
* @param string $value
|
||||
* @return $this
|
||||
*/
|
||||
public function setInputId($value)
|
||||
{
|
||||
return $this->setId($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render block HTML
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function _toHtml(): string
|
||||
{
|
||||
if (!$this->getOptions()) {
|
||||
$this->setOptions($this->getSourceOptions());
|
||||
}
|
||||
|
||||
return parent::_toHtml();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve cookie category options
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getSourceOptions(): array
|
||||
{
|
||||
return $this->cookieCategory->getAllOptions();
|
||||
}
|
||||
}
|
||||
+149
@@ -0,0 +1,149 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Plumrocket_CookieConsent
|
||||
* @copyright Copyright (c) 2025 Plumrocket Inc. (https://plumrocket.com)
|
||||
* @license https://plumrocket.com/license End-user License Agreement
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Plumrocket\CookieConsent\Block\Adminhtml\System\Config\Form\ConsentTypes;
|
||||
|
||||
use Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray;
|
||||
use Magento\Framework\DataObject;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
|
||||
/**
|
||||
* @since 2.0.5
|
||||
*/
|
||||
class MappingTable extends AbstractFieldArray
|
||||
{
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Block\Adminhtml\System\Config\Form\ConsentTypes\StatusSelect|null
|
||||
*/
|
||||
private $statusRenderer;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Block\Adminhtml\System\Config\Form\ConsentTypes\CookieCategorySelect|null
|
||||
*/
|
||||
private $cookieCategoryRender;
|
||||
|
||||
/**
|
||||
* Prepare rendering the new field by adding all the needed columns
|
||||
*/
|
||||
protected function _prepareToRender(): void
|
||||
{
|
||||
$this->addColumn('consent_type', ['label' => __('Consent Type'), 'class' => 'required-entry']);
|
||||
$this->addColumn('status', ['label' => __('Default Status'), 'renderer' => $this->getStatusRenderer()]);
|
||||
$this->addColumn(
|
||||
'cookie_category',
|
||||
['label' => __('Cookie Category'), 'renderer' => $this->getCookieCategoryRenderer()]
|
||||
);
|
||||
$this->_addAfter = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function renderCellTemplate($columnName)
|
||||
{
|
||||
$html = parent::renderCellTemplate($columnName);
|
||||
|
||||
if ($columnName === 'consent_type') {
|
||||
$doc = new \DOMDocument();
|
||||
$doc->loadHTML($html);
|
||||
$input = $doc->getElementsByTagName('input')[0];
|
||||
$input->setAttribute('readonly', '');
|
||||
$html = $doc->saveHTML($input);
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare existing row data object
|
||||
*
|
||||
* @param DataObject $row
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
protected function _prepareArrayRow(DataObject $row): void
|
||||
{
|
||||
$options = [];
|
||||
|
||||
$status = $row->getStatus();
|
||||
if ($status !== null) {
|
||||
$options['option_' . $this->getStatusRenderer()->calcOptionHash($status)] = 'selected="selected"';
|
||||
}
|
||||
|
||||
$cookieCategory = $row->getCookieCategory();
|
||||
if ($cookieCategory !== null) {
|
||||
$optionHash = $this->getCookieCategoryRenderer()->calcOptionHash($cookieCategory);
|
||||
$options['option_' . $optionHash] = 'selected="selected"';
|
||||
}
|
||||
|
||||
$row->setData('option_extra_attrs', $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function _toHtml(): string
|
||||
{
|
||||
$html = parent::_toHtml();
|
||||
$style = $this->getStyle();
|
||||
|
||||
return $html . $style;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve css styles
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getStyle(): string
|
||||
{
|
||||
$htmlId = '#' . $this->_escaper->escapeHtml($this->getElement()->getId());
|
||||
|
||||
return "<style>
|
||||
$htmlId tfoot, .col-actions {display: none;}
|
||||
</style>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve status column renderer
|
||||
*
|
||||
* @return \Plumrocket\CookieConsent\Block\Adminhtml\System\Config\Form\ConsentTypes\StatusSelect
|
||||
*/
|
||||
private function getStatusRenderer(): StatusSelect
|
||||
{
|
||||
if (! $this->statusRenderer) {
|
||||
$this->statusRenderer = $this->getLayout()
|
||||
->createBlock(
|
||||
StatusSelect::class,
|
||||
'',
|
||||
['data' => ['is_render_to_js_template' => true]]
|
||||
);
|
||||
}
|
||||
|
||||
return $this->statusRenderer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve cookie_category column renderer
|
||||
*
|
||||
* @return \Plumrocket\CookieConsent\Block\Adminhtml\System\Config\Form\ConsentTypes\CookieCategorySelect
|
||||
*/
|
||||
private function getCookieCategoryRenderer(): CookieCategorySelect
|
||||
{
|
||||
if (!$this->cookieCategoryRender) {
|
||||
$this->cookieCategoryRender = $this->getLayout()
|
||||
->createBlock(
|
||||
CookieCategorySelect::class,
|
||||
'',
|
||||
['data' => ['is_render_to_js_template' => true]]
|
||||
);
|
||||
}
|
||||
|
||||
return $this->cookieCategoryRender;
|
||||
}
|
||||
}
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Plumrocket_CookieConsent
|
||||
* @copyright Copyright (c) 2025 Plumrocket Inc. (https://plumrocket.com)
|
||||
* @license https://plumrocket.com/license End-user License Agreement
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Plumrocket\CookieConsent\Block\Adminhtml\System\Config\Form\ConsentTypes;
|
||||
|
||||
use Magento\Framework\View\Element\Html\Select;
|
||||
|
||||
/**
|
||||
* @since 2.0.5
|
||||
*/
|
||||
class StatusSelect extends Select
|
||||
{
|
||||
/**
|
||||
* Set "name" for <select> element
|
||||
*
|
||||
* @param string $value
|
||||
* @return $this
|
||||
*/
|
||||
public function setInputName($value)
|
||||
{
|
||||
return $this->setName($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set "id" for <select> element
|
||||
*
|
||||
* @param string $value
|
||||
* @return $this
|
||||
*/
|
||||
public function setInputId($value)
|
||||
{
|
||||
return $this->setId($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render block HTML
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function _toHtml(): string
|
||||
{
|
||||
if (!$this->getOptions()) {
|
||||
$this->setOptions($this->getSourceOptions());
|
||||
}
|
||||
|
||||
return parent::_toHtml();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve status options
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getSourceOptions(): array
|
||||
{
|
||||
return [
|
||||
['label' => __('Granted'), 'value' => 'granted'],
|
||||
['label' => __('Denied'), 'value' => 'denied'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
/**
|
||||
* Plumrocket Inc.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the End-user License Agreement
|
||||
* that is available through the world-wide-web at this URL:
|
||||
* http://wiki.plumrocket.net/wiki/EULA
|
||||
* If you are unable to obtain it through the world-wide-web, please
|
||||
* send an email to support@plumrocket.com so we can send you a copy immediately.
|
||||
*
|
||||
* @package Plumrocket_CookieConsent
|
||||
* @copyright Copyright (c) 2020 Plumrocket Inc. (http://www.plumrocket.com)
|
||||
* @license http://wiki.plumrocket.net/wiki/EULA End-user License Agreement
|
||||
*/
|
||||
|
||||
namespace Plumrocket\CookieConsent\Block\Adminhtml\System\Config\Form;
|
||||
|
||||
use Magento\Backend\Block\Template\Context;
|
||||
use Magento\Config\Block\System\Config\Form\Field;
|
||||
use Magento\Framework\App\RequestInterface;
|
||||
use Magento\Framework\Data\Form\Element\AbstractElement;
|
||||
|
||||
class Cookie extends Field
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\App\Request\Http
|
||||
*/
|
||||
private $request;
|
||||
|
||||
/**
|
||||
* Cookie constructor.
|
||||
*
|
||||
* @param \Magento\Backend\Block\Template\Context $context
|
||||
* @param \Magento\Framework\App\RequestInterface $request
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(
|
||||
Context $context,
|
||||
RequestInterface $request,
|
||||
array $data = []
|
||||
) {
|
||||
$this->request = $request;
|
||||
parent::__construct($context, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve element HTML markup
|
||||
* Argument $element must be specified
|
||||
* We need to extend parent method
|
||||
*
|
||||
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
|
||||
* @return string
|
||||
*/
|
||||
protected function _getElementHtml(AbstractElement $element)
|
||||
{
|
||||
$params = [];
|
||||
$websiteId = (int) $this->request->getParam('website', 0);
|
||||
$storeId = (int) $this->request->getParam('store', 0);
|
||||
|
||||
if ($websiteId) {
|
||||
$params['website'] = $websiteId;
|
||||
}
|
||||
|
||||
if ($storeId) {
|
||||
$params['store'] = $storeId;
|
||||
}
|
||||
|
||||
$url = $this->_urlBuilder->getUrl('adminhtml/system_config/edit/section/web', $params);
|
||||
|
||||
return __(
|
||||
'To Enable, <a href="%1" target="_blank">Click here</a>, then open "Default Cookie Settings" section and' .
|
||||
' set "Yes" next to the "Cookie Restriction Mode". Then save changes.',
|
||||
$url
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render inheritance checkbox (Use Default or Use Website)
|
||||
* Argument $element must be specified
|
||||
* We need to extend parent method
|
||||
*
|
||||
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
|
||||
* @return string
|
||||
*/
|
||||
protected function _renderInheritCheckbox(AbstractElement $element)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Plumrocket_CookieConsent
|
||||
* @copyright Copyright (c) 2022 Plumrocket Inc. (https://plumrocket.com)
|
||||
* @license https://plumrocket.com/license End-user License Agreement
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Plumrocket\CookieConsent\Block\Adminhtml\System\Config\Form;
|
||||
|
||||
use Plumrocket\CookieConsent\Block\Adminhtml\System\Config\Form\ConsentTypes\MappingTable;
|
||||
|
||||
/**
|
||||
* @since 1.5.0
|
||||
* @deprecated since 2.0.5
|
||||
* @see \Plumrocket\CookieConsent\Block\Adminhtml\System\Config\Form\ConsentTypes\MappingTable
|
||||
*/
|
||||
class GtmConsentMode extends MappingTable
|
||||
{
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Plumrocket_CookieConsent
|
||||
* @copyright Copyright (c) 2022 Plumrocket Inc. (https://plumrocket.com)
|
||||
* @license https://plumrocket.com/license End-user License Agreement
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Plumrocket\CookieConsent\Block\Adminhtml\System\Config\Form;
|
||||
|
||||
use Plumrocket\CookieConsent\Block\Adminhtml\System\Config\Form\ConsentTypes\CookieCategorySelect;
|
||||
|
||||
/**
|
||||
* @since 1.5.0
|
||||
* @deprecated since 2.0.5
|
||||
* @see \Plumrocket\CookieConsent\Block\Adminhtml\System\Config\Form\ConsentTypes\CookieCategorySelect
|
||||
*/
|
||||
class GtmConsentModeCookieCategory extends CookieCategorySelect
|
||||
{
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Plumrocket_CookieConsent
|
||||
* @copyright Copyright (c) 2022 Plumrocket Inc. (https://plumrocket.com)
|
||||
* @license https://plumrocket.com/license End-user License Agreement
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Plumrocket\CookieConsent\Block\Adminhtml\System\Config\Form;
|
||||
|
||||
use Plumrocket\CookieConsent\Block\Adminhtml\System\Config\Form\ConsentTypes\StatusSelect;
|
||||
|
||||
/**
|
||||
* @since 1.5.0
|
||||
* @deprecated since 2.0.5
|
||||
* @see \Plumrocket\CookieConsent\Block\Adminhtml\System\Config\Form\ConsentTypes\StatusSelect
|
||||
*/
|
||||
class GtmConsentModeStatus extends StatusSelect
|
||||
{
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Plumrocket_CookieConsent
|
||||
* @copyright Copyright (c) 2025 Plumrocket Inc. (https://plumrocket.com)
|
||||
* @license https://plumrocket.com/license End-user License Agreement
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Plumrocket\CookieConsent\Block\Adminhtml\System\Config\Form;
|
||||
|
||||
use Magento\Config\Block\System\Config\Form\Field;
|
||||
use Magento\Framework\Data\Form\Element\AbstractElement;
|
||||
|
||||
class UpgradeToProVersionNotice extends Field
|
||||
{
|
||||
protected $_template = 'Plumrocket_CookieConsent::system/config/upgrade_to_pro_version_notice.phtml';
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Data\Form\Element\AbstractElement
|
||||
*/
|
||||
private $element;
|
||||
|
||||
/**
|
||||
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
|
||||
* @return string
|
||||
*/
|
||||
public function render(AbstractElement $element): string
|
||||
{
|
||||
$this->setData('notice_intro', $element->getData('field_config/notice_intro'));
|
||||
$html = <<<HTML
|
||||
<td class="pr-cookie value pr-notice__content-wrapper" colspan="3">
|
||||
<div class="pr-notice__content">
|
||||
{$this->_getElementHtml($element)}
|
||||
</div>
|
||||
</td>
|
||||
HTML;
|
||||
return $this->_decorateRowHtml($element, $html);
|
||||
}
|
||||
|
||||
protected function _getElementHtml(AbstractElement $element): string
|
||||
{
|
||||
return $this->_toHtml();
|
||||
}
|
||||
|
||||
/**
|
||||
* Decorate field row html
|
||||
*
|
||||
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
|
||||
* @param string $html
|
||||
* @return string
|
||||
*/
|
||||
protected function _decorateRowHtml(AbstractElement $element, $html): string
|
||||
{
|
||||
return <<<HTML
|
||||
<tr id="row_{$element->getHtmlId()}" class="pr_notice pr_notice--note upgrade-to-pro pr-notice--full-width">
|
||||
{$html}
|
||||
</tr>
|
||||
HTML;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getNoticeIntro(): string
|
||||
{
|
||||
return $this->getData('notice_intro');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* Plumrocket Inc.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the End-user License Agreement
|
||||
* that is available through the world-wide-web at this URL:
|
||||
* http://wiki.plumrocket.net/wiki/EULA
|
||||
* If you are unable to obtain it through the world-wide-web, please
|
||||
* send an email to support@plumrocket.com so we can send you a copy immediately.
|
||||
*
|
||||
* @package Plumrocket_CookieConsent
|
||||
* @copyright Copyright (c) 2021 Plumrocket Inc. (http://www.plumrocket.com)
|
||||
* @license http://wiki.plumrocket.net/wiki/EULA End-user License Agreement
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Plumrocket\CookieConsent\Block\Adminhtml\System\Config\Form;
|
||||
|
||||
use Magento\Config\Block\System\Config\Form\Field;
|
||||
use Magento\Framework\Data\Form\Element\AbstractElement;
|
||||
|
||||
/**
|
||||
* @since 1.2.0
|
||||
*/
|
||||
class WidgetCode extends Field
|
||||
{
|
||||
/**
|
||||
* Make this field readonly
|
||||
*
|
||||
* Do it here because no possibility via system.xml
|
||||
*
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function _getElementHtml(AbstractElement $element)
|
||||
{
|
||||
$element->setReadonly(true);
|
||||
return parent::_getElementHtml($element);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
/**
|
||||
* Plumrocket Inc.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the End-user License Agreement
|
||||
* that is available through the world-wide-web at this URL:
|
||||
* http://wiki.plumrocket.net/wiki/EULA
|
||||
* If you are unable to obtain it through the world-wide-web, please
|
||||
* send an email to support@plumrocket.com so we can send you a copy immediately.
|
||||
*
|
||||
* @package Plumrocket_CookieConsent
|
||||
* @copyright Copyright (c) 2020 Plumrocket Inc. (http://www.plumrocket.com)
|
||||
* @license http://wiki.plumrocket.net/wiki/EULA End-user License Agreement
|
||||
*/
|
||||
|
||||
namespace Plumrocket\CookieConsent\Block;
|
||||
|
||||
use Magento\Cms\Model\Template\FilterProvider;
|
||||
use Magento\Framework\Serialize\SerializerInterface;
|
||||
use Magento\Framework\View\Element\Template;
|
||||
use Magento\Framework\View\Element\Template\Context;
|
||||
use Plumrocket\Base\Model\Utils\IsMatchUrl;
|
||||
use Plumrocket\CookieConsent\Helper\Config\CookieNotice as CookieNoticeConfig;
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class CookieNotice extends Template
|
||||
{
|
||||
public const COOKIE_NAME_STATUS = 'pr-cookie-notice-status';
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Serialize\SerializerInterface
|
||||
*/
|
||||
private $serializer;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\Base\Model\Utils\IsMatchUrl
|
||||
*/
|
||||
private $isMatchUrl;
|
||||
|
||||
/**
|
||||
* @var \Magento\Cms\Model\Template\FilterProvider
|
||||
*/
|
||||
private $filterProvider;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Helper\Config\CookieNotice
|
||||
*/
|
||||
private $cookieNoticeConfig;
|
||||
|
||||
/**
|
||||
* @param \Magento\Framework\View\Element\Template\Context $context
|
||||
* @param \Magento\Framework\Serialize\SerializerInterface $serializer
|
||||
* @param \Plumrocket\Base\Model\Utils\IsMatchUrl $isMatchUrl
|
||||
* @param \Magento\Cms\Model\Template\FilterProvider $filterProvider
|
||||
* @param \Plumrocket\CookieConsent\Helper\Config\CookieNotice $cookieNoticeConfig
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(
|
||||
Context $context,
|
||||
SerializerInterface $serializer,
|
||||
IsMatchUrl $isMatchUrl,
|
||||
FilterProvider $filterProvider,
|
||||
CookieNoticeConfig $cookieNoticeConfig,
|
||||
array $data = []
|
||||
) {
|
||||
parent::__construct($context, $data);
|
||||
$this->serializer = $serializer;
|
||||
$this->isMatchUrl = $isMatchUrl;
|
||||
$this->filterProvider = $filterProvider;
|
||||
$this->cookieNoticeConfig = $cookieNoticeConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getJsComponentConfig(): array
|
||||
{
|
||||
return [
|
||||
'displayStyle' => $this->cookieNoticeConfig->getDisplayStyle(),
|
||||
'acceptButtonConfig' => $this->prepareButtonConfig($this->cookieNoticeConfig->getAcceptButtonConfig()),
|
||||
'declineButtonConfig' => $this->prepareButtonConfig($this->cookieNoticeConfig->getDeclineButtonConfig()),
|
||||
'settingsButtonConfig' => $this->prepareButtonConfig($this->cookieNoticeConfig->getSettingsButtonConfig()),
|
||||
'statusCookieName' => self::COOKIE_NAME_STATUS,
|
||||
'noticeTitle' => $this->cookieNoticeConfig->getTitle(),
|
||||
'noticeTextHtml' => $this->filterProvider->getBlockFilter()->filter(
|
||||
$this->cookieNoticeConfig->getText()
|
||||
),
|
||||
'design' => [
|
||||
'titleColor' => $this->cookieNoticeConfig->getTitleColor(),
|
||||
'textColor' => $this->cookieNoticeConfig->getTextColor(),
|
||||
'backgroundColor' => $this->cookieNoticeConfig->getBackgroundColor(),
|
||||
'overlayBackgroundColor' => $this->cookieNoticeConfig->getOverlayBackgroundColor(),
|
||||
'overlayBlur' => $this->cookieNoticeConfig->getIsNeedBlurOverlay(),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isAllowedPage(): bool
|
||||
{
|
||||
return ! $this->isMatchUrl->executeList(
|
||||
$this->_urlBuilder->getCurrentUrl(),
|
||||
$this->cookieNoticeConfig->getUrlsToHide()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return false|string
|
||||
*/
|
||||
public function getJsLayout()
|
||||
{
|
||||
if (isset($this->jsLayout['components']['pr-cookie-notice'])) {
|
||||
$this->jsLayout['components']['pr-cookie-notice'] = array_merge_recursive(
|
||||
$this->jsLayout['components']['pr-cookie-notice'],
|
||||
$this->getJsComponentConfig()
|
||||
);
|
||||
} else {
|
||||
$this->jsLayout['components']['pr-cookie-notice'] = $this->getJsComponentConfig();
|
||||
}
|
||||
|
||||
return $this->jsLayout ? $this->serializer->serialize($this->jsLayout) : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $config
|
||||
* @return array
|
||||
*/
|
||||
private function prepareButtonConfig(array $config): array
|
||||
{
|
||||
if (isset($config['enabled'])) {
|
||||
$config['enabled'] = (bool) $config['enabled'];
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,196 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Plumrocket_CookieConsent
|
||||
* @copyright Copyright (c) 2020 Plumrocket Inc. (https://plumrocket.com)
|
||||
* @license https://plumrocket.com/license End-user License Agreement
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Plumrocket\CookieConsent\Block;
|
||||
|
||||
use Magento\Framework\Code\Minifier\Adapter\Js\JShrink;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Framework\Serialize\SerializerInterface;
|
||||
use Magento\Framework\View\Element\Template\Context;
|
||||
use Plumrocket\CookieConsent\Block\Html\HeadScripts;
|
||||
use Plumrocket\CookieConsent\Helper\Config;
|
||||
|
||||
/**
|
||||
* Google Tag Manager Page Block
|
||||
*/
|
||||
class Gtm extends HeadScripts
|
||||
{
|
||||
/**
|
||||
* @var Config
|
||||
*/
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* @var SerializerInterface
|
||||
*/
|
||||
private $serializer;
|
||||
|
||||
/**
|
||||
* @param \Magento\Framework\View\Element\Template\Context $context
|
||||
* @param \Plumrocket\CookieConsent\Helper\Config $config
|
||||
* @param \Magento\Framework\Serialize\SerializerInterface $serializer
|
||||
* @param \Magento\Framework\Code\Minifier\Adapter\Js\JShrink $jsMinifier
|
||||
* @param \Magento\Framework\ObjectManagerInterface $objectManager
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(
|
||||
Context $context,
|
||||
Config $config,
|
||||
SerializerInterface $serializer,
|
||||
JShrink $jsMinifier,
|
||||
ObjectManagerInterface $objectManager,
|
||||
array $data = []
|
||||
) {
|
||||
parent::__construct(
|
||||
$context,
|
||||
$jsMinifier,
|
||||
$objectManager,
|
||||
$data
|
||||
);
|
||||
$this->config = $config;
|
||||
$this->serializer = $serializer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render GTM tracking scripts
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _toHtml()
|
||||
{
|
||||
if (! $this->config->isGtmEnabled()) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return parent::_toHtml();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return cookie restriction mode value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getGtmContainerId(): string
|
||||
{
|
||||
return $this->config->getGtmContainerId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getGtmServerBaseUrl(): string
|
||||
{
|
||||
return $this->config->getGtmServerBaseUrl();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return cookie restriction mode value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getGmtAssociatedCategoryKey(): string
|
||||
{
|
||||
return $this->config->getGmtAssociatedCategoryKey();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if consent mode enabled
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function isConsentModeEnabled(): int
|
||||
{
|
||||
return (int) $this->config->isGtmConsentModeEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve consent types default status
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDefaultConsentTypesStatus(): string
|
||||
{
|
||||
$result = [];
|
||||
|
||||
if ($this->isConsentModeEnabled()) {
|
||||
foreach ($this->config->getGtmConsentTypesConfig() as $config) {
|
||||
$result[$config['consent_type']] = $config['status'];
|
||||
}
|
||||
}
|
||||
|
||||
return $this->serializer->serialize($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve consent types default status
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDefaultConsentStatus(): array
|
||||
{
|
||||
$result = [];
|
||||
if ($this->isConsentModeEnabled()) {
|
||||
foreach ($this->config->getGtmConsentTypesConfig() as $config) {
|
||||
$result[$config['consent_type']] = $config['status'];
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve cookie categories assigned to the consent types
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getConsentTypesCategories(): string
|
||||
{
|
||||
$result = [];
|
||||
|
||||
if ($this->isConsentModeEnabled()) {
|
||||
foreach ($this->config->getGtmConsentTypesConfig() as $config) {
|
||||
$result[$config['consent_type']] = $config['cookie_category'];
|
||||
}
|
||||
}
|
||||
|
||||
return $this->serializer->serialize($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cookie categories to consent types mapping.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCategoriesMapping(): array
|
||||
{
|
||||
$result = [];
|
||||
if ($this->isConsentModeEnabled()) {
|
||||
foreach ($this->config->getGtmConsentTypesConfig() as $config) {
|
||||
$result[$config['consent_type']] = $config['cookie_category'];
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get serialized config.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getJsonConfig(): string
|
||||
{
|
||||
return $this->serializer->serialize([
|
||||
'categoryKey' => $this->getGmtAssociatedCategoryKey(),
|
||||
'containerId' => $this->getGtmContainerId(),
|
||||
'consentMode' => $this->isConsentModeEnabled(),
|
||||
'defaultConsentTypes' => $this->getDefaultConsentStatus(),
|
||||
'consentTypesCategories' => $this->getCategoriesMapping()
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
/**
|
||||
* Plumrocket Inc.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the End-user License Agreement
|
||||
* that is available through the world-wide-web at this URL:
|
||||
* http://wiki.plumrocket.net/wiki/EULA
|
||||
* If you are unable to obtain it through the world-wide-web, please
|
||||
* send an email to support@plumrocket.com so we can send you a copy immediately.
|
||||
*
|
||||
* @package Plumrocket_CookieConsent
|
||||
* @copyright Copyright (c) 2020 Plumrocket Inc. (http://www.plumrocket.com)
|
||||
* @license http://wiki.plumrocket.net/wiki/EULA End-user License Agreement
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Plumrocket\CookieConsent\Block\Html;
|
||||
|
||||
use Magento\Framework\View\Element\Template;
|
||||
use Magento\Framework\View\Element\Template\Context;
|
||||
use Plumrocket\CookieConsent\Api\Data\CategoryInterface;
|
||||
use Plumrocket\CookieConsent\Model\Category\GetCategoriesWithScripts;
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class BodyScripts extends Template
|
||||
{
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Model\Category\GetCategoriesWithScripts
|
||||
*/
|
||||
private $getCategoriesWithScripts;
|
||||
|
||||
/**
|
||||
* @param \Magento\Framework\View\Element\Template\Context $context
|
||||
* @param \Plumrocket\CookieConsent\Model\Category\GetCategoriesWithScripts $getCategoriesWithScripts
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(
|
||||
Context $context,
|
||||
GetCategoriesWithScripts $getCategoriesWithScripts,
|
||||
array $data = []
|
||||
) {
|
||||
parent::__construct($context, $data);
|
||||
$this->getCategoriesWithScripts = $getCategoriesWithScripts;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Plumrocket\CookieConsent\Api\Data\CategoryInterface[]
|
||||
*/
|
||||
public function getEssentialCategoriesWithScripts(): array
|
||||
{
|
||||
return array_filter(
|
||||
$this->getCategoriesWithScripts->execute(),
|
||||
static function (CategoryInterface $category) {
|
||||
return $category->isEssential();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Plumrocket\CookieConsent\Api\Data\CategoryInterface[]
|
||||
*/
|
||||
public function getOptionalCategoriesWithScripts(): array
|
||||
{
|
||||
return array_filter(
|
||||
$this->getCategoriesWithScripts->execute(),
|
||||
static function (CategoryInterface $category) {
|
||||
return ! $category->isEssential();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $html
|
||||
* @return string
|
||||
*/
|
||||
public function prepareHtml(string $html): string
|
||||
{
|
||||
return str_replace(
|
||||
['\'', '<script', '</script>', "\n","\t","\r", ],
|
||||
['\\\'', '<scr\' + \'ipt', '</scr\' + \'ipt>', ' ', ' ', ' ', ],
|
||||
$html
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
/**
|
||||
* Plumrocket Inc.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the End-user License Agreement
|
||||
* that is available through the world-wide-web at this URL:
|
||||
* http://wiki.plumrocket.net/wiki/EULA
|
||||
* If you are unable to obtain it through the world-wide-web, please
|
||||
* send an email to support@plumrocket.com so we can send you a copy immediately.
|
||||
*
|
||||
* @package Plumrocket_CookieConsent
|
||||
* @copyright Copyright (c) 2021 Plumrocket Inc. (http://www.plumrocket.com)
|
||||
* @license http://wiki.plumrocket.net/wiki/EULA End-user License Agreement
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Plumrocket\CookieConsent\Block\Html;
|
||||
|
||||
use Magento\Framework\View\Element\Html\Link;
|
||||
use Magento\Framework\View\Element\Template\Context;
|
||||
use Plumrocket\CookieConsent\Api\CanManageCookieInterface;
|
||||
|
||||
/**
|
||||
* @since 1.2.0
|
||||
*/
|
||||
class CookieSettingsLink extends Link
|
||||
{
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Api\CanManageCookieInterface
|
||||
*/
|
||||
private $canManageCookie;
|
||||
|
||||
/**
|
||||
* @param \Magento\Framework\View\Element\Template\Context $context
|
||||
* @param \Plumrocket\CookieConsent\Api\CanManageCookieInterface $canManageCookie
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(
|
||||
Context $context,
|
||||
CanManageCookieInterface $canManageCookie,
|
||||
array $data = []
|
||||
) {
|
||||
parent::__construct($context, $data);
|
||||
$this->canManageCookie = $canManageCookie;
|
||||
}
|
||||
|
||||
/**
|
||||
* Need to overwrite parent method to avoid build the URL
|
||||
*
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getHref(): string
|
||||
{
|
||||
return $this->getPath();
|
||||
}
|
||||
|
||||
/**
|
||||
* If customer cannot manage cookie we should not show link
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _toHtml()
|
||||
{
|
||||
if (! $this->canManageCookie->execute()) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return parent::_toHtml();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Plumrocket_CookieConsent
|
||||
* @copyright Copyright (c) 2025 Plumrocket Inc. (https://plumrocket.com)
|
||||
* @license https://plumrocket.com/license End-user License Agreement
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Plumrocket\CookieConsent\Block\Html;
|
||||
|
||||
use Magento\Framework\Code\Minifier\Adapter\Js\JShrink;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Framework\View\Element\Template;
|
||||
use Magento\Framework\View\Element\Template\Context;
|
||||
use Magento\Framework\View\Helper\SecureHtmlRenderer;
|
||||
|
||||
/**
|
||||
* @since 2.0.4
|
||||
*/
|
||||
class HeadScripts extends Template
|
||||
{
|
||||
public const SCRIPT_TAG_REPLACEMENT = 'prcookie-head-script';
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Code\Minifier\Adapter\Js\JShrink
|
||||
*/
|
||||
private $jsMinifier;
|
||||
|
||||
/**
|
||||
* @param \Magento\Framework\View\Element\Template\Context $context
|
||||
* @param \Magento\Framework\Code\Minifier\Adapter\Js\JShrink $jsMinifier
|
||||
* @param \Magento\Framework\ObjectManagerInterface $objectManager
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(
|
||||
Context $context,
|
||||
JShrink $jsMinifier,
|
||||
ObjectManagerInterface $objectManager,
|
||||
array $data = []
|
||||
) {
|
||||
parent::__construct($context, $data);
|
||||
$this->jsMinifier = $jsMinifier;
|
||||
|
||||
/**
|
||||
* @TODO Refactor when leave support of Magento 2.3.7 and less
|
||||
*/
|
||||
$this->secureHtmlRenderer = class_exists(SecureHtmlRenderer::class)
|
||||
? $objectManager->get(SecureHtmlRenderer::class)
|
||||
: null;
|
||||
}
|
||||
|
||||
protected function _toHtml()
|
||||
{
|
||||
$html = parent::_toHtml();
|
||||
|
||||
preg_match_all('/<script[\s\S]*?\/script>/', $html, $scriptTags);
|
||||
$scriptTags = array_shift($scriptTags);
|
||||
foreach ($scriptTags as $scriptTag) {
|
||||
try {
|
||||
$modifiedScriptTag = $this->modifyScriptTag($scriptTag);
|
||||
} catch (\Exception $e) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$html = str_replace($scriptTag, $modifiedScriptTag, $html);
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify script tag to prevent from being moved to footer
|
||||
*
|
||||
* @param string $scriptTag
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function modifyScriptTag(string $scriptTag): string
|
||||
{
|
||||
/**
|
||||
* @TODO Refactor when leave support of Magento 2.3.7 and less
|
||||
*/
|
||||
if (! $this->secureHtmlRenderer) {
|
||||
preg_match('#<script[\s\S]*?>([^`]*?)<\/script>#', $scriptTag, $matches);
|
||||
|
||||
if(isset($matches[1])) {
|
||||
$originalTagContent = $matches[1];
|
||||
$minifiedContent = $this->jsMinifier->minify($originalTagContent);
|
||||
$scriptTag = str_replace($originalTagContent, $minifiedContent, $scriptTag);
|
||||
}
|
||||
|
||||
return str_replace(
|
||||
['<script', '/script>'],
|
||||
['<' . self::SCRIPT_TAG_REPLACEMENT, '/'.self::SCRIPT_TAG_REPLACEMENT.'>'],
|
||||
$scriptTag
|
||||
);
|
||||
}
|
||||
|
||||
$doc = new \DOMDocument();
|
||||
$doc->loadHTML($scriptTag);
|
||||
$scriptNode = $doc->getElementsByTagName('script')->item(0);
|
||||
|
||||
$tagAttributes = array_column(iterator_to_array($scriptNode->attributes), 'nodeValue', 'name');
|
||||
$tagContent = $this->jsMinifier->minify($scriptNode->textContent);
|
||||
|
||||
return $this->secureHtmlRenderer->renderTag(self::SCRIPT_TAG_REPLACEMENT, $tagAttributes, $tagContent, false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,232 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Plumrocket_CookieConsent
|
||||
* @copyright Copyright (c) 2020 Plumrocket Inc. (https://plumrocket.com)
|
||||
* @license https://plumrocket.com/license End-user License Agreement
|
||||
*/
|
||||
|
||||
namespace Plumrocket\CookieConsent\Block;
|
||||
|
||||
use Magento\Cookie\Helper\Cookie as CookieHelper;
|
||||
use Magento\Customer\Model\Context as HttpContext;
|
||||
use Magento\Customer\Model\GroupManagement;
|
||||
use Magento\Framework\Serialize\SerializerInterface;
|
||||
use Magento\Framework\Session\Config\ConfigInterface;
|
||||
use Magento\Framework\View\Element\Template;
|
||||
use Magento\Framework\View\Element\Template\Context;
|
||||
use Plumrocket\CookieConsent\Api\CanManageCookieInterface;
|
||||
use Plumrocket\CookieConsent\Api\GetCookieToCategoryMappingInterface;
|
||||
use Plumrocket\CookieConsent\Api\GetEssentialCategoryKeysInterface;
|
||||
use Plumrocket\CookieConsent\Helper\Config;
|
||||
use Plumrocket\CookieConsent\Model\Cookie\Name\ToRegex;
|
||||
use Plumrocket\CookieConsent\Model\Cookie\ParentDomain;
|
||||
use Plumrocket\CookieConsent\Model\ResourceModel\Cookie\GetDynamicNames;
|
||||
use Plumrocket\CookieConsent\ViewModel\CookieProvider;
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class RestrictionConfig extends Template
|
||||
{
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Helper\Config
|
||||
*/
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Api\GetEssentialCategoryKeysInterface
|
||||
*/
|
||||
private $getEssentialCategoryKeys;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Api\GetCookieToCategoryMappingInterface
|
||||
*/
|
||||
private $getCookieToCategoryMapping;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Serialize\SerializerInterface
|
||||
*/
|
||||
private $serializer;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Api\CanManageCookieInterface
|
||||
*/
|
||||
private $canManageCookie;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\App\Http\Context
|
||||
*/
|
||||
private $httpContext;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Session\Config\ConfigInterface
|
||||
*/
|
||||
private $cookieConfig;
|
||||
|
||||
/**
|
||||
* @var \Magento\Cookie\Helper\Cookie
|
||||
*/
|
||||
private $cookieConfigHelper;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Model\ResourceModel\Cookie\GetDynamicNames
|
||||
*/
|
||||
private $getDynamicNames;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Model\Cookie\Name\ToRegex
|
||||
*/
|
||||
private $toRegex;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\ViewModel\CookieProvider
|
||||
*/
|
||||
private $cookieProvider;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Model\Cookie\ParentDomain
|
||||
*/
|
||||
private $parentDomain;
|
||||
|
||||
/**
|
||||
* Mapping constructor.
|
||||
*
|
||||
* @param \Magento\Framework\View\Element\Template\Context $context
|
||||
* @param \Plumrocket\CookieConsent\Helper\Config $config
|
||||
* @param \Plumrocket\CookieConsent\Api\GetEssentialCategoryKeysInterface $getEssentialCategoryKeys
|
||||
* @param \Plumrocket\CookieConsent\Api\GetCookieToCategoryMappingInterface $getCookieToCategoryMapping
|
||||
* @param \Magento\Framework\Serialize\SerializerInterface $serializer
|
||||
* @param \Plumrocket\CookieConsent\Api\CanManageCookieInterface $canManageCookie
|
||||
* @param \Magento\Framework\App\Http\Context $httpContext
|
||||
* @param \Magento\Framework\Session\Config\ConfigInterface $cookieConfig
|
||||
* @param \Magento\Cookie\Helper\Cookie $cookieConfigHelper
|
||||
* @param \Plumrocket\CookieConsent\Model\ResourceModel\Cookie\GetDynamicNames $getDynamicNames
|
||||
* @param \Plumrocket\CookieConsent\Model\Cookie\Name\ToRegex $toRegex
|
||||
* @param \Plumrocket\CookieConsent\ViewModel\CookieProvider $cookieProvider
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(
|
||||
Context $context,
|
||||
Config $config,
|
||||
GetEssentialCategoryKeysInterface $getEssentialCategoryKeys,
|
||||
GetCookieToCategoryMappingInterface $getCookieToCategoryMapping,
|
||||
SerializerInterface $serializer,
|
||||
CanManageCookieInterface $canManageCookie,
|
||||
\Magento\Framework\App\Http\Context $httpContext,
|
||||
ConfigInterface $cookieConfig,
|
||||
CookieHelper $cookieConfigHelper,
|
||||
GetDynamicNames $getDynamicNames,
|
||||
ParentDomain $parentDomain,
|
||||
ToRegex $toRegex,
|
||||
CookieProvider $cookieProvider,
|
||||
array $data = []
|
||||
) {
|
||||
parent::__construct($context, $data);
|
||||
$this->config = $config;
|
||||
$this->serializer = $serializer;
|
||||
$this->getEssentialCategoryKeys = $getEssentialCategoryKeys;
|
||||
$this->getCookieToCategoryMapping = $getCookieToCategoryMapping;
|
||||
$this->canManageCookie = $canManageCookie;
|
||||
$this->httpContext = $httpContext;
|
||||
$this->cookieConfig = $cookieConfig;
|
||||
$this->cookieConfigHelper = $cookieConfigHelper;
|
||||
$this->getDynamicNames = $getDynamicNames;
|
||||
$this->toRegex = $toRegex;
|
||||
$this->cookieProvider = $cookieProvider;
|
||||
$this->parentDomain = $parentDomain;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get configurations for restriction.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getRestrictionConfig(): array
|
||||
{
|
||||
return [
|
||||
'canManageCookie' => null,
|
||||
'canManageCookieApiUrl' => $this->getBaseUrl() . 'rest/V1/pr_cookie/can-manage-cookie',
|
||||
'canUseCookieBeforeOptIn' => $this->config->canUseCookieBeforeOptIn(),
|
||||
'canBlockUnknownCookie' => $this->config->canBlockUnknownCookie(),
|
||||
'consent' => [
|
||||
'isLoggedIn' => $this->isLoggedIn(),
|
||||
'logUrl' => $this->isLoggedIn()
|
||||
? $this->getCustomerConsentUpdateUrl()
|
||||
: $this->getGuestConsentUpdateUrl(),
|
||||
'reloadAfterAccept' => $this->config->reloadAfterAccept(),
|
||||
'reloadAfterDecline' => $this->config->reloadAfterDecline(),
|
||||
'expiry' => $this->config->getConsentExpiry(),
|
||||
],
|
||||
'cookie' => [
|
||||
'path' => $this->cookieConfig->getCookiePath(),
|
||||
'domain' => $this->cookieConfig->getCookieDomain(),
|
||||
'parentDomain' => $this->parentDomain->resolve($this->cookieConfig->getCookieDomain()),
|
||||
],
|
||||
'cookies' => $this->getCookieData(),
|
||||
'mage' => [
|
||||
'website' => (int) $this->_storeManager->getWebsite()->getId(),
|
||||
'cookieName' => CookieHelper::IS_USER_ALLOWED_SAVE_COOKIE,
|
||||
'lifetime' => $this->cookieConfigHelper->getCookieRestrictionLifetime(),
|
||||
],
|
||||
'cookieToCategoryMapping' => $this->getCookieToCategoryMapping->execute(),
|
||||
'essentialCategoryKeys' => $this->getEssentialCategoryKeys->execute(),
|
||||
'dynamicNamesPatterns' => $this->toRegex->execute($this->getDynamicNames->execute()),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve serialized config.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSerializedRestrictionConfig(): string
|
||||
{
|
||||
return $this->serializer->serialize($this->getRestrictionConfig());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if customer is logged in.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isLoggedIn(): bool
|
||||
{
|
||||
return GroupManagement::NOT_LOGGED_IN_ID !== $this->httpContext->getValue(HttpContext::CONTEXT_GROUP);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get url for customer update.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCustomerConsentUpdateUrl(): string
|
||||
{
|
||||
return $this->getUrl('pr_cookie/consent_customer/update');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get url for guest update.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getGuestConsentUpdateUrl(): string
|
||||
{
|
||||
return $this->getUrl('pr_cookie/consent_guest/update');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cookie details.
|
||||
*
|
||||
* @return array[]
|
||||
*/
|
||||
private function getCookieData(): array
|
||||
{
|
||||
$result = [];
|
||||
foreach ($this->cookieProvider->get() as $cookie) {
|
||||
$result[$cookie->getName()] = [
|
||||
'domain' => $cookie->getDomain()
|
||||
];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Plumrocket_CookieConsent
|
||||
* @copyright Copyright (c) 2020 Plumrocket Inc. (https://plumrocket.com)
|
||||
* @license https://plumrocket.com/license End-user License Agreement
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Plumrocket\CookieConsent\Block;
|
||||
|
||||
use Magento\Cms\Model\Template\FilterProvider;
|
||||
use Magento\Framework\Serialize\SerializerInterface;
|
||||
use Magento\Framework\View\Element\Template;
|
||||
use Magento\Framework\View\Element\Template\Context;
|
||||
use Plumrocket\CookieConsent\Api\CanManageCookieInterface;
|
||||
use Plumrocket\CookieConsent\Api\Data\CategoryInterface;
|
||||
use Plumrocket\CookieConsent\Api\Data\CookieInterface;
|
||||
use Plumrocket\CookieConsent\Helper\Config\SettingsBar as SettingsBarConfig;
|
||||
use Plumrocket\CookieConsent\ViewModel\CategoryProvider;
|
||||
use Plumrocket\CookieConsent\ViewModel\CookieProvider;
|
||||
use Plumrocket\CookieConsent\ViewModel\ExtractCategoryData;
|
||||
use Plumrocket\CookieConsent\ViewModel\ExtractCookieData;
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Settings extends Template
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\Serialize\SerializerInterface
|
||||
*/
|
||||
private $serializer;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\ViewModel\ExtractCookieData
|
||||
*/
|
||||
private $extractCookieData;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\ViewModel\ExtractCategoryData
|
||||
*/
|
||||
private $extractCategoryData;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Helper\Config\SettingsBar
|
||||
*/
|
||||
private $settingsBarConfig;
|
||||
|
||||
/**
|
||||
* @var \Magento\Cms\Model\Template\FilterProvider
|
||||
*/
|
||||
private $filterProvider;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\ViewModel\CategoryProvider
|
||||
*/
|
||||
private $categoryProvider;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\ViewModel\CookieProvider
|
||||
*/
|
||||
private $cookieProvider;
|
||||
|
||||
/**
|
||||
* @param \Magento\Framework\View\Element\Template\Context $context
|
||||
* @param \Magento\Framework\Serialize\SerializerInterface $serializer
|
||||
* @param \Plumrocket\CookieConsent\ViewModel\ExtractCookieData $extractCookieData
|
||||
* @param \Plumrocket\CookieConsent\ViewModel\ExtractCategoryData $extractCategoryData
|
||||
* @param \Plumrocket\CookieConsent\Helper\Config\SettingsBar $settingsBarConfig
|
||||
* @param \Magento\Cms\Model\Template\FilterProvider $filterProvider
|
||||
* @param \Plumrocket\CookieConsent\ViewModel\CategoryProvider $categoryProvider
|
||||
* @param \Plumrocket\CookieConsent\ViewModel\CookieProvider $cookieProvider
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(
|
||||
Context $context,
|
||||
SerializerInterface $serializer,
|
||||
ExtractCookieData $extractCookieData,
|
||||
ExtractCategoryData $extractCategoryData,
|
||||
SettingsBarConfig $settingsBarConfig,
|
||||
FilterProvider $filterProvider,
|
||||
CategoryProvider $categoryProvider,
|
||||
CookieProvider $cookieProvider,
|
||||
array $data = []
|
||||
) {
|
||||
parent::__construct($context, $data);
|
||||
$this->serializer = $serializer;
|
||||
$this->extractCookieData = $extractCookieData;
|
||||
$this->extractCategoryData = $extractCategoryData;
|
||||
$this->settingsBarConfig = $settingsBarConfig;
|
||||
$this->filterProvider = $filterProvider;
|
||||
$this->categoryProvider = $categoryProvider;
|
||||
$this->cookieProvider = $cookieProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get configurations for setting panel.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getJsComponentConfig(): array
|
||||
{
|
||||
return [
|
||||
'categories' => $this->getCategoriesData(),
|
||||
'cookies' => $this->getCookiesData(),
|
||||
'displayStyle' => $this->settingsBarConfig->getDisplayStyle(),
|
||||
'canShowCookieDetails' => $this->settingsBarConfig->canShowCookieDetails(),
|
||||
'overview' => [
|
||||
'title' => $this->settingsBarConfig->getOverviewTitle(),
|
||||
'text' => $this->filterProvider->getPageFilter()->filter($this->settingsBarConfig->getOverviewText()),
|
||||
],
|
||||
'consentPreferences' => [
|
||||
'header' => __($this->settingsBarConfig->getConsentPreferencesHeader()),
|
||||
'essential_category_status' => __($this->settingsBarConfig->getEssentialCategoryStatus()),
|
||||
'cookie_details_link' => __($this->settingsBarConfig->getCookieDetailsLinkTitle()),
|
||||
],
|
||||
'design' => [
|
||||
'textColor' => $this->settingsBarConfig->getTextColor(),
|
||||
'backgroundColor' => $this->settingsBarConfig->getBackgroundColor(),
|
||||
],
|
||||
'acceptButtonConfig' => $this->prepareButtonConfig($this->settingsBarConfig->getAcceptButtonConfig()),
|
||||
'declineButtonConfig' => $this->prepareButtonConfig($this->settingsBarConfig->getDeclineButtonConfig()),
|
||||
'confirmButtonConfig' => $this->prepareButtonConfig($this->settingsBarConfig->getConfirmButtonConfig()),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get js layout.
|
||||
*
|
||||
* @return false|string
|
||||
*/
|
||||
public function getJsLayout()
|
||||
{
|
||||
if (isset($this->jsLayout['components']['pr-cookie-settings-bar'])) {
|
||||
$this->jsLayout['components']['pr-cookie-settings-bar'] = array_merge_recursive(
|
||||
$this->jsLayout['components']['pr-cookie-settings-bar'],
|
||||
$this->getJsComponentConfig()
|
||||
);
|
||||
} else {
|
||||
$this->jsLayout['components']['pr-cookie-settings-bar'] = $this->getJsComponentConfig();
|
||||
}
|
||||
|
||||
return $this->jsLayout ? $this->serializer->serialize($this->jsLayout) : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get categories data for render.
|
||||
*
|
||||
* @return array[]
|
||||
*/
|
||||
private function getCategoriesData(): array
|
||||
{
|
||||
$extractCategoryData = $this->extractCategoryData;
|
||||
return array_values(array_map(static function (CategoryInterface $category) use ($extractCategoryData) {
|
||||
return $extractCategoryData->execute($category);
|
||||
}, $this->categoryProvider->get()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cookie data for render.
|
||||
*
|
||||
* @return array[]
|
||||
*/
|
||||
private function getCookiesData(): array
|
||||
{
|
||||
$extractCookieData = $this->extractCookieData;
|
||||
return array_values(array_map(static function (CookieInterface $cookie) use ($extractCookieData) {
|
||||
return $extractCookieData->execute($cookie);
|
||||
}, $this->cookieProvider->get()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Correct button config.
|
||||
*
|
||||
* @param array $config
|
||||
* @return array
|
||||
*/
|
||||
private function prepareButtonConfig(array $config): array
|
||||
{
|
||||
if (isset($config['enabled'])) {
|
||||
$config['enabled'] = (bool) $config['enabled'];
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
/**
|
||||
* Plumrocket Inc.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the End-user License Agreement
|
||||
* that is available through the world-wide-web at this URL:
|
||||
* http://wiki.plumrocket.net/wiki/EULA
|
||||
* If you are unable to obtain it through the world-wide-web, please
|
||||
* send an email to support@plumrocket.com so we can send you a copy immediately.
|
||||
*
|
||||
* @package Plumrocket_CookieConsent
|
||||
* @copyright Copyright (c) 2021 Plumrocket Inc. (http://www.plumrocket.com)
|
||||
* @license http://wiki.plumrocket.net/wiki/EULA End-user License Agreement
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Plumrocket\CookieConsent\Block\Widget;
|
||||
|
||||
use Magento\Framework\View\Element\Template;
|
||||
use Magento\Framework\View\Element\Template\Context;
|
||||
use Magento\Widget\Block\BlockInterface;
|
||||
use Plumrocket\CookieConsent\Api\CanManageCookieInterface;
|
||||
|
||||
/**
|
||||
* @since 1.2.0
|
||||
*/
|
||||
class CookieSettingsButton extends Template implements BlockInterface
|
||||
{
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Api\CanManageCookieInterface
|
||||
*/
|
||||
private $canManageCookie;
|
||||
|
||||
/**
|
||||
* @param \Magento\Framework\View\Element\Template\Context $context
|
||||
* @param \Plumrocket\CookieConsent\Api\CanManageCookieInterface $canManageCookie
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(
|
||||
Context $context,
|
||||
CanManageCookieInterface $canManageCookie,
|
||||
array $data = []
|
||||
) {
|
||||
parent::__construct($context, $data);
|
||||
$this->canManageCookie = $canManageCookie;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle(): string
|
||||
{
|
||||
return $this->_getData('title') ?: 'Cookie Settings';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function _toHtml(): string
|
||||
{
|
||||
if (! $this->canManageCookie->execute()) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return (string) parent::_toHtml();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user