ltsecurityinc安防产品在线商城代码
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
<?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\Model;
|
||||
|
||||
use Magento\Framework\View\Element\Block\ArgumentInterface;
|
||||
use Plumrocket\CookieConsent\Api\CanManageCookieInterface;
|
||||
use Plumrocket\CookieConsent\Helper\Config;
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class CanManageCookie implements CanManageCookieInterface, ArgumentInterface
|
||||
{
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Helper\Config
|
||||
*/
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* @param \Plumrocket\CookieConsent\Helper\Config $config
|
||||
*/
|
||||
public function __construct(Config $config)
|
||||
{
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function execute(): bool
|
||||
{
|
||||
return $this->config->isModuleEnabled();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,228 @@
|
||||
<?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\Model;
|
||||
|
||||
use Magento\Catalog\Model\AbstractModel as CatalogAbstractModel;
|
||||
use Magento\Framework\DataObject\IdentityInterface;
|
||||
use Plumrocket\CookieConsent\Api\Data\CategoryInterface;
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
* @method $this setData($key, $value = null)
|
||||
*/
|
||||
class Category extends CatalogAbstractModel implements IdentityInterface, CategoryInterface
|
||||
{
|
||||
public const ENTITY = 'pr_cookie_category';
|
||||
|
||||
public const CACHE_TAG = 'pr_cookie_category';
|
||||
|
||||
/**
|
||||
* Prefix of model events names
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_eventPrefix = 'pr_cookie_category';
|
||||
|
||||
/**
|
||||
* Parameter name in event
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_eventObject = 'category';
|
||||
|
||||
/**
|
||||
* Model cache tag for clear cache in after save and after delete
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_cacheTag = self::CACHE_TAG;
|
||||
|
||||
/**
|
||||
* Initialize resources
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _construct()
|
||||
{
|
||||
$this->_init(ResourceModel\Category::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return (int) parent::getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get identities
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getIdentities(): array
|
||||
{
|
||||
return [self::CACHE_TAG . '_' . $this->getId()];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function isEnabled(): bool
|
||||
{
|
||||
return (bool) $this->getData(self::STATUS);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setStatus(bool $status): CategoryInterface
|
||||
{
|
||||
return $this->setData(self::STATUS, $status);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function isPreChecked(): bool
|
||||
{
|
||||
return (bool) $this->getData(self::IS_PRE_CHECKED);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setIsPreChecked(bool $flag): CategoryInterface
|
||||
{
|
||||
return $this->setData(self::IS_PRE_CHECKED, $flag);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function isEssential(): bool
|
||||
{
|
||||
return (bool) $this->getData(self::IS_ESSENTIAL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setIsEssential(bool $isEssential): CategoryInterface
|
||||
{
|
||||
return $this->setData(self::IS_ESSENTIAL, $isEssential);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getKey(): string
|
||||
{
|
||||
return (string) $this->getData(self::KEY);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setKey(string $key): CategoryInterface
|
||||
{
|
||||
return $this->setData(self::KEY, $key);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return (string) $this->getData(self::NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setName(string $name): CategoryInterface
|
||||
{
|
||||
return $this->setData(self::NAME, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getDescription(): string
|
||||
{
|
||||
return (string) $this->getData(self::DESCRIPTION);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setDescription(string $description): CategoryInterface
|
||||
{
|
||||
return $this->setData(self::DESCRIPTION, $description);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getSortOrder(): int
|
||||
{
|
||||
return (int) $this->getData(self::SORT_ORDER);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setSortOrder(int $sortOrder): CategoryInterface
|
||||
{
|
||||
return $this->setData(self::SORT_ORDER, $sortOrder);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getHeadScripts(): string
|
||||
{
|
||||
return (string) $this->getData(self::HEAD_SCRIPTS);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setHeadScripts(string $headScripts): CategoryInterface
|
||||
{
|
||||
return $this->setData(self::HEAD_SCRIPTS, $headScripts);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getFooterMiscellaneousHtml(): string
|
||||
{
|
||||
return (string) $this->getData(self::FOOTER_MISCELLANEOUS_HTML);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setFooterMiscellaneousHtml(string $footerMiscellaneousHtml): CategoryInterface
|
||||
{
|
||||
return $this->setData(self::FOOTER_MISCELLANEOUS_HTML, $footerMiscellaneousHtml);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?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\Model\Category\Attribute\Source;
|
||||
|
||||
use Magento\Eav\Model\Entity\Attribute\Source\AbstractSource as EavAbstractSource;
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class CategoryKey extends EavAbstractSource
|
||||
{
|
||||
public const KEY_NECESSARY = 'necessary';
|
||||
public const KEY_PREFERENCES = 'preferences';
|
||||
public const KEY_STATISTICS = 'statistics';
|
||||
public const KEY_MARKETING = 'marketing';
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getAllOptions(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
'label' => __('Strictly necessary'),
|
||||
'value' => self::KEY_NECESSARY,
|
||||
],
|
||||
[
|
||||
'label' => __('Preferences'),
|
||||
'value' => self::KEY_PREFERENCES,
|
||||
],
|
||||
[
|
||||
'label' => __('Statistics'),
|
||||
'value' => self::KEY_STATISTICS,
|
||||
],
|
||||
[
|
||||
'label' => __('Marketing'),
|
||||
'value' => self::KEY_MARKETING,
|
||||
],
|
||||
[
|
||||
'label' => __('Custom'),
|
||||
'value' => 'custom',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
<?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\Model\Category;
|
||||
|
||||
use Magento\Framework\Api\FilterBuilder;
|
||||
use Magento\Framework\Api\SearchCriteriaBuilder;
|
||||
use Plumrocket\CookieConsent\Api\CategoryRepositoryInterface;
|
||||
use Plumrocket\CookieConsent\Api\Data\CategoryInterface;
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class GetCategoriesWithScripts
|
||||
{
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Api\CategoryRepositoryInterface
|
||||
*/
|
||||
private $categoryRepository;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Api\SearchCriteriaBuilder
|
||||
*/
|
||||
private $searchCriteriaBuilder;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Api\Data\CategoryInterface[]
|
||||
*/
|
||||
private $localCache;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Api\FilterBuilder
|
||||
*/
|
||||
private $filterBuilder;
|
||||
|
||||
/**
|
||||
* @param \Plumrocket\CookieConsent\Api\CategoryRepositoryInterface $categoryRepository
|
||||
* @param \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder
|
||||
* @param \Magento\Framework\Api\FilterBuilder $filterBuilder
|
||||
*/
|
||||
public function __construct(
|
||||
CategoryRepositoryInterface $categoryRepository,
|
||||
SearchCriteriaBuilder $searchCriteriaBuilder,
|
||||
FilterBuilder $filterBuilder
|
||||
) {
|
||||
$this->categoryRepository = $categoryRepository;
|
||||
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
|
||||
$this->filterBuilder = $filterBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Plumrocket\CookieConsent\Api\Data\CategoryInterface[]
|
||||
*/
|
||||
public function execute(): array
|
||||
{
|
||||
if (null === $this->localCache) {
|
||||
$this->searchCriteriaBuilder->addFilter(CategoryInterface::STATUS, 1);
|
||||
|
||||
$notEmptyHeadScriptsFilter = $this->filterBuilder
|
||||
->setField(CategoryInterface::HEAD_SCRIPTS)
|
||||
->setValue('')
|
||||
->setConditionType('neq')
|
||||
->create();
|
||||
$notEmptyFooterHtmlFilter = $this->filterBuilder
|
||||
->setField(CategoryInterface::FOOTER_MISCELLANEOUS_HTML)
|
||||
->setValue('')
|
||||
->setConditionType('neq')
|
||||
->create();
|
||||
|
||||
$this->searchCriteriaBuilder->addFilters([$notEmptyHeadScriptsFilter, $notEmptyFooterHtmlFilter]);
|
||||
|
||||
$searchResults = $this->categoryRepository->getList($this->searchCriteriaBuilder->create());
|
||||
|
||||
$this->localCache = $searchResults->getItems();
|
||||
}
|
||||
|
||||
return $this->localCache;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?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\Model\Category;
|
||||
|
||||
use Magento\Framework\Api\SearchCriteriaBuilder;
|
||||
use Plumrocket\CookieConsent\Api\CategoryRepositoryInterface;
|
||||
use Plumrocket\CookieConsent\Api\Data\CategoryInterface;
|
||||
use Plumrocket\CookieConsent\Api\GetEssentialCategoryKeysInterface;
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class GetEssentialKeys implements GetEssentialCategoryKeysInterface
|
||||
{
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Api\CategoryRepositoryInterface
|
||||
*/
|
||||
private $categoryRepository;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Api\SearchCriteriaBuilder
|
||||
*/
|
||||
private $searchCriteriaBuilder;
|
||||
|
||||
/**
|
||||
* Contain essential categories keys
|
||||
*
|
||||
* @var null|string[]
|
||||
*/
|
||||
private $localCache;
|
||||
|
||||
/**
|
||||
* @param \Plumrocket\CookieConsent\Api\CategoryRepositoryInterface $categoryRepository
|
||||
* @param \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder
|
||||
*/
|
||||
public function __construct(
|
||||
CategoryRepositoryInterface $categoryRepository,
|
||||
SearchCriteriaBuilder $searchCriteriaBuilder
|
||||
) {
|
||||
$this->categoryRepository = $categoryRepository;
|
||||
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function execute(): array
|
||||
{
|
||||
if (null === $this->localCache) {
|
||||
$this->searchCriteriaBuilder->addFilter(CategoryInterface::STATUS, 1);
|
||||
$this->searchCriteriaBuilder->addFilter(CategoryInterface::IS_ESSENTIAL, 1);
|
||||
|
||||
$searchResults = $this->categoryRepository->getList($this->searchCriteriaBuilder->create());
|
||||
|
||||
$this->localCache = [];
|
||||
foreach ($searchResults->getItems() as $category) {
|
||||
$this->localCache[] = $category->getKey();
|
||||
}
|
||||
}
|
||||
|
||||
return $this->localCache;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
<?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\Model\Category;
|
||||
|
||||
use Plumrocket\CookieConsent\Api\CanManageCookieInterface;
|
||||
use Plumrocket\CookieConsent\Api\Data\CategoryInterface;
|
||||
use Plumrocket\CookieConsent\Api\GetEssentialCategoryKeysInterface;
|
||||
use Plumrocket\CookieConsent\Api\GetUserConsentInterface;
|
||||
use Plumrocket\CookieConsent\Api\IsAllowedCategoryInterface;
|
||||
use Plumrocket\CookieConsent\Api\IsUserOptInInterface;
|
||||
use Plumrocket\CookieConsent\Helper\Config;
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class IsAllowed implements IsAllowedCategoryInterface
|
||||
{
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Api\CanManageCookieInterface
|
||||
*/
|
||||
private $canManageCookie;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Api\GetUserConsentInterface
|
||||
*/
|
||||
private $getUserConsent;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Api\IsUserOptInInterface
|
||||
*/
|
||||
private $isUserOptIn;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Helper\Config
|
||||
*/
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Api\GetEssentialCategoryKeysInterface
|
||||
*/
|
||||
private $getEssentialCategoryKeys;
|
||||
|
||||
/**
|
||||
* @param \Plumrocket\CookieConsent\Api\CanManageCookieInterface $canManageCookie
|
||||
* @param \Plumrocket\CookieConsent\Api\GetUserConsentInterface $getUserConsent
|
||||
* @param \Plumrocket\CookieConsent\Api\IsUserOptInInterface $isUserOptIn
|
||||
* @param \Plumrocket\CookieConsent\Helper\Config $config
|
||||
* @param \Plumrocket\CookieConsent\Api\GetEssentialCategoryKeysInterface $getEssentialCategoryKeys
|
||||
*/
|
||||
public function __construct(
|
||||
CanManageCookieInterface $canManageCookie,
|
||||
GetUserConsentInterface $getUserConsent,
|
||||
IsUserOptInInterface $isUserOptIn,
|
||||
Config $config,
|
||||
GetEssentialCategoryKeysInterface $getEssentialCategoryKeys
|
||||
) {
|
||||
$this->canManageCookie = $canManageCookie;
|
||||
$this->getUserConsent = $getUserConsent;
|
||||
$this->isUserOptIn = $isUserOptIn;
|
||||
$this->config = $config;
|
||||
$this->getEssentialCategoryKeys = $getEssentialCategoryKeys;
|
||||
}
|
||||
|
||||
/**
|
||||
* This logic has js alternative in CookieRestriction.isAllowedCategory
|
||||
*
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function execute(string $key): bool
|
||||
{
|
||||
if (! $this->canManageCookie->execute()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (in_array($key, $this->getEssentialCategoryKeys->execute(), true)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->isUserOptIn->execute()) {
|
||||
$allowedCategories = $this->getUserConsent->execute();
|
||||
if (in_array(CategoryInterface::ALL_CATEGORIES, $allowedCategories, true)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return in_array($key, $allowedCategories, true);
|
||||
}
|
||||
|
||||
return $this->config->canUseCookieBeforeOptIn();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
<?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\Model\Category\Source;
|
||||
|
||||
use Magento\Framework\Api\SearchCriteriaBuilder;
|
||||
use Magento\Framework\Data\OptionSourceInterface;
|
||||
use Plumrocket\CookieConsent\Api\CategoryRepositoryInterface;
|
||||
use Plumrocket\CookieConsent\Api\Data\CategoryInterface;
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class EnabledCategories implements OptionSourceInterface
|
||||
{
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Api\CategoryRepositoryInterface
|
||||
*/
|
||||
private $categoryRepository;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Api\SearchCriteriaBuilder
|
||||
*/
|
||||
private $searchCriteriaBuilder;
|
||||
|
||||
/**
|
||||
* @var array|null
|
||||
*/
|
||||
private $optionHash;
|
||||
|
||||
/**
|
||||
* CategoryKey constructor.
|
||||
*
|
||||
* @param \Plumrocket\CookieConsent\Api\CategoryRepositoryInterface $categoryRepository
|
||||
* @param \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder
|
||||
*/
|
||||
public function __construct(
|
||||
CategoryRepositoryInterface $categoryRepository,
|
||||
SearchCriteriaBuilder $searchCriteriaBuilder
|
||||
) {
|
||||
$this->categoryRepository = $categoryRepository;
|
||||
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return array of options
|
||||
*
|
||||
* @return array Format: array(array('<value>' => '<label>'), ...)
|
||||
*/
|
||||
public function toOptionHash(): array
|
||||
{
|
||||
if (null === $this->optionHash) {
|
||||
$categories = $this->categoryRepository
|
||||
->getList($this->searchCriteriaBuilder->addFilter(CategoryInterface::STATUS, 1)->create())
|
||||
->getItems();
|
||||
|
||||
$this->optionHash = [];
|
||||
foreach ($categories as $category) {
|
||||
$this->optionHash[$category->getKey()] = $category->getName();
|
||||
}
|
||||
}
|
||||
|
||||
return $this->optionHash;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function toOptionArray(): array
|
||||
{
|
||||
$result = [];
|
||||
foreach ($this->toOptionHash() as $key => $value) {
|
||||
$result[] = [
|
||||
'value' => $key,
|
||||
'label' => $value,
|
||||
];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,257 @@
|
||||
<?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\Model;
|
||||
|
||||
use Magento\Eav\Model\Entity\Attribute\Exception as AttributeException;
|
||||
use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface;
|
||||
use Magento\Framework\Api\SearchCriteriaInterface;
|
||||
use Magento\Framework\Api\SearchResultsInterface;
|
||||
use Magento\Framework\Exception\CouldNotSaveException;
|
||||
use Magento\Framework\Exception\InputException;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\Exception\StateException;
|
||||
use Magento\Framework\Exception\ValidatorException;
|
||||
use Plumrocket\CookieConsent\Api\CategoryRepositoryInterface;
|
||||
use Plumrocket\CookieConsent\Api\Data\CategoryInterface;
|
||||
use Plumrocket\CookieConsent\Api\Data\CategoryInterfaceFactory;
|
||||
use Plumrocket\CookieConsent\Api\Data\CategorySearchResultsInterfaceFactory;
|
||||
use Plumrocket\CookieConsent\Api\GetCategoryIdByKeyInterface;
|
||||
use Plumrocket\CookieConsent\Model\ResourceModel\Category\CollectionFactory;
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class CategoryRepository implements CategoryRepositoryInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @var CategoryInterface[][]
|
||||
*/
|
||||
private $instancesById = [];
|
||||
|
||||
/**
|
||||
* @var CategoryInterface[][]
|
||||
*/
|
||||
private $instancesByKey = [];
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Api\Data\CategoryInterfaceFactory
|
||||
*/
|
||||
private $categoryFactory;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Model\ResourceModel\Category
|
||||
*/
|
||||
private $resourceModel;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Api\GetCategoryIdByKeyInterface
|
||||
*/
|
||||
private $getCategoryIdByKey;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Model\ResourceModel\Category\CollectionFactory
|
||||
*/
|
||||
private $collectionFactory;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Api\Data\CategorySearchResultsInterfaceFactory
|
||||
*/
|
||||
private $searchResultsFactory;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface
|
||||
*/
|
||||
private $collectionProcessor;
|
||||
|
||||
/**
|
||||
* CategoryRepository constructor.
|
||||
*
|
||||
* @param \Plumrocket\CookieConsent\Api\Data\CategoryInterfaceFactory $categoryFactory
|
||||
* @param \Plumrocket\CookieConsent\Model\ResourceModel\Category $resourceModel
|
||||
* @param \Plumrocket\CookieConsent\Api\GetCategoryIdByKeyInterface $getCategoryIdByKey
|
||||
* @param \Plumrocket\CookieConsent\Model\ResourceModel\Category\CollectionFactory $collectionFactory
|
||||
* @param \Plumrocket\CookieConsent\Api\Data\CategorySearchResultsInterfaceFactory $searchResultsFactory
|
||||
* @param \Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface $collectionProcessor
|
||||
*/
|
||||
public function __construct(
|
||||
CategoryInterfaceFactory $categoryFactory,
|
||||
\Plumrocket\CookieConsent\Model\ResourceModel\Category $resourceModel,
|
||||
GetCategoryIdByKeyInterface $getCategoryIdByKey,
|
||||
CollectionFactory $collectionFactory,
|
||||
CategorySearchResultsInterfaceFactory $searchResultsFactory,
|
||||
CollectionProcessorInterface $collectionProcessor
|
||||
) {
|
||||
$this->categoryFactory = $categoryFactory;
|
||||
$this->resourceModel = $resourceModel;
|
||||
$this->getCategoryIdByKey = $getCategoryIdByKey;
|
||||
$this->collectionFactory = $collectionFactory;
|
||||
$this->searchResultsFactory = $searchResultsFactory;
|
||||
$this->collectionProcessor = $collectionProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function save(CategoryInterface $category): CategoryInterface
|
||||
{
|
||||
try {
|
||||
$this->clearLocalCache($category);
|
||||
$this->resourceModel->save($category);
|
||||
} catch (AttributeException $exception) {
|
||||
throw InputException::invalidFieldValue(
|
||||
$exception->getAttributeCode(),
|
||||
$category->getData($exception->getAttributeCode()),
|
||||
$exception
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
throw new CouldNotSaveException(
|
||||
__('The cookie category was unable to be saved. Please try again.'),
|
||||
$e
|
||||
);
|
||||
}
|
||||
|
||||
$this->clearLocalCache($category);
|
||||
|
||||
return $this->getById($category->getId(), $category->getStoreId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get info about checkbox by checkbox id
|
||||
*
|
||||
* @param int $categoryId
|
||||
* @param int|null $storeId
|
||||
* @param bool $forceReload
|
||||
* @return CategoryInterface
|
||||
* @throws \Magento\Framework\Exception\NoSuchEntityException
|
||||
*/
|
||||
public function getById(int $categoryId, ?int $storeId = null, bool $forceReload = false): CategoryInterface
|
||||
{
|
||||
if (! isset($this->instancesById[$categoryId][$storeId]) || $forceReload) {
|
||||
/** @var \Plumrocket\CookieConsent\Model\Category $category */
|
||||
$category = $this->categoryFactory->create();
|
||||
if ($storeId !== null) {
|
||||
$category->setStoreId($storeId);
|
||||
}
|
||||
$category->load($categoryId);
|
||||
if (! $category->getId()) {
|
||||
throw new NoSuchEntityException(
|
||||
__("The category that was requested doesn't exist. Verify the cookie category and try again.")
|
||||
);
|
||||
}
|
||||
|
||||
$this->saveToLocalCache($category, $storeId);
|
||||
}
|
||||
|
||||
return $this->instancesById[$categoryId][$storeId];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function get(string $categoryKey, ?int $storeId = null, bool $forceReload = false): CategoryInterface
|
||||
{
|
||||
if (! isset($this->instancesByKey[$categoryKey][$storeId]) || $forceReload) {
|
||||
$categoryId = $this->getCategoryIdByKey->execute($categoryKey, $forceReload);
|
||||
if (! $categoryId) {
|
||||
throw new NoSuchEntityException(
|
||||
__("The category that was requested doesn't exist. Verify the cookie category and try again.")
|
||||
);
|
||||
}
|
||||
|
||||
return $this->getById($categoryId);
|
||||
}
|
||||
|
||||
return $this->instancesByKey[$categoryKey][$storeId];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getList(SearchCriteriaInterface $searchCriteria): SearchResultsInterface
|
||||
{
|
||||
/** @var \Plumrocket\CookieConsent\Model\ResourceModel\Category\Collection $collection */
|
||||
$collection = $this->collectionFactory->create();
|
||||
$collection->addAttributeToSelect('*');
|
||||
$this->collectionProcessor->process($searchCriteria, $collection);
|
||||
|
||||
/** @var \Plumrocket\CookieConsent\Api\Data\CategorySearchResultsInterface $searchResult */
|
||||
$searchResult = $this->searchResultsFactory->create();
|
||||
$searchResult->setSearchCriteria($searchCriteria);
|
||||
$searchResult->setItems($collection->getItems());
|
||||
$searchResult->setTotalCount($collection->getSize());
|
||||
|
||||
return $searchResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function delete(CategoryInterface $category): bool
|
||||
{
|
||||
$categoryId = $category->getId();
|
||||
$categoryKey = $category->getKey();
|
||||
try {
|
||||
$this->clearLocalCache($category);
|
||||
$this->resourceModel->delete($category);
|
||||
} catch (ValidatorException $e) {
|
||||
throw new CouldNotSaveException(__($e->getMessage()));
|
||||
} catch (\Exception $e) {
|
||||
throw new StateException(
|
||||
__('The "%1" category couldn\'t be removed.', $categoryId)
|
||||
);
|
||||
}
|
||||
|
||||
unset($this->instancesById[$categoryId], $this->instancesByKey[$categoryKey]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function deleteById(int $id): bool
|
||||
{
|
||||
$category = $this->getById($id);
|
||||
return $this->delete($category);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save to cache.
|
||||
*
|
||||
* @param \Plumrocket\CookieConsent\Api\Data\CategoryInterface $category
|
||||
* @param int|null $storeId
|
||||
*/
|
||||
private function saveToLocalCache(CategoryInterface $category, ?int $storeId = null): void
|
||||
{
|
||||
$this->instancesById[$category->getId()][$storeId] = $category;
|
||||
$this->instancesByKey[$category->getKey()][$storeId] = $category;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear cache.
|
||||
*
|
||||
* @param \Plumrocket\CookieConsent\Api\Data\CategoryInterface $category
|
||||
*/
|
||||
private function clearLocalCache(CategoryInterface $category): void
|
||||
{
|
||||
unset($this->instancesById[$category->getId()], $this->instancesByKey[$category->getKey()]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
<?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\Model\Config\Backend;
|
||||
|
||||
use Magento\Config\Model\Config\Backend\Serialized\ArraySerialized;
|
||||
use Magento\Framework\App\Cache\TypeListInterface;
|
||||
use Magento\Framework\App\Config\ScopeConfigInterface;
|
||||
use Magento\Framework\Data\Collection\AbstractDb;
|
||||
use Magento\Framework\Model\Context;
|
||||
use Magento\Framework\Model\ResourceModel\AbstractResource;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\Framework\Serialize\SerializerInterface;
|
||||
|
||||
/**
|
||||
* @since 1.5.0
|
||||
*/
|
||||
class ConsentTypes extends ArraySerialized
|
||||
{
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Serialize\SerializerInterface
|
||||
*/
|
||||
private $jsonSerializer;
|
||||
|
||||
/**
|
||||
* @param \Magento\Framework\Model\Context $context
|
||||
* @param \Magento\Framework\Registry $registry
|
||||
* @param \Magento\Framework\App\Config\ScopeConfigInterface $config
|
||||
* @param \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList
|
||||
* @param \Magento\Framework\Serialize\SerializerInterface $jsonSerializer
|
||||
* @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource
|
||||
* @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(
|
||||
Context $context,
|
||||
Registry $registry,
|
||||
ScopeConfigInterface $config,
|
||||
TypeListInterface $cacheTypeList,
|
||||
SerializerInterface $jsonSerializer,
|
||||
?AbstractResource $resource = null,
|
||||
?AbstractDb $resourceCollection = null,
|
||||
array $data = []
|
||||
) {
|
||||
parent::__construct(
|
||||
$context,
|
||||
$registry,
|
||||
$config,
|
||||
$cacheTypeList,
|
||||
$resource,
|
||||
$resourceCollection,
|
||||
$data
|
||||
);
|
||||
$this->jsonSerializer = $jsonSerializer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function beforeSave()
|
||||
{
|
||||
parent::beforeSave();
|
||||
$value = $this->getValue();
|
||||
if ($value === '[]') {
|
||||
$this->_dataSaveAllowed = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fix get old value.
|
||||
*
|
||||
* We have array as default value and magento cannot resolve it by itself
|
||||
* because it doesn't know how to convert it to string.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getOldValue(): string
|
||||
{
|
||||
$oldValue = $this->_config->getValue(
|
||||
$this->getPath(),
|
||||
$this->getScope() ?: ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
|
||||
$this->getScopeCode()
|
||||
);
|
||||
|
||||
if (is_array($oldValue)) {
|
||||
$oldValue = $this->jsonSerializer->serialize($oldValue);
|
||||
}
|
||||
|
||||
return (string) $oldValue;
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
namespace Plumrocket\CookieConsent\Model\Config\Source;
|
||||
|
||||
use Magento\Framework\Data\OptionSourceInterface;
|
||||
use Magento\Framework\View\Asset\Repository;
|
||||
use Plumrocket\ExtendedAdminUi\Api\ImageRadioButtonSourceInterface;
|
||||
|
||||
/**
|
||||
* @since 1.1.0
|
||||
*/
|
||||
class BannerDisplayStyle implements OptionSourceInterface, ImageRadioButtonSourceInterface
|
||||
{
|
||||
public const POPUP = 'popup';
|
||||
public const BOTTOM = 'bottom';
|
||||
public const WALL = 'wall';
|
||||
|
||||
/**
|
||||
* @var Repository
|
||||
*/
|
||||
private $viewAssetRepository;
|
||||
|
||||
/**
|
||||
* ReviewPageStructure constructor.
|
||||
*
|
||||
* @param Repository $viewAssetRepository
|
||||
*/
|
||||
public function __construct(Repository $viewAssetRepository)
|
||||
{
|
||||
$this->viewAssetRepository = $viewAssetRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function toOptionArray(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
'value' => self::POPUP,
|
||||
'label' => __('Cookie Consent Popup'),
|
||||
'image' => $this->viewAssetRepository->getUrl(
|
||||
'Plumrocket_CookieConsent::images/system_config/banner-style/consent_popup.png'
|
||||
),
|
||||
'image2x' => $this->viewAssetRepository->getUrl(
|
||||
'Plumrocket_CookieConsent::images/system_config/banner-style/consent_popup@2x.png'
|
||||
),
|
||||
],
|
||||
[
|
||||
'value' => self::BOTTOM,
|
||||
'label' => __('Bottom Cookie Banner'),
|
||||
'image' => $this->viewAssetRepository->getUrl(
|
||||
'Plumrocket_CookieConsent::images/system_config/banner-style/bottom_panel.png'
|
||||
),
|
||||
'image2x' => $this->viewAssetRepository->getUrl(
|
||||
'Plumrocket_CookieConsent::images/system_config/banner-style/bottom_panel@2x.png'
|
||||
),
|
||||
],
|
||||
[
|
||||
'value' => self::WALL,
|
||||
'label' => __('Full-Screen Cookie Wall'),
|
||||
'image' => $this->viewAssetRepository->getUrl(
|
||||
'Plumrocket_CookieConsent::images/system_config/banner-style/full_screen.png'
|
||||
),
|
||||
'image2x' => $this->viewAssetRepository->getUrl(
|
||||
'Plumrocket_CookieConsent::images/system_config/banner-style/full_screen@2x.png'
|
||||
),
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?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\Model\Config\Source;
|
||||
|
||||
use Magento\Framework\Data\OptionSourceInterface;
|
||||
|
||||
class CategoryStatus implements OptionSourceInterface
|
||||
{
|
||||
public const ENABLED = 1;
|
||||
public const DISABLED = 0;
|
||||
public const COMPLETED = 'completed';
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function toOptionArray(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
'value' => self::ENABLED,
|
||||
'label' => __('Enabled'),
|
||||
],
|
||||
[
|
||||
'value' => self::DISABLED,
|
||||
'label' => __('Disabled'),
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?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\Model\Config\Source;
|
||||
|
||||
use Magento\Framework\Data\OptionSourceInterface;
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class SettingsButtonType implements OptionSourceInterface
|
||||
{
|
||||
public const BUTTON = 'button';
|
||||
public const LINK = 'link';
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function toOptionArray(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
'value' => self::BUTTON,
|
||||
'label' => __('Button'),
|
||||
],
|
||||
[
|
||||
'value' => self::LINK,
|
||||
'label' => __('Link'),
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?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\Model\Config\Source;
|
||||
|
||||
use Magento\Framework\Data\OptionSourceInterface;
|
||||
use Magento\Framework\View\Asset\Repository;
|
||||
use Plumrocket\ExtendedAdminUi\Api\ImageRadioButtonSourceInterface;
|
||||
|
||||
/**
|
||||
* @since 1.7.0
|
||||
*/
|
||||
class SettingsPanelDisplayStyle implements OptionSourceInterface, ImageRadioButtonSourceInterface
|
||||
{
|
||||
|
||||
public const LEFT_BAR = 'left_bar';
|
||||
public const ACCORDION_POPUP = 'accordions_popup';
|
||||
|
||||
/**
|
||||
* @var Repository
|
||||
*/
|
||||
private $viewAssetRepository;
|
||||
|
||||
/**
|
||||
* ReviewPageStructure constructor.
|
||||
*
|
||||
* @param Repository $viewAssetRepository
|
||||
*/
|
||||
public function __construct(Repository $viewAssetRepository)
|
||||
{
|
||||
$this->viewAssetRepository = $viewAssetRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function toOptionArray(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
'value' => self::LEFT_BAR,
|
||||
'label' => __('Left Sidebar'),
|
||||
'image' => $this->viewAssetRepository->getUrl(
|
||||
'Plumrocket_CookieConsent::images/system_config/left_bar.png'
|
||||
),
|
||||
'image2x' => $this->viewAssetRepository->getUrl(
|
||||
'Plumrocket_CookieConsent::images/system_config/left_bar@2x.png'
|
||||
),
|
||||
],
|
||||
[
|
||||
'value' => self::ACCORDION_POPUP,
|
||||
'label' => __('Popup'),
|
||||
'image' => $this->viewAssetRepository->getUrl(
|
||||
'Plumrocket_CookieConsent::images/system_config/popup.png'
|
||||
),
|
||||
'image2x' => $this->viewAssetRepository->getUrl(
|
||||
'Plumrocket_CookieConsent::images/system_config/popup@2x.png'
|
||||
),
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
<?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\Model\Consent;
|
||||
|
||||
use Plumrocket\CookieConsent\Api\Data\CategoryInterface;
|
||||
use Plumrocket\CookieConsent\Api\GetEssentialCategoryKeysInterface;
|
||||
use Plumrocket\CookieConsent\Model\Category\Source\EnabledCategories;
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class CreateSettingsFromParam
|
||||
{
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Model\Category\Source\EnabledCategories
|
||||
*/
|
||||
private $enabledCategories;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Api\GetEssentialCategoryKeysInterface
|
||||
*/
|
||||
private $getEssentialCategoryKeys;
|
||||
|
||||
/**
|
||||
* @param \Plumrocket\CookieConsent\Model\Category\Source\EnabledCategories $enabledCategories
|
||||
* @param \Plumrocket\CookieConsent\Api\GetEssentialCategoryKeysInterface $getEssentialCategoryKeys
|
||||
*/
|
||||
public function __construct(
|
||||
EnabledCategories $enabledCategories,
|
||||
GetEssentialCategoryKeysInterface $getEssentialCategoryKeys
|
||||
) {
|
||||
$this->enabledCategories = $enabledCategories;
|
||||
$this->getEssentialCategoryKeys = $getEssentialCategoryKeys;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $acceptedKeys
|
||||
* @return bool[]
|
||||
*/
|
||||
public function execute(array $acceptedKeys): array
|
||||
{
|
||||
if (empty($acceptedKeys)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (in_array(CategoryInterface::ALL_CATEGORIES, $acceptedKeys, true)) {
|
||||
$settings = [CategoryInterface::ALL_CATEGORIES => true];
|
||||
} else {
|
||||
$enabledCategoriesKeys = array_keys($this->enabledCategories->toOptionHash());
|
||||
$essentialCategoryKeys = $this->getEssentialCategoryKeys->execute();
|
||||
|
||||
$settings = [];
|
||||
foreach ($enabledCategoriesKeys as $enabledCategoriesKey) {
|
||||
if (in_array($enabledCategoriesKey, $essentialCategoryKeys, true)) {
|
||||
$settings[$enabledCategoriesKey] = true;
|
||||
} else {
|
||||
$settings[$enabledCategoriesKey] = in_array($enabledCategoriesKey, $acceptedKeys, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $settings;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
<?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\Model\Consent;
|
||||
|
||||
use Magento\Framework\Model\AbstractModel;
|
||||
use Plumrocket\CookieConsent\Api\Data\ConsentLogInterface;
|
||||
use Plumrocket\CookieConsent\Model\ResourceModel\ConsentLog as ConsentLogResource;
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Log extends AbstractModel implements ConsentLogInterface
|
||||
{
|
||||
/**
|
||||
* Initialize resource model.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _construct()
|
||||
{
|
||||
$this->_init(ConsentLogResource::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getCustomerId(): int
|
||||
{
|
||||
return (int) $this->_getData(ConsentLogInterface::CUSTOMER_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getGuestEmail(): string
|
||||
{
|
||||
return (string) $this->_getData(ConsentLogInterface::GUEST_EMAIL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getWebsiteId(): int
|
||||
{
|
||||
return (int) $this->_getData(ConsentLogInterface::WEBSITE_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getSettings(): array
|
||||
{
|
||||
return (array) $this->_getData(ConsentLogInterface::SETTINGS);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getIpAddress(): string
|
||||
{
|
||||
return (string) $this->_getData(ConsentLogInterface::IP_ADDRESS);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getCreatedAt(): string
|
||||
{
|
||||
return (string) $this->_getData(ConsentLogInterface::CREATED_AT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getUserAgent(): string
|
||||
{
|
||||
return (string) $this->_getData(ConsentLogInterface::USER_AGENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getUrl(): string
|
||||
{
|
||||
return (string) $this->_getData(ConsentLogInterface::URL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setCustomerId(int $customerId): ConsentLogInterface
|
||||
{
|
||||
return $this->setData(ConsentLogInterface::CUSTOMER_ID, $customerId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setGuestEmail(string $guestEmail): ConsentLogInterface
|
||||
{
|
||||
return $this->setData(ConsentLogInterface::GUEST_EMAIL, $guestEmail);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setWebsiteId(int $websiteId): ConsentLogInterface
|
||||
{
|
||||
return $this->setData(ConsentLogInterface::WEBSITE_ID, $websiteId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setSettings(array $settings): ConsentLogInterface
|
||||
{
|
||||
return $this->setData(ConsentLogInterface::SETTINGS, $settings);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setIpAddress(string $ipAddress): ConsentLogInterface
|
||||
{
|
||||
return $this->setData(ConsentLogInterface::IP_ADDRESS, $ipAddress);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setCreatedAt(string $gmtDateTime): ConsentLogInterface
|
||||
{
|
||||
return $this->setData(ConsentLogInterface::CREATED_AT, $gmtDateTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setUserAgent(string $userAgent): ConsentLogInterface
|
||||
{
|
||||
return $this->setData(ConsentLogInterface::USER_AGENT, $userAgent);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setUrl(string $url): ConsentLogInterface
|
||||
{
|
||||
return $this->setData(ConsentLogInterface::URL, $url);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
<?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\Model\Consent;
|
||||
|
||||
use Magento\Customer\Helper\Session\CurrentCustomer;
|
||||
use Magento\Framework\App\Response\RedirectInterface;
|
||||
use Magento\Framework\HTTP\Header;
|
||||
use Magento\Framework\HTTP\PhpEnvironment\RemoteAddress;
|
||||
use Magento\Framework\Stdlib\DateTime\DateTime;
|
||||
use Magento\Framework\UrlInterface;
|
||||
use Magento\Store\Model\StoreManagerInterface;
|
||||
use Plumrocket\CookieConsent\Api\Data\ConsentLogInterface;
|
||||
use Plumrocket\CookieConsent\Api\Data\ConsentLogInterfaceFactory;
|
||||
use Plumrocket\CookieConsent\Model\ResourceModel\ConsentLog as ConsentLogResource;
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Logger
|
||||
{
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Api\Data\ConsentLogInterfaceFactory
|
||||
*/
|
||||
private $consentLogFactory;
|
||||
|
||||
/**
|
||||
* @var \Magento\Store\Model\StoreManagerInterface
|
||||
*/
|
||||
private $storeManager;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\HTTP\PhpEnvironment\RemoteAddress
|
||||
*/
|
||||
private $remoteAddress;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Stdlib\DateTime\DateTime
|
||||
*/
|
||||
private $dateTime;
|
||||
|
||||
/**
|
||||
* @var \Magento\Customer\Helper\Session\CurrentCustomer
|
||||
*/
|
||||
private $currentCustomer;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Model\ResourceModel\ConsentLog
|
||||
*/
|
||||
private $consentLogResource;
|
||||
|
||||
/**
|
||||
* @var Header
|
||||
*/
|
||||
private $httpHeader;
|
||||
|
||||
/**
|
||||
* @var RedirectInterface
|
||||
*/
|
||||
private $redirect;
|
||||
|
||||
/**
|
||||
* @param \Plumrocket\CookieConsent\Api\Data\ConsentLogInterfaceFactory $consentLogFactory
|
||||
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
|
||||
* @param \Magento\Framework\HTTP\PhpEnvironment\RemoteAddress $remoteAddress
|
||||
* @param \Magento\Framework\Stdlib\DateTime\DateTime $dateTime
|
||||
* @param \Magento\Customer\Helper\Session\CurrentCustomer $currentCustomer
|
||||
* @param \Plumrocket\CookieConsent\Model\ResourceModel\ConsentLog $consentLogResource
|
||||
* @param Header $httpHeader
|
||||
* @param RedirectInterface $redirect
|
||||
*/
|
||||
public function __construct(
|
||||
ConsentLogInterfaceFactory $consentLogFactory,
|
||||
StoreManagerInterface $storeManager,
|
||||
RemoteAddress $remoteAddress,
|
||||
DateTime $dateTime,
|
||||
CurrentCustomer $currentCustomer,
|
||||
ConsentLogResource $consentLogResource,
|
||||
Header $httpHeader,
|
||||
RedirectInterface $redirect
|
||||
) {
|
||||
$this->consentLogFactory = $consentLogFactory;
|
||||
$this->storeManager = $storeManager;
|
||||
$this->remoteAddress = $remoteAddress;
|
||||
$this->dateTime = $dateTime;
|
||||
$this->currentCustomer = $currentCustomer;
|
||||
$this->consentLogResource = $consentLogResource;
|
||||
$this->httpHeader = $httpHeader;
|
||||
$this->redirect = $redirect;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $settings
|
||||
* @return \Plumrocket\CookieConsent\Api\Data\ConsentLogInterface
|
||||
* @throws \Magento\Framework\Exception\AlreadyExistsException
|
||||
* @throws \Magento\Framework\Exception\NoSuchEntityException
|
||||
*/
|
||||
public function log(array $settings): ConsentLogInterface
|
||||
{
|
||||
/** @var ConsentLogInterface|Log $consentLog */
|
||||
$consentLog = $this->consentLogFactory->create();
|
||||
|
||||
$consentLog->setCustomerId((int) $this->currentCustomer->getCustomerId());
|
||||
$consentLog->setSettings($settings);
|
||||
$consentLog->setWebsiteId((int) $this->storeManager->getStore()->getWebsiteId());
|
||||
$consentLog->setIpAddress($this->getAnonymizedIp());
|
||||
$consentLog->setUserAgent($this->httpHeader->getHttpUserAgent());
|
||||
$consentLog->setUrl($this->redirect->getRefererUrl());
|
||||
$consentLog->setCreatedAt($this->getFormattedGmtDateTime());
|
||||
|
||||
$this->consentLogResource->save($consentLog);
|
||||
|
||||
return $consentLog;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the date in the proper format
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getFormattedGmtDateTime(): string
|
||||
{
|
||||
return (string) date('Y-m-d H:i:s', $this->dateTime->gmtTimestamp());
|
||||
}
|
||||
|
||||
/**
|
||||
* Anonymize customer Ip
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getAnonymizedIp(): string
|
||||
{
|
||||
$realIp = $this->remoteAddress->getRemoteAddress();
|
||||
$ipPieces = explode('.', $realIp);
|
||||
end($ipPieces);
|
||||
$ipPieces[key($ipPieces)] = '000';
|
||||
|
||||
return implode('.', $ipPieces);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,188 @@
|
||||
<?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\Model;
|
||||
|
||||
use Magento\Catalog\Model\AbstractModel as CatalogAbstractModel;
|
||||
use Magento\Framework\DataObject\IdentityInterface;
|
||||
use Plumrocket\CookieConsent\Api\Data\CookieInterface;
|
||||
use Plumrocket\CookieConsent\Model\Cookie\Attribute\Source\Type as CookieType;
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Cookie extends CatalogAbstractModel implements IdentityInterface, CookieInterface
|
||||
{
|
||||
public const ENTITY = 'pr_cookie';
|
||||
|
||||
public const CACHE_TAG = 'pr_cookie';
|
||||
|
||||
/**
|
||||
* Prefix of model events names
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_eventPrefix = 'pr_cookie';
|
||||
|
||||
/**
|
||||
* Parameter name in event
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_eventObject = 'cookie';
|
||||
|
||||
/**
|
||||
* Model cache tag for clear cache in after save and after delete
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_cacheTag = self::CACHE_TAG;
|
||||
|
||||
/**
|
||||
* Initialize resources
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _construct()
|
||||
{
|
||||
$this->_init(ResourceModel\Cookie::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return (int) parent::getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get identities
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getIdentities(): array
|
||||
{
|
||||
return [self::CACHE_TAG . '_' . $this->getId()];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return (string) $this->_getData(CookieInterface::NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setName(string $name): CookieInterface
|
||||
{
|
||||
return $this->setData(CookieInterface::NAME, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getCategoryKey(): string
|
||||
{
|
||||
return (string) $this->_getData(CookieInterface::CATEGORY_KEY);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setCategoryKey(string $categoryKey): CookieInterface
|
||||
{
|
||||
return $this->setData(CookieInterface::CATEGORY_KEY, $categoryKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function isFirstParty(): bool
|
||||
{
|
||||
return CookieType::TYPE_FIRST === $this->getType();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getType(): string
|
||||
{
|
||||
return (string) $this->_getData(CookieInterface::TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setType(string $type): CookieInterface
|
||||
{
|
||||
return $this->setData(CookieInterface::TYPE, $type);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getDomain(): string
|
||||
{
|
||||
return (string) $this->_getData(CookieInterface::DOMAIN);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setDomain(string $domain): CookieInterface
|
||||
{
|
||||
return $this->setData(CookieInterface::DOMAIN, $domain);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getDuration(): int
|
||||
{
|
||||
return (int) $this->_getData(CookieInterface::DURATION);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setDuration(int $duration): CookieInterface
|
||||
{
|
||||
return $this->setData(CookieInterface::DURATION, $duration);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getDescription(): string
|
||||
{
|
||||
return (string) $this->_getData(CookieInterface::DESCRIPTION);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setDescription(string $description): CookieInterface
|
||||
{
|
||||
return $this->setData(CookieInterface::DESCRIPTION, $description);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
<?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\Model\Cookie\Attribute;
|
||||
|
||||
use Magento\Framework\Data\OptionSourceInterface;
|
||||
use Plumrocket\CookieConsent\Api\Data\CookieInterface;
|
||||
|
||||
class DurationDecorator implements OptionSourceInterface
|
||||
{
|
||||
public const PERIOD_DAYS = 'days';
|
||||
public const PERIOD_HOURS = 'hours';
|
||||
public const PERIOD_MINUTES = 'minutes';
|
||||
public const PERIOD_SECONDS = 'seconds';
|
||||
|
||||
public const DURATION_PERIOD = 'duration-period';
|
||||
|
||||
public const PERIODS = [
|
||||
self::PERIOD_DAYS => 86400,
|
||||
self::PERIOD_HOURS => 3600,
|
||||
self::PERIOD_MINUTES => 60,
|
||||
];
|
||||
|
||||
/**
|
||||
* Serialize two duration fields into one
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
public function serializeParams(array $data): array
|
||||
{
|
||||
if ($data[CookieInterface::DURATION]) {
|
||||
$duration = $data[CookieInterface::DURATION];
|
||||
$period = $data[self::DURATION_PERIOD];
|
||||
switch ($period) {
|
||||
case self::PERIOD_DAYS:
|
||||
$data[CookieInterface::DURATION] = self::PERIODS[self::PERIOD_DAYS] * $duration;
|
||||
break;
|
||||
case self::PERIOD_HOURS:
|
||||
$data[CookieInterface::DURATION] = self::PERIODS[self::PERIOD_HOURS] * $duration;
|
||||
break;
|
||||
case self::PERIOD_MINUTES:
|
||||
$data[CookieInterface::DURATION] = self::PERIODS[self::PERIOD_MINUTES] * $duration;
|
||||
break;
|
||||
case self::PERIOD_SECONDS:
|
||||
$data[CookieInterface::DURATION] = $duration;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
unset($data[self::DURATION_PERIOD]);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
public function unserializeParams(array $data): array
|
||||
{
|
||||
return array_merge($data, $this->getValues(
|
||||
(int) ($data[CookieInterface::DURATION] ?? 0)
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate values for 'duration' and 'duration-select'
|
||||
*
|
||||
* @param int $durationInSeconds
|
||||
* @return array
|
||||
*/
|
||||
private function getValues(int $durationInSeconds): array
|
||||
{
|
||||
if ($durationInSeconds) {
|
||||
foreach (self::PERIODS as $optionName => $periodInSeconds) {
|
||||
if (! ($durationInSeconds % $periodInSeconds)) {
|
||||
return [
|
||||
CookieInterface::DURATION => $durationInSeconds / $periodInSeconds,
|
||||
self::DURATION_PERIOD => $optionName,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
CookieInterface::DURATION => $durationInSeconds,
|
||||
self::DURATION_PERIOD => self::PERIOD_SECONDS,
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
CookieInterface::DURATION => 0,
|
||||
self::DURATION_PERIOD => self::PERIOD_DAYS,
|
||||
];
|
||||
}
|
||||
|
||||
public function toOptionArray(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
'value' => self::PERIOD_SECONDS,
|
||||
'label' => __('seconds')
|
||||
],
|
||||
[
|
||||
'value' => self::PERIOD_MINUTES,
|
||||
'label' => __('minutes')
|
||||
],
|
||||
[
|
||||
'value' => self::PERIOD_HOURS,
|
||||
'label' => __('hours')
|
||||
],
|
||||
[
|
||||
'value' => self::PERIOD_DAYS,
|
||||
'label' => __('days')
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
<?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\Model\Cookie\Attribute\Source;
|
||||
|
||||
use Magento\Eav\Model\Entity\Attribute\Source\AbstractSource as EavAbstractSource;
|
||||
use Magento\Framework\Api\SearchCriteriaBuilder;
|
||||
use Plumrocket\CookieConsent\Api\CategoryRepositoryInterface;
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class CategoryKey extends EavAbstractSource
|
||||
{
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Api\CategoryRepositoryInterface
|
||||
*/
|
||||
private $categoryRepository;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Api\SearchCriteriaBuilder
|
||||
*/
|
||||
private $searchCriteriaBuilder;
|
||||
|
||||
/**
|
||||
* @var array|null
|
||||
*/
|
||||
private $optionHash;
|
||||
|
||||
/**
|
||||
* CategoryKey constructor.
|
||||
*
|
||||
* @param \Plumrocket\CookieConsent\Api\CategoryRepositoryInterface $categoryRepository
|
||||
* @param \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder
|
||||
*/
|
||||
public function __construct(
|
||||
CategoryRepositoryInterface $categoryRepository,
|
||||
SearchCriteriaBuilder $searchCriteriaBuilder
|
||||
) {
|
||||
$this->categoryRepository = $categoryRepository;
|
||||
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getAllOptions(): array
|
||||
{
|
||||
$result = [];
|
||||
foreach ($this->toOptionHash() as $key => $value) {
|
||||
$result[] = [
|
||||
'value' => $key,
|
||||
'label' => $value,
|
||||
];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return array of options
|
||||
*
|
||||
* @return array Format: array(array('<value>' => '<label>'), ...)
|
||||
*/
|
||||
public function toOptionHash(): array
|
||||
{
|
||||
if (null === $this->optionHash) {
|
||||
$categories = $this->categoryRepository
|
||||
->getList($this->searchCriteriaBuilder->create())
|
||||
->getItems();
|
||||
|
||||
$this->optionHash = ['' => __('--Please Select--')];
|
||||
foreach ($categories as $category) {
|
||||
$this->optionHash[$category->getKey()] = $category->getName();
|
||||
}
|
||||
}
|
||||
|
||||
return $this->optionHash;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?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\Model\Cookie\Attribute\Source;
|
||||
|
||||
use Magento\Eav\Model\Entity\Attribute\Source\AbstractSource as EavAbstractSource;
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Type extends EavAbstractSource
|
||||
{
|
||||
public const TYPE_FIRST = 'first';
|
||||
public const TYPE_THIRD = 'third';
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getAllOptions(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
'value' => self::TYPE_FIRST,
|
||||
'label' => __('1st Party')
|
||||
],
|
||||
[
|
||||
'value' => self::TYPE_THIRD,
|
||||
'label' => __('3rd Party')
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
<?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\Model\Cookie;
|
||||
|
||||
use Magento\Framework\Session\Config\ConfigInterface;
|
||||
use Magento\Framework\Stdlib\Cookie\CookieMetadataFactory;
|
||||
use Magento\Framework\Stdlib\CookieManagerInterface;
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class ClearRejected
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\Stdlib\CookieManagerInterface
|
||||
*/
|
||||
private $cookieManager;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Model\Cookie\IsAllowed
|
||||
*/
|
||||
private $isAllowed;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Model\Cookie\GetSetCookiesNames
|
||||
*/
|
||||
private $getSetCookiesNames;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory
|
||||
*/
|
||||
private $cookieMetadataFactory;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Session\Config\ConfigInterface
|
||||
*/
|
||||
private $sessionConfig;
|
||||
|
||||
/**
|
||||
* @param \Magento\Framework\Stdlib\CookieManagerInterface $cookieManager
|
||||
* @param \Plumrocket\CookieConsent\Model\Cookie\IsAllowed $isAllowed
|
||||
* @param \Plumrocket\CookieConsent\Model\Cookie\GetSetCookiesNames $getSetCookiesNames
|
||||
* @param \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory $cookieMetadataFactory
|
||||
* @param \Magento\Framework\Session\Config\ConfigInterface $sessionConfig
|
||||
*/
|
||||
public function __construct(
|
||||
CookieManagerInterface $cookieManager,
|
||||
IsAllowed $isAllowed,
|
||||
GetSetCookiesNames $getSetCookiesNames,
|
||||
CookieMetadataFactory $cookieMetadataFactory,
|
||||
ConfigInterface $sessionConfig
|
||||
) {
|
||||
$this->cookieManager = $cookieManager;
|
||||
$this->isAllowed = $isAllowed;
|
||||
$this->getSetCookiesNames = $getSetCookiesNames;
|
||||
$this->cookieMetadataFactory = $cookieMetadataFactory;
|
||||
$this->sessionConfig = $sessionConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Magento\Framework\Exception\InputException
|
||||
* @throws \Magento\Framework\Stdlib\Cookie\FailureToSendException
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$metadata = $this->cookieMetadataFactory->createPublicCookieMetadata();
|
||||
$metadata->setPath('/');
|
||||
$metadata->setSecure($this->sessionConfig->getCookieSecure());
|
||||
$metadata->setHttpOnly($this->sessionConfig->getCookieHttpOnly());
|
||||
|
||||
foreach ($this->getSetCookiesNames->execute() as $cookieName) {
|
||||
if (! $this->isAllowed->execute($cookieName)) {
|
||||
$this->cookieManager->deleteCookie($cookieName, $metadata);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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\Model\Cookie\Config;
|
||||
|
||||
use Magento\Framework\Config\ConverterInterface;
|
||||
use Magento\Framework\Data\Argument\Interpreter\Constant;
|
||||
use Plumrocket\CookieConsent\Model\Cookie\Attribute\Source\Type;
|
||||
|
||||
class Converter implements ConverterInterface
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\Data\Argument\Interpreter\Constant
|
||||
*/
|
||||
private $constInterpreter;
|
||||
|
||||
public function __construct(Constant $constInterpreter)
|
||||
{
|
||||
$this->constInterpreter = $constInterpreter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert dom node tree to array
|
||||
*
|
||||
* @param \DOMDocument $source
|
||||
* @return array
|
||||
*/
|
||||
public function convert($source)
|
||||
{
|
||||
$output = [];
|
||||
/** @var \DOMNodeList $cookies */
|
||||
$cookies = $source->getElementsByTagName('cookie');
|
||||
/** @var \DOMNode $cookie */
|
||||
foreach ($cookies as $cookie) {
|
||||
$cookieConfig = [];
|
||||
foreach ($cookie->attributes as $attribute) {
|
||||
$cookieConfig[$attribute->nodeName] = $attribute->nodeValue;
|
||||
}
|
||||
/** @var \DOMNode $childNode */
|
||||
foreach ($cookie->childNodes as $childNode) {
|
||||
if ($childNode->nodeType == XML_ELEMENT_NODE ||
|
||||
($childNode->nodeType == XML_CDATA_SECTION_NODE ||
|
||||
$childNode->nodeType == XML_TEXT_NODE && trim(
|
||||
$childNode->nodeValue
|
||||
) != '')
|
||||
) {
|
||||
if ($childNode->attributes->getNamedItem('type')
|
||||
&& 'const' === $childNode->attributes->getNamedItem('type')->nodeValue
|
||||
) {
|
||||
$value = $this->constInterpreter->evaluate(['value' => $childNode->nodeValue]);
|
||||
} else {
|
||||
$value = $childNode->nodeValue;
|
||||
}
|
||||
|
||||
$cookieConfig[$childNode->nodeName] = $value;
|
||||
}
|
||||
}
|
||||
$output[$cookie->attributes->getNamedItem('name')->nodeValue] = $cookieConfig;
|
||||
}
|
||||
|
||||
$output = array_map(static function ($cookie) {
|
||||
$cookie['type'] = $cookie['type'] ?? Type::TYPE_FIRST;
|
||||
$cookie['category_key'] = $cookie['category'];
|
||||
unset($cookie['category']);
|
||||
return $cookie;
|
||||
}, $output);
|
||||
|
||||
return ['cookies' => $output];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?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\Model\Cookie;
|
||||
|
||||
use Magento\Framework\Session\Config\ConfigInterface;
|
||||
use Plumrocket\CookieConsent\Api\Data\CookieInterface;
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Domain
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\Session\Config\ConfigInterface
|
||||
*/
|
||||
private $sessionConfig;
|
||||
|
||||
/**
|
||||
* @param \Magento\Framework\Session\Config\ConfigInterface $sessionConfig
|
||||
*/
|
||||
public function __construct(ConfigInterface $sessionConfig)
|
||||
{
|
||||
$this->sessionConfig = $sessionConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Plumrocket\CookieConsent\Api\Data\CookieInterface $cookie
|
||||
* @return string
|
||||
*/
|
||||
public function getLabel(CookieInterface $cookie): string
|
||||
{
|
||||
if ($cookie->isFirstParty() && ! $cookie->getDomain()) {
|
||||
return $this->sessionConfig->getCookieDomain();
|
||||
}
|
||||
|
||||
return $cookie->getDomain();
|
||||
}
|
||||
}
|
||||
@@ -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) 2020 Plumrocket Inc. (http://www.plumrocket.com)
|
||||
* @license http://wiki.plumrocket.net/wiki/EULA End-user License Agreement
|
||||
*/
|
||||
|
||||
namespace Plumrocket\CookieConsent\Model\Cookie;
|
||||
|
||||
use Plumrocket\CookieConsent\Api\Data\CookieInterface;
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Duration
|
||||
{
|
||||
public const ONE_YEAR = 31536000;
|
||||
public const TWO_YEARS = 63072000;
|
||||
public const SESSION = 0;
|
||||
public const ONE_DAY = 86400;
|
||||
public const FOR_LOCAL_STORAGE_COOKIE = 86400;
|
||||
public const ONE_HOUR = 3600;
|
||||
|
||||
/**
|
||||
* @param \Plumrocket\CookieConsent\Api\Data\CookieInterface $cookie
|
||||
* @return string
|
||||
*/
|
||||
public function getLabel(CookieInterface $cookie): string
|
||||
{
|
||||
return $this->durationToLabel($cookie->getDuration());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $seconds
|
||||
* @return string
|
||||
*/
|
||||
public function durationToLabel(int $seconds): string
|
||||
{
|
||||
if (self::SESSION === $seconds) {
|
||||
return (string) __('Session');
|
||||
}
|
||||
|
||||
if ($seconds >= self::ONE_DAY) {
|
||||
$days = round($seconds / self::ONE_DAY);
|
||||
if ($days > 1) {
|
||||
return (string) __('%1 days', $days);
|
||||
}
|
||||
|
||||
return (string) __('1 day');
|
||||
}
|
||||
|
||||
if ($seconds >= self::ONE_HOUR) {
|
||||
$hours = round($seconds / self::ONE_HOUR);
|
||||
if ($hours > 1) {
|
||||
return (string) __('%1 hours', $hours);
|
||||
}
|
||||
|
||||
return (string) __('1 hour');
|
||||
}
|
||||
|
||||
return (string) __('less than an hour');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?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\Model\Cookie;
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class GetSetCookiesNames
|
||||
{
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function execute(): array
|
||||
{
|
||||
return array_keys($_COOKIE); //phpcs:ignore -- magento cookie reader has not method for reading all cookies
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
<?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\Model\Cookie;
|
||||
|
||||
use Plumrocket\CookieConsent\Api\CanManageCookieInterface;
|
||||
use Plumrocket\CookieConsent\Api\IsAllowedCategoryInterface;
|
||||
use Plumrocket\CookieConsent\Api\IsAllowedCookieInterface;
|
||||
use Plumrocket\CookieConsent\Api\IsUserOptInInterface;
|
||||
use Plumrocket\CookieConsent\Helper\Config;
|
||||
use Plumrocket\CookieConsent\Model\Cookie\Name\GetTrueName;
|
||||
use Plumrocket\CookieConsent\Model\ResourceModel\Cookie\GetCategoryKey;
|
||||
use Plumrocket\CookieConsent\Model\ResourceModel\Cookie\IsKnown;
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class IsAllowed implements IsAllowedCookieInterface
|
||||
{
|
||||
/**
|
||||
* System cookie always allowed
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $systemCookies;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Api\CanManageCookieInterface
|
||||
*/
|
||||
private $canManageCookie;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Helper\Config
|
||||
*/
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Model\ResourceModel\Cookie\GetCategoryKey
|
||||
*/
|
||||
private $getCategoryKey;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Api\IsAllowedCategoryInterface
|
||||
*/
|
||||
private $isAllowedCategory;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Model\ResourceModel\Cookie\IsKnown
|
||||
*/
|
||||
private $isKnownCookie;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Api\IsUserOptInInterface
|
||||
*/
|
||||
private $isUserOptIn;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Model\Cookie\Name\GetTrueName
|
||||
*/
|
||||
private $getTrueName;
|
||||
|
||||
/**
|
||||
* @param \Plumrocket\CookieConsent\Api\CanManageCookieInterface $canManageCookie
|
||||
* @param \Plumrocket\CookieConsent\Helper\Config $config
|
||||
* @param \Plumrocket\CookieConsent\Api\IsUserOptInInterface $isUserOptIn
|
||||
* @param \Plumrocket\CookieConsent\Model\ResourceModel\Cookie\GetCategoryKey $getCategoryKey
|
||||
* @param \Plumrocket\CookieConsent\Api\IsAllowedCategoryInterface $isAllowedCategory
|
||||
* @param \Plumrocket\CookieConsent\Model\ResourceModel\Cookie\IsKnown $isKnownCookie
|
||||
* @param \Plumrocket\CookieConsent\Model\Cookie\Name\GetTrueName $getTrueName
|
||||
* @param array $systemCookies
|
||||
*/
|
||||
public function __construct(
|
||||
CanManageCookieInterface $canManageCookie,
|
||||
Config $config,
|
||||
IsUserOptInInterface $isUserOptIn,
|
||||
GetCategoryKey $getCategoryKey,
|
||||
IsAllowedCategoryInterface $isAllowedCategory,
|
||||
IsKnown $isKnownCookie,
|
||||
GetTrueName $getTrueName,
|
||||
array $systemCookies = []
|
||||
) {
|
||||
$this->canManageCookie = $canManageCookie;
|
||||
$this->config = $config;
|
||||
$this->isUserOptIn = $isUserOptIn;
|
||||
$this->getCategoryKey = $getCategoryKey;
|
||||
$this->isAllowedCategory = $isAllowedCategory;
|
||||
$this->isKnownCookie = $isKnownCookie;
|
||||
$this->systemCookies = $systemCookies;
|
||||
$this->getTrueName = $getTrueName;
|
||||
}
|
||||
|
||||
/**
|
||||
* This logic has js alternative in CookieRestriction.isAllowed
|
||||
*
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function execute(string $name): bool
|
||||
{
|
||||
if (in_array($name, $this->systemCookies, true)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (! $this->canManageCookie->execute()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$name = $this->getTrueName->execute($name);
|
||||
|
||||
if (! $this->isUserOptIn->execute()) {
|
||||
if ($this->config->canUseCookieBeforeOptIn()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->isKnownCookie->execute($name)) {
|
||||
return $this->isAllowedCategory->execute($this->getCategoryKey->execute($name));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $this->isKnownCookie->execute($name)) {
|
||||
return ! $this->config->canBlockUnknownCookie();
|
||||
}
|
||||
|
||||
return $this->isAllowedCategory->execute($this->getCategoryKey->execute($name));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
<?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\Model\Cookie;
|
||||
|
||||
use Magento\Framework\Config\DataInterface;
|
||||
use Magento\Framework\Session\Config\ConfigInterface;
|
||||
use Magento\Persistent\Helper\Data as PersistentHelper;
|
||||
use Plumrocket\CookieConsent\Api\GetUserConsentInterface;
|
||||
use Plumrocket\CookieConsent\Api\KnownCookieRegistryInterface;
|
||||
use Plumrocket\CookieConsent\Helper\Config;
|
||||
use Plumrocket\CookieConsent\Model\Category\Attribute\Source\CategoryKey;
|
||||
use Plumrocket\CookieConsent\Model\Cookie\Attribute\Source\Type;
|
||||
use Plumrocket\CookieConsent\Model\User\SetCookieConsentId;
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class KnownCookieRegistry implements KnownCookieRegistryInterface
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $list;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Session\Config\ConfigInterface
|
||||
*/
|
||||
private $sessionConfig;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Helper\Config
|
||||
*/
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* @var \Magento\Persistent\Helper\Data
|
||||
*/
|
||||
private $persistentHelper;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Config\DataInterface
|
||||
*/
|
||||
private $cookieConfig;
|
||||
|
||||
/**
|
||||
* @param \Magento\Framework\Session\Config\ConfigInterface $sessionConfig
|
||||
* @param \Plumrocket\CookieConsent\Helper\Config $config
|
||||
* @param \Magento\Persistent\Helper\Data $persistentHelper
|
||||
* @param \Magento\Framework\Config\DataInterface $cookieConfig
|
||||
* @param array $list
|
||||
*/
|
||||
public function __construct(
|
||||
ConfigInterface $sessionConfig,
|
||||
Config $config,
|
||||
PersistentHelper $persistentHelper,
|
||||
DataInterface $cookieConfig,
|
||||
array $list = []
|
||||
) {
|
||||
$this->list = $list;
|
||||
$this->sessionConfig = $sessionConfig;
|
||||
$this->config = $config;
|
||||
$this->persistentHelper = $persistentHelper;
|
||||
$this->cookieConfig = $cookieConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getList(): array
|
||||
{
|
||||
$magentoCookieLifeTime = $this->sessionConfig->getCookieLifetime();
|
||||
$persistentLifeTime = $this->persistentHelper->getLifeTime();
|
||||
|
||||
$dynamicCookie = [
|
||||
GetUserConsentInterface::COOKIE_CONSENT_NAME => [
|
||||
'category_key' => CategoryKey::KEY_NECESSARY,
|
||||
'type' => Type::TYPE_FIRST,
|
||||
'duration' => $this->config->getConsentExpiry(),
|
||||
'description' => 'Keeps your cookie consent.'
|
||||
],
|
||||
SetCookieConsentId::COOKIE_CONSENT_ID => [
|
||||
'category_key' => CategoryKey::KEY_NECESSARY,
|
||||
'type' => Type::TYPE_FIRST,
|
||||
'duration' => $this->config->getConsentExpiry(),
|
||||
'description' => 'Keeps your cookie consent id.'
|
||||
],
|
||||
'form_key' => [
|
||||
'category_key' => CategoryKey::KEY_NECESSARY,
|
||||
'type' => Type::TYPE_FIRST,
|
||||
'duration' => $magentoCookieLifeTime,
|
||||
'description' => 'A security measure that appends a random ' .
|
||||
'string to all form submissions to protect the data from ' .
|
||||
'Cross-Site Request Forgery (CSRF).'
|
||||
],
|
||||
'X-Magento-Vary' => [
|
||||
'category_key' => CategoryKey::KEY_NECESSARY,
|
||||
'type' => Type::TYPE_FIRST,
|
||||
'duration' => $magentoCookieLifeTime,
|
||||
'description' => 'Configuration setting that improves performance ' .
|
||||
'when using Varnish static content caching.'
|
||||
],
|
||||
'private_content_version' => [
|
||||
'category_key' => CategoryKey::KEY_NECESSARY,
|
||||
'type' => Type::TYPE_FIRST,
|
||||
'duration' => $persistentLifeTime,
|
||||
'description' => 'Appends a random, unique number and time to pages with customer content to prevent ' .
|
||||
'them from being cached on the server.'
|
||||
],
|
||||
|
||||
'persistent_shopping_cart' => [
|
||||
'category_key' => CategoryKey::KEY_NECESSARY,
|
||||
'type' => Type::TYPE_FIRST,
|
||||
'duration' => $persistentLifeTime,
|
||||
'description' => 'Stores the key (ID) of persistent cart to make it possible to restore the cart ' .
|
||||
'for an anonymous shopper.'
|
||||
],
|
||||
|
||||
// Magento Commerce only
|
||||
|
||||
'add_to_cart' => [
|
||||
'category_key' => CategoryKey::KEY_STATISTICS,
|
||||
'type' => Type::TYPE_FIRST,
|
||||
'duration' => Duration::ONE_HOUR,
|
||||
'description' => 'Used by Google Tag Manager. Captures the product SKU, name, price and quantity ' .
|
||||
'removed from the cart, and makes the information available for future integration by third-party '.
|
||||
'scripts.'
|
||||
],
|
||||
|
||||
'mage-banners-cache-storage' => [
|
||||
'category_key' => CategoryKey::KEY_NECESSARY,
|
||||
'type' => Type::TYPE_FIRST,
|
||||
'duration' => Duration::ONE_HOUR,
|
||||
'description' => 'Stores banner content locally to improve performance.'
|
||||
],
|
||||
|
||||
'remove_from_cart' => [
|
||||
'category_key' => CategoryKey::KEY_STATISTICS,
|
||||
'type' => Type::TYPE_FIRST,
|
||||
'duration' => Duration::ONE_HOUR,
|
||||
'description' => 'Used by Google Tag Manager. Captures the product SKU, name, price and quantity ' .
|
||||
'added to the cart, and makes the information available for future integration by third-party ' .
|
||||
'scripts.'
|
||||
],
|
||||
];
|
||||
|
||||
return array_merge($this->cookieConfig->get('cookies'), $this->list, $dynamicCookie);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?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\Model\Cookie\Name;
|
||||
|
||||
use Plumrocket\CookieConsent\Model\ResourceModel\Cookie\GetDynamicNames;
|
||||
|
||||
/**
|
||||
* If cookie name match some pattern if would be replaced to name in data base
|
||||
*
|
||||
* @since 1.1.1
|
||||
*/
|
||||
class GetTrueName
|
||||
{
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Model\ResourceModel\Cookie\GetDynamicNames
|
||||
*/
|
||||
private $getDynamicNames;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Model\Cookie\Name\ToRegex
|
||||
*/
|
||||
private $toRegex;
|
||||
|
||||
/**
|
||||
* @param \Plumrocket\CookieConsent\Model\ResourceModel\Cookie\GetDynamicNames $getDynamicNames
|
||||
* @param \Plumrocket\CookieConsent\Model\Cookie\Name\ToRegex $toRegex
|
||||
*/
|
||||
public function __construct(
|
||||
GetDynamicNames $getDynamicNames,
|
||||
ToRegex $toRegex
|
||||
) {
|
||||
$this->getDynamicNames = $getDynamicNames;
|
||||
$this->toRegex = $toRegex;
|
||||
}
|
||||
|
||||
public function execute(string $name): string
|
||||
{
|
||||
$patterns = $this->toRegex->execute($this->getDynamicNames->execute());
|
||||
|
||||
foreach ($patterns as $dynamicName => $pattern) {
|
||||
if (preg_match("#$pattern#", $name)) {
|
||||
return $dynamicName;
|
||||
}
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
}
|
||||
@@ -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) 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\Model\Cookie\Name;
|
||||
|
||||
/**
|
||||
* Convert dynamic names to regex without borders /../
|
||||
*
|
||||
* @since 1.1.1
|
||||
*/
|
||||
class ToRegex
|
||||
{
|
||||
/**
|
||||
* @param string[] $names
|
||||
* @return string[]
|
||||
*/
|
||||
public function execute(array $names): array
|
||||
{
|
||||
$result = [];
|
||||
foreach ($names as $name) {
|
||||
$result[$name] = str_replace('*', '.*', $name);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?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\Model\Cookie;
|
||||
|
||||
/**
|
||||
* @since 1.8.2
|
||||
*/
|
||||
class ParentDomain
|
||||
{
|
||||
/**
|
||||
* Get parent domain from subdomain.
|
||||
*
|
||||
* @param string $domain
|
||||
* @return string
|
||||
*/
|
||||
public function resolve(string $domain): string
|
||||
{
|
||||
$countDots = substr_count($domain, '.');
|
||||
|
||||
if (1 === $countDots) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (2 === $countDots && preg_match('/\.\w\w\.\w\w/', $domain)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return preg_replace('/[^.]+/', '', $domain, 1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,251 @@
|
||||
<?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\Model;
|
||||
|
||||
use Magento\Eav\Model\Entity\Attribute\Exception as AttributeException;
|
||||
use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface;
|
||||
use Magento\Framework\Api\SearchCriteriaInterface;
|
||||
use Magento\Framework\Api\SearchResultsInterface;
|
||||
use Magento\Framework\Exception\CouldNotSaveException;
|
||||
use Magento\Framework\Exception\InputException;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\Exception\StateException;
|
||||
use Magento\Framework\Exception\ValidatorException;
|
||||
use Plumrocket\CookieConsent\Api\CookieRepositoryInterface;
|
||||
use Plumrocket\CookieConsent\Api\Data\CookieInterface;
|
||||
use Plumrocket\CookieConsent\Api\Data\CookieInterfaceFactory;
|
||||
use Plumrocket\CookieConsent\Api\Data\CookieSearchResultsInterfaceFactory;
|
||||
use Plumrocket\CookieConsent\Api\GetCookieIdByNameInterface;
|
||||
use Plumrocket\CookieConsent\Model\ResourceModel\Cookie\CollectionFactory;
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class CookieRepository implements CookieRepositoryInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @var CookieInterface[][]
|
||||
*/
|
||||
private $instancesById = [];
|
||||
|
||||
/**
|
||||
* @var CookieInterface[][]
|
||||
*/
|
||||
private $instancesByName = [];
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Api\Data\CookieInterfaceFactory
|
||||
*/
|
||||
private $cookieFactory;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Api\Data\CookieSearchResultsInterfaceFactory
|
||||
*/
|
||||
private $searchResultsFactory;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Model\ResourceModel\Cookie
|
||||
*/
|
||||
private $resourceModel;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Api\GetCookieIdByNameInterface
|
||||
*/
|
||||
private $getCookieIdByName;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Model\ResourceModel\Cookie\CollectionFactory
|
||||
*/
|
||||
private $collectionFactory;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface
|
||||
*/
|
||||
private $collectionProcessor;
|
||||
|
||||
/**
|
||||
* CookieRepository constructor.
|
||||
*
|
||||
* @param \Plumrocket\CookieConsent\Api\Data\CookieInterfaceFactory $cookieFactory
|
||||
* @param \Plumrocket\CookieConsent\Api\Data\CookieSearchResultsInterfaceFactory $searchResultsFactory
|
||||
* @param \Plumrocket\CookieConsent\Model\ResourceModel\Cookie $resourceModel
|
||||
* @param \Plumrocket\CookieConsent\Api\GetCookieIdByNameInterface $getCookieIdByName
|
||||
* @param \Plumrocket\CookieConsent\Model\ResourceModel\Cookie\CollectionFactory $collectionFactory
|
||||
* @param \Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface $collectionProcessor
|
||||
*/
|
||||
public function __construct(
|
||||
CookieInterfaceFactory $cookieFactory,
|
||||
CookieSearchResultsInterfaceFactory $searchResultsFactory,
|
||||
\Plumrocket\CookieConsent\Model\ResourceModel\Cookie $resourceModel,
|
||||
GetCookieIdByNameInterface $getCookieIdByName,
|
||||
CollectionFactory $collectionFactory,
|
||||
CollectionProcessorInterface $collectionProcessor
|
||||
) {
|
||||
$this->cookieFactory = $cookieFactory;
|
||||
$this->searchResultsFactory = $searchResultsFactory;
|
||||
$this->resourceModel = $resourceModel;
|
||||
$this->getCookieIdByName = $getCookieIdByName;
|
||||
$this->collectionFactory = $collectionFactory;
|
||||
$this->collectionProcessor = $collectionProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function save(CookieInterface $cookie): CookieInterface
|
||||
{
|
||||
try {
|
||||
$this->clearLocalCache($cookie);
|
||||
$this->resourceModel->save($cookie);
|
||||
} catch (AttributeException $exception) {
|
||||
throw InputException::invalidFieldValue(
|
||||
$exception->getAttributeCode(),
|
||||
$cookie->getData($exception->getAttributeCode()),
|
||||
$exception
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
throw new CouldNotSaveException(
|
||||
__('The cookie was unable to be saved. Please try again.'),
|
||||
$e
|
||||
);
|
||||
}
|
||||
|
||||
$this->clearLocalCache($cookie);
|
||||
|
||||
return $this->getById($cookie->getId(), $cookie->getStoreId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function get(string $name, ?int $storeId = null, bool $forceReload = false): CookieInterface
|
||||
{
|
||||
if (! isset($this->instancesByName[$name][$storeId]) || $forceReload) {
|
||||
$cookieId = $this->getCookieIdByName->execute($name, $forceReload);
|
||||
if (! $cookieId) {
|
||||
throw new NoSuchEntityException(
|
||||
__("The cookie that was requested doesn't exist. Verify the cookie and try again.")
|
||||
);
|
||||
}
|
||||
|
||||
return $this->getById($cookieId);
|
||||
}
|
||||
|
||||
return $this->instancesByName[$name][$storeId];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getById(int $cookieId, ?int $storeId = null, bool $forceReload = false): CookieInterface
|
||||
{
|
||||
if (! isset($this->instancesById[$cookieId][$storeId]) || $forceReload) {
|
||||
/** @var \Plumrocket\CookieConsent\Model\Cookie $cookie */
|
||||
$cookie = $this->cookieFactory->create();
|
||||
if ($storeId !== null) {
|
||||
$cookie->setStoreId($storeId);
|
||||
}
|
||||
$cookie->load($cookieId);
|
||||
if (! $cookie->getId()) {
|
||||
throw new NoSuchEntityException(
|
||||
__("The cookie that was requested doesn't exist. Verify the cookie and try again.")
|
||||
);
|
||||
}
|
||||
|
||||
$this->saveToLocalCache($cookie, $storeId);
|
||||
}
|
||||
|
||||
return $this->instancesById[$cookieId][$storeId];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function delete(CookieInterface $cookie): bool
|
||||
{
|
||||
$cookieId = $cookie->getId();
|
||||
$cookieKey = $cookie->getName();
|
||||
try {
|
||||
$this->clearLocalCache($cookie);
|
||||
$this->resourceModel->delete($cookie);
|
||||
} catch (ValidatorException $e) {
|
||||
throw new CouldNotSaveException(__($e->getMessage()));
|
||||
} catch (\Exception $e) {
|
||||
throw new StateException(
|
||||
__('The "%1" cookie couldn\'t be removed.', $cookieId)
|
||||
);
|
||||
}
|
||||
|
||||
unset($this->instancesById[$cookieId], $this->instancesByName[$cookieKey]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function deleteById(int $id): bool
|
||||
{
|
||||
$cookie = $this->getById($id);
|
||||
return $this->delete($cookie);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getList(SearchCriteriaInterface $searchCriteria): SearchResultsInterface
|
||||
{
|
||||
/** @var \Plumrocket\CookieConsent\Model\ResourceModel\Cookie\Collection $collection */
|
||||
$collection = $this->collectionFactory->create();
|
||||
$collection->addAttributeToSelect('*');
|
||||
$this->collectionProcessor->process($searchCriteria, $collection);
|
||||
|
||||
/** @var \Plumrocket\CookieConsent\Api\Data\CookieSearchResultsInterface $searchResult */
|
||||
$searchResult = $this->searchResultsFactory->create();
|
||||
$searchResult->setSearchCriteria($searchCriteria);
|
||||
$searchResult->setItems($collection->getItems());
|
||||
$searchResult->setTotalCount($collection->getSize());
|
||||
|
||||
return $searchResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save loaded cookie model.
|
||||
*
|
||||
* @param \Plumrocket\CookieConsent\Api\Data\CookieInterface $cookie
|
||||
* @param int|null $storeId
|
||||
*/
|
||||
private function saveToLocalCache(CookieInterface $cookie, ?int $storeId = null): void
|
||||
{
|
||||
$this->instancesById[$cookie->getId()][$storeId] = $cookie;
|
||||
$this->instancesByName[$cookie->getName()][$storeId] = $cookie;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear loaded models.
|
||||
*
|
||||
* @param \Plumrocket\CookieConsent\Api\Data\CookieInterface $cookie
|
||||
*/
|
||||
private function clearLocalCache(CookieInterface $cookie): void
|
||||
{
|
||||
unset($this->instancesById[$cookie->getId()], $this->instancesByName[$cookie->getKey()]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
<?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\Model\Eav;
|
||||
|
||||
use Magento\Catalog\Model\Category\Attribute as CategoryAttribute;
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Attribute extends \Magento\Catalog\Model\Entity\Attribute
|
||||
{
|
||||
/**
|
||||
* Retrieve attribute scope
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getScope()
|
||||
{
|
||||
$scope = (int) $this->_getData(CategoryAttribute::KEY_IS_GLOBAL);
|
||||
if ($scope === CategoryAttribute::SCOPE_GLOBAL) {
|
||||
return CategoryAttribute::SCOPE_GLOBAL_TEXT;
|
||||
}
|
||||
if ($scope === CategoryAttribute::SCOPE_WEBSITE) {
|
||||
return CategoryAttribute::SCOPE_WEBSITE_TEXT;
|
||||
}
|
||||
|
||||
return CategoryAttribute::SCOPE_STORE_TEXT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set attribute scope
|
||||
*
|
||||
* @param string $scope
|
||||
* @return $this
|
||||
*/
|
||||
public function setScope($scope)
|
||||
{
|
||||
if ($scope === CategoryAttribute::SCOPE_GLOBAL_TEXT) {
|
||||
return $this->setData(CategoryAttribute::KEY_IS_GLOBAL, CategoryAttribute::SCOPE_GLOBAL);
|
||||
}
|
||||
if ($scope === CategoryAttribute::SCOPE_WEBSITE_TEXT) {
|
||||
return $this->setData(CategoryAttribute::KEY_IS_GLOBAL, CategoryAttribute::SCOPE_WEBSITE);
|
||||
}
|
||||
if ($scope === CategoryAttribute::SCOPE_STORE_TEXT) {
|
||||
return $this->setData(CategoryAttribute::KEY_IS_GLOBAL, CategoryAttribute::SCOPE_STORE);
|
||||
}
|
||||
|
||||
//Ignore unrecognized scope
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return is attribute global
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getIsGlobal(): int
|
||||
{
|
||||
return (int) $this->_getData(CategoryAttribute::KEY_IS_GLOBAL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve attribute is global scope flag
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isScopeGlobal(): bool
|
||||
{
|
||||
return $this->getIsGlobal() === CategoryAttribute::SCOPE_GLOBAL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve attribute is website scope website
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isScopeWebsite(): bool
|
||||
{
|
||||
return $this->getIsGlobal() === CategoryAttribute::SCOPE_WEBSITE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve attribute is store scope flag
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isScopeStore(): bool
|
||||
{
|
||||
return !$this->isScopeGlobal() && !$this->isScopeWebsite();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?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\Model;
|
||||
|
||||
use Magento\Framework\Api\SearchCriteriaBuilder;
|
||||
use Plumrocket\CookieConsent\Api\CookieRepositoryInterface;
|
||||
use Plumrocket\CookieConsent\Api\GetCookieToCategoryMappingInterface;
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class GetCookieToCategoryMapping implements GetCookieToCategoryMappingInterface
|
||||
{
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Api\CookieRepositoryInterface
|
||||
*/
|
||||
private $cookieRepository;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Api\SearchCriteriaBuilder
|
||||
*/
|
||||
private $searchCriteriaBuilder;
|
||||
|
||||
/**
|
||||
* @var null|string[]
|
||||
*/
|
||||
private $mapping;
|
||||
|
||||
/**
|
||||
* @param \Plumrocket\CookieConsent\Api\CookieRepositoryInterface $cookieRepository
|
||||
* @param \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder
|
||||
*/
|
||||
public function __construct(
|
||||
CookieRepositoryInterface $cookieRepository,
|
||||
SearchCriteriaBuilder $searchCriteriaBuilder
|
||||
) {
|
||||
$this->cookieRepository = $cookieRepository;
|
||||
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function execute(): array
|
||||
{
|
||||
if (null === $this->mapping) {
|
||||
$searchResults = $this->cookieRepository->getList($this->searchCriteriaBuilder->create());
|
||||
|
||||
$this->mapping = [];
|
||||
foreach ($searchResults->getItems() as $cookie) {
|
||||
$this->mapping[$cookie->getName()] = $cookie->getCategoryKey();
|
||||
}
|
||||
}
|
||||
|
||||
return $this->mapping;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
<?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\Model\Integration\AdobeCommerce;
|
||||
|
||||
use Magento\Framework\Module\Manager as ModuleManager;
|
||||
use Plumrocket\Base\Api\ConfigUtilsInterface;
|
||||
use Plumrocket\CookieConsent\Helper\Config;
|
||||
|
||||
/**
|
||||
* @since 2.0.4
|
||||
*/
|
||||
class DataCollection
|
||||
{
|
||||
public const XML_PATH_CATEGORY_KEY = 'pr_cookie/integrations/adobe_commerce_data_collection/category';
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Helper\Config
|
||||
*/
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\Base\Api\ConfigUtilsInterface
|
||||
*/
|
||||
private $configUtils;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Module\Manager
|
||||
*/
|
||||
private $moduleManager;
|
||||
|
||||
/**
|
||||
* @param \Plumrocket\CookieConsent\Helper\Config $config
|
||||
* @param \Plumrocket\Base\Api\ConfigUtilsInterface $configUtils
|
||||
* @param \Magento\Framework\Module\Manager $moduleManager
|
||||
*/
|
||||
public function __construct(
|
||||
Config $config,
|
||||
ConfigUtilsInterface $configUtils,
|
||||
ModuleManager $moduleManager
|
||||
) {
|
||||
$this->config = $config;
|
||||
$this->configUtils = $configUtils;
|
||||
$this->moduleManager = $moduleManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isEnabled(): bool
|
||||
{
|
||||
if (! $this->config->isModuleEnabled() || ! $this->getAssociatedCategoryKey()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $this->moduleManager->isEnabled('Magento_DataServices')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get key of associated cookie category.
|
||||
*
|
||||
* @param int|string|null $store
|
||||
* @return string
|
||||
*/
|
||||
public function getAssociatedCategoryKey($store = null): string
|
||||
{
|
||||
return (string) $this->configUtils->getStoreConfig(self::XML_PATH_CATEGORY_KEY, $store);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
<?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\Model\Integration;
|
||||
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Plumrocket\Base\Api\ConfigUtilsInterface;
|
||||
use Plumrocket\CookieConsent\Api\CategoryRepositoryInterface;
|
||||
use Plumrocket\CookieConsent\Helper\Config;
|
||||
|
||||
/**
|
||||
* @since 1.9.0
|
||||
*/
|
||||
class NoCookieYoutube
|
||||
{
|
||||
|
||||
public const XML_PATH_CATEGORY_KEY = 'pr_cookie/no_cookie_youtube/category';
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Helper\Config
|
||||
*/
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Api\CategoryRepositoryInterface
|
||||
*/
|
||||
private $cookieCategoryRepository;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\Base\Api\ConfigUtilsInterface
|
||||
*/
|
||||
private $configUtils;
|
||||
|
||||
/**
|
||||
* @param \Plumrocket\CookieConsent\Helper\Config $config
|
||||
* @param \Plumrocket\CookieConsent\Api\CategoryRepositoryInterface $cookieCategoryRepository
|
||||
* @param \Plumrocket\Base\Api\ConfigUtilsInterface $configUtils
|
||||
*/
|
||||
public function __construct(
|
||||
Config $config,
|
||||
CategoryRepositoryInterface $cookieCategoryRepository,
|
||||
ConfigUtilsInterface $configUtils
|
||||
) {
|
||||
$this->config = $config;
|
||||
$this->cookieCategoryRepository = $cookieCategoryRepository;
|
||||
$this->configUtils = $configUtils;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the no cookie mode enabled.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isEnabled(): bool
|
||||
{
|
||||
if (! $this->config->isModuleEnabled() || ! $this->getAssociatedCategoryKey()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
$cookieCategory = $this->cookieCategoryRepository->get($this->getAssociatedCategoryKey());
|
||||
return $cookieCategory->isEnabled() && ! $cookieCategory->isEssential();
|
||||
} catch (NoSuchEntityException $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get key of associated cookie category.
|
||||
*
|
||||
* @param int|string|null $store
|
||||
* @return string
|
||||
*/
|
||||
public function getAssociatedCategoryKey($store = null): string
|
||||
{
|
||||
return (string) $this->configUtils->getStoreConfig(self::XML_PATH_CATEGORY_KEY, $store);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace domain in YouTube iframes to no cookie mode.
|
||||
*
|
||||
* @param string $html
|
||||
* @return string
|
||||
*/
|
||||
public function convertHtml(string $html): string
|
||||
{
|
||||
preg_match_all(
|
||||
'/(?:<iframe[^>]*?youtube\.com[^>]*)(?:(?:\/>)|(?:>.*?<\/iframe>))/s',
|
||||
$html,
|
||||
$matches,
|
||||
PREG_PATTERN_ORDER
|
||||
);
|
||||
|
||||
foreach ($matches[0] as $iframe) {
|
||||
$iframeWithNoCookieDomain = str_replace(
|
||||
'youtube.com',
|
||||
'youtube-nocookie.com',
|
||||
$iframe,
|
||||
$domainReplaced
|
||||
);
|
||||
|
||||
if ($domainReplaced) {
|
||||
$html = str_replace($iframe, $iframeWithNoCookieDomain, $html);
|
||||
}
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
+119
@@ -0,0 +1,119 @@
|
||||
<?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\Model\ResourceModel;
|
||||
|
||||
use Magento\Eav\Model\Config;
|
||||
use Magento\Eav\Model\ResourceModel\Entity\Attribute as MagentoEavResourceAttribute;
|
||||
use Magento\Framework\Data\Collection\Db\FetchStrategyInterface;
|
||||
use Magento\Framework\Data\Collection\EntityFactory;
|
||||
use Magento\Framework\DB\Adapter\AdapterInterface;
|
||||
use Magento\Framework\Event\ManagerInterface;
|
||||
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
|
||||
use Plumrocket\CookieConsent\Model\Eav\Attribute as CookieConsentEavAttribute;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*/
|
||||
abstract class AbstractAttributeCollection extends MagentoEavResourceAttribute\Collection
|
||||
{
|
||||
|
||||
public const EAV_ATTRIBUTE_ADDITIONAL_TABLE = 'plumrocket_eav_attribute_additional';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $entityCode;
|
||||
|
||||
/**
|
||||
* Entity factory
|
||||
*
|
||||
* @var \Magento\Eav\Model\EntityFactory
|
||||
*/
|
||||
public $eavEntityFactory;
|
||||
|
||||
/**
|
||||
* @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory
|
||||
* @param \Psr\Log\LoggerInterface $logger
|
||||
* @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy
|
||||
* @param \Magento\Framework\Event\ManagerInterface $eventManager
|
||||
* @param \Magento\Eav\Model\Config $eavConfig
|
||||
* @param \Magento\Eav\Model\EntityFactory $eavEntityFactory
|
||||
* @param \Magento\Framework\DB\Adapter\AdapterInterface|null $connection
|
||||
* @param \Magento\Framework\Model\ResourceModel\Db\AbstractDb|null $resource
|
||||
*/
|
||||
public function __construct(
|
||||
EntityFactory $entityFactory,
|
||||
LoggerInterface $logger,
|
||||
FetchStrategyInterface $fetchStrategy,
|
||||
ManagerInterface $eventManager,
|
||||
Config $eavConfig,
|
||||
\Magento\Eav\Model\EntityFactory $eavEntityFactory,
|
||||
?AdapterInterface $connection = null,
|
||||
?AbstractDb $resource = null
|
||||
) {
|
||||
$this->eavEntityFactory = $eavEntityFactory;
|
||||
|
||||
parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $eavConfig, $connection, $resource);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resource model initialization
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _construct()
|
||||
{
|
||||
$this->_init(
|
||||
CookieConsentEavAttribute::class,
|
||||
MagentoEavResourceAttribute::class
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function _initSelect()
|
||||
{
|
||||
$this->getSelect()->from(
|
||||
['main_table' => $this->getResource()->getMainTable()]
|
||||
)->where(
|
||||
'main_table.entity_type_id=?',
|
||||
$this->eavEntityFactory->create()->setType($this->entityCode)->getTypeId()
|
||||
)->join(
|
||||
['additional_table' => $this->getTable(self::EAV_ATTRIBUTE_ADDITIONAL_TABLE)],
|
||||
'additional_table.attribute_id = main_table.attribute_id'
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify attribute entity type filter
|
||||
*
|
||||
* @param int $typeId
|
||||
* @return $this
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function setEntityTypeFilter($typeId)
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
<?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\Model\ResourceModel;
|
||||
|
||||
use Magento\Catalog\Model\ResourceModel\AbstractResource as CatalogAbstractResource;
|
||||
use Magento\Framework\DataObject;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Plumrocket\CookieConsent\Api\Data\CategoryInterface;
|
||||
|
||||
/**
|
||||
* Export Log resource model.
|
||||
*/
|
||||
class Category extends CatalogAbstractResource
|
||||
{
|
||||
/**
|
||||
* Name of Main Table
|
||||
*/
|
||||
public const MAIN_TABLE_NAME = 'pr_cookie_category_entity';
|
||||
|
||||
/**
|
||||
* Name of Primary Column
|
||||
*/
|
||||
public const ID_FIELD_NAME = 'entity_id';
|
||||
|
||||
/**
|
||||
* @return \Magento\Eav\Model\Entity\Type
|
||||
*/
|
||||
public function getEntityType()
|
||||
{
|
||||
if (empty($this->_type)) {
|
||||
$this->setType(\Plumrocket\CookieConsent\Model\Category::ENTITY);
|
||||
}
|
||||
|
||||
return parent::getEntityType();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve customer entity default attributes
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
protected function _getDefaultAttributes(): array
|
||||
{
|
||||
return [
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform operations before object save
|
||||
*
|
||||
* @param DataObject|CategoryInterface $object
|
||||
* @return \Plumrocket\CookieConsent\Model\ResourceModel\Category
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
protected function _beforeSave(DataObject $object): Category
|
||||
{
|
||||
if (CategoryInterface::ALL_CATEGORIES === $object->getKey()) {
|
||||
throw new LocalizedException(
|
||||
__('A cookie category key cannot be "all" because it reserved by extension.')
|
||||
);
|
||||
}
|
||||
|
||||
if (! $this->isUniqueKey($object)) {
|
||||
throw new LocalizedException(
|
||||
__('A cookie category with the same key already exists.')
|
||||
);
|
||||
}
|
||||
|
||||
// Delete spaces to correct selection categories with scripts.
|
||||
$object->setHeadScripts(trim($object->getHeadScripts()));
|
||||
$object->setFooterMiscellaneousHtml(trim($object->getFooterMiscellaneousHtml()));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if key is unique.
|
||||
*
|
||||
* @param \Plumrocket\CookieConsent\Api\Data\CategoryInterface $category
|
||||
* @return bool
|
||||
*/
|
||||
private function isUniqueKey(CategoryInterface $category): bool
|
||||
{
|
||||
$select = $this->getConnection()->select()
|
||||
->from($this->getTable(self::MAIN_TABLE_NAME))
|
||||
->where('\'key\' = ? ', $category->getKey());
|
||||
|
||||
if ($category->getId()) {
|
||||
$select->where(self::ID_FIELD_NAME . ' <> ?', $category->getId());
|
||||
}
|
||||
|
||||
if ($this->getConnection()->fetchRow($select)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
<?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\Model\ResourceModel\Category\Attribute;
|
||||
|
||||
use Plumrocket\CookieConsent\Model\Category;
|
||||
use Plumrocket\CookieConsent\Model\ResourceModel\AbstractAttributeCollection;
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Collection extends AbstractAttributeCollection
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $entityCode = Category::ENTITY;
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?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\Model\ResourceModel\Category;
|
||||
|
||||
use Magento\Catalog\Model\ResourceModel\Collection\AbstractCollection;
|
||||
use Plumrocket\CookieConsent\Api\Data\CategoryInterface;
|
||||
use Plumrocket\CookieConsent\Model\Category;
|
||||
use Plumrocket\CookieConsent\Model\ResourceModel\Category as CategoryResource;
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
* @method CategoryInterface[] getItems()
|
||||
*/
|
||||
class Collection extends AbstractCollection
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $idFieldName = CategoryResource::ID_FIELD_NAME;
|
||||
|
||||
/**
|
||||
* Resource initialization.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _construct()
|
||||
{
|
||||
$this->_init(Category::class, CategoryResource::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?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\Model\ResourceModel\Category;
|
||||
|
||||
use Plumrocket\CookieConsent\Api\GetCategoryIdByKeyInterface;
|
||||
use Plumrocket\CookieConsent\Model\ResourceModel\Category;
|
||||
|
||||
/**
|
||||
* Retrieve category id by its key
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class GetIdByKey implements GetCategoryIdByKeyInterface
|
||||
{
|
||||
/**
|
||||
* @var int[]
|
||||
*/
|
||||
private $ids = [];
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Model\ResourceModel\Category
|
||||
*/
|
||||
private $category;
|
||||
|
||||
/**
|
||||
* GetIdByKey constructor.
|
||||
*
|
||||
* @param \Plumrocket\CookieConsent\Model\ResourceModel\Category $category
|
||||
*/
|
||||
public function __construct(Category $category)
|
||||
{
|
||||
$this->category = $category;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function execute(string $key, bool $forceReload = false): int
|
||||
{
|
||||
if (! isset($this->ids[$key])) {
|
||||
$connection = $this->category->getConnection();
|
||||
|
||||
$select = $connection->select()
|
||||
->from($this->category->getEntityTable(), 'entity_id')
|
||||
->where('`key` = :key');
|
||||
|
||||
$bind = [':key' => $key];
|
||||
|
||||
$this->ids[$key] = (int) $connection->fetchOne($select, $bind);
|
||||
}
|
||||
|
||||
return $this->ids[$key];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?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\Model\ResourceModel\Category;
|
||||
|
||||
use Magento\Framework\App\ResourceConnection;
|
||||
use Plumrocket\CookieConsent\Model\ResourceModel\Category;
|
||||
|
||||
/**
|
||||
* Retrieve keys of created categories
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class GetKeys
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\App\ResourceConnection
|
||||
*/
|
||||
private $resourceConnection;
|
||||
|
||||
/**
|
||||
* GetNames constructor.
|
||||
*
|
||||
* @param \Magento\Framework\App\ResourceConnection $resourceConnection
|
||||
*/
|
||||
public function __construct(ResourceConnection $resourceConnection)
|
||||
{
|
||||
$this->resourceConnection = $resourceConnection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function execute(): array
|
||||
{
|
||||
$connection = $this->resourceConnection->getConnection();
|
||||
|
||||
$select = $connection
|
||||
->select()
|
||||
->from(
|
||||
['main_table' => $this->resourceConnection->getTableName(Category::MAIN_TABLE_NAME)],
|
||||
['key']
|
||||
);
|
||||
|
||||
return $connection->fetchCol($select);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?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\Model\ResourceModel;
|
||||
|
||||
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
|
||||
use Magento\Framework\View\Element\UiComponent\DataProvider\Document;
|
||||
use Plumrocket\CookieConsent\Api\Data\ConsentLogInterface;
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class ConsentLog extends AbstractDb
|
||||
{
|
||||
/**
|
||||
* Name of Main Table
|
||||
*/
|
||||
public const MAIN_TABLE_NAME = 'pr_cookie_consent_log';
|
||||
|
||||
/**
|
||||
* Name of Primary Column
|
||||
*/
|
||||
public const ID_FIELD_NAME = 'consent_id';
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected $_serializableFields = [
|
||||
ConsentLogInterface::SETTINGS => [[], []],
|
||||
];
|
||||
|
||||
/**
|
||||
* Resource initialization
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _construct()
|
||||
{
|
||||
$this->_init(self::MAIN_TABLE_NAME, self::ID_FIELD_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Magento\Framework\View\Element\UiComponent\DataProvider\Document $consentLog
|
||||
*/
|
||||
public function unserializeDataProviderDocumentFields(Document $consentLog)
|
||||
{
|
||||
foreach ($this->_serializableFields as $field => list($serializeDefault, $unserializeDefault)) {
|
||||
$this->_unserializeField($consentLog, $field, $unserializeDefault);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?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\Model\ResourceModel\ConsentLog;
|
||||
|
||||
use Magento\Framework\DataObject;
|
||||
use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
|
||||
use Plumrocket\CookieConsent\Model\Consent\Log;
|
||||
use Plumrocket\CookieConsent\Model\ResourceModel\ConsentLog as ConsentLogResource;
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Collection extends AbstractCollection
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $idFieldName = ConsentLogResource::ID_FIELD_NAME;
|
||||
|
||||
/**
|
||||
* Resource initialization.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _construct()
|
||||
{
|
||||
$this->_init(
|
||||
Log::class,
|
||||
ConsentLogResource::class
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Magento\Framework\DataObject|\Magento\Framework\Model\AbstractModel $item
|
||||
* @return \Magento\Framework\DataObject
|
||||
*/
|
||||
protected function beforeAddLoadedItem(DataObject $item)
|
||||
{
|
||||
$this->getResource()->unserializeFields($item);
|
||||
return parent::beforeAddLoadedItem($item);
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Plumrocket\CookieConsent\Model\ResourceModel\ConsentLog\Grid;
|
||||
|
||||
use Magento\Framework\Data\Collection\Db\FetchStrategyInterface;
|
||||
use Magento\Framework\Data\Collection\EntityFactoryInterface;
|
||||
use Magento\Framework\DataObject;
|
||||
use Magento\Framework\Event\ManagerInterface;
|
||||
use Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult;
|
||||
use Plumrocket\CookieConsent\Api\Data\ConsentLogInterface;
|
||||
use Plumrocket\CookieConsent\Model\ResourceModel\ConsentLog as ConsentLogResource;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class Collection extends SearchResult
|
||||
{
|
||||
/**
|
||||
* Initialize dependencies.
|
||||
*
|
||||
* @param \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory
|
||||
* @param \Psr\Log\LoggerInterface $logger
|
||||
* @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy
|
||||
* @param \Magento\Framework\Event\ManagerInterface $eventManager
|
||||
* @param string $mainTable
|
||||
* @param string $resourceModel
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
public function __construct(// @codingStandardsIgnoreLine $mainTable and $resourceModel specified here
|
||||
EntityFactoryInterface $entityFactory,
|
||||
LoggerInterface $logger,
|
||||
FetchStrategyInterface $fetchStrategy,
|
||||
ManagerInterface $eventManager,
|
||||
$mainTable = ConsentLogResource::MAIN_TABLE_NAME,
|
||||
$resourceModel = ConsentLogResource::class
|
||||
) {
|
||||
parent::__construct(
|
||||
$entityFactory,
|
||||
$logger,
|
||||
$fetchStrategy,
|
||||
$eventManager,
|
||||
$mainTable,
|
||||
$resourceModel
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialization here
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _initSelect()
|
||||
{
|
||||
parent::_initSelect();
|
||||
$this->addCustomData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add custom data to collection
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function addCustomData()
|
||||
{
|
||||
$this->getSelect()
|
||||
->joinLeft(
|
||||
['cg' => $this->getTable('customer_grid_flat')],
|
||||
'cg.entity_id = main_table.customer_id',
|
||||
['cg.name as customer_name', 'cg.email as customer_email', 'cg.entity_id as customer_exist']
|
||||
)->joinLeft(
|
||||
['sw' => $this->getTable('store_website')],
|
||||
'sw.website_id = main_table.website_id',
|
||||
['sw.name as website']
|
||||
);
|
||||
|
||||
$this->getSelect()->columns(
|
||||
['merge_email' => new \Zend_Db_Expr('IF(ISNULL(`cg`.`email`), `main_table`.`guest_email`, `cg`.`email`)')]
|
||||
);
|
||||
|
||||
$filtersMap = [
|
||||
ConsentLogResource::ID_FIELD_NAME => 'main_table.' . ConsentLogResource::ID_FIELD_NAME,
|
||||
ConsentLogInterface::CUSTOMER_ID => 'main_table.' . ConsentLogInterface::CUSTOMER_ID,
|
||||
'customer_name' => 'cg.name',
|
||||
'customer_exist' => 'cg.entity_id',
|
||||
'website' => 'sw.name',
|
||||
ConsentLogInterface::CREATED_AT => 'main_table.' . ConsentLogInterface::CREATED_AT,
|
||||
ConsentLogInterface::IP_ADDRESS => 'main_table.' . ConsentLogInterface::IP_ADDRESS,
|
||||
ConsentLogInterface::SETTINGS => 'main_table.' . ConsentLogInterface::SETTINGS,
|
||||
];
|
||||
|
||||
foreach ($filtersMap as $filter => $alias) {
|
||||
$this->addFilterToMap($filter, $alias);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom filter for 'merge_email' field
|
||||
*
|
||||
* @param array|string $field
|
||||
* @param null $condition
|
||||
* @return $this|\Plumrocket\CookieConsent\Model\ResourceModel\ConsentLog\Grid\Collection
|
||||
*/
|
||||
public function addFieldToFilter($field, $condition = null)
|
||||
{
|
||||
if ('merge_email' === $field) {
|
||||
$this->getSelect()->where(
|
||||
"(`cg`.`email` LIKE ? OR (`main_table`.`guest_email` LIKE ? AND `cg`.`email` IS NULL))",
|
||||
$condition['like']
|
||||
);
|
||||
return $this;
|
||||
}
|
||||
|
||||
return parent::addFieldToFilter($field, $condition);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Magento\Framework\DataObject|\Magento\Framework\Model\AbstractModel $item
|
||||
* @return \Magento\Framework\DataObject
|
||||
*/
|
||||
protected function beforeAddLoadedItem(DataObject $item)
|
||||
{
|
||||
$this->getResource()->unserializeDataProviderDocumentFields($item);
|
||||
return parent::beforeAddLoadedItem($item);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
<?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\Model\ResourceModel;
|
||||
|
||||
use Magento\Catalog\Model\ResourceModel\AbstractResource as CatalogAbstractResource;
|
||||
use Magento\Framework\DataObject;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Plumrocket\CookieConsent\Api\Data\CookieInterface;
|
||||
|
||||
/**
|
||||
* Export Log resource model.
|
||||
*/
|
||||
class Cookie extends CatalogAbstractResource
|
||||
{
|
||||
/**
|
||||
* Name of Main Table
|
||||
*/
|
||||
public const MAIN_TABLE_NAME = 'pr_cookie_entity';
|
||||
|
||||
/**
|
||||
* Name of Primary Column
|
||||
*/
|
||||
public const ID_FIELD_NAME = 'entity_id';
|
||||
|
||||
/**
|
||||
* @return \Magento\Eav\Model\Entity\Type
|
||||
*/
|
||||
public function getEntityType()
|
||||
{
|
||||
if (empty($this->_type)) {
|
||||
$this->setType(\Plumrocket\CookieConsent\Model\Cookie::ENTITY);
|
||||
}
|
||||
|
||||
return parent::getEntityType();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve customer entity default attributes
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
protected function _getDefaultAttributes(): array
|
||||
{
|
||||
return [
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform operations before object save
|
||||
*
|
||||
* @param DataObject|CookieInterface $object
|
||||
* @return \Plumrocket\CookieConsent\Model\ResourceModel\Cookie
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
protected function _beforeSave(DataObject $object): Cookie
|
||||
{
|
||||
if (! $this->isUniqueCookieName($object)) {
|
||||
throw new LocalizedException(
|
||||
__('A cookie with the same name already exists. Please update old cookie or delete it.')
|
||||
);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Plumrocket\CookieConsent\Api\Data\CookieInterface $cookie
|
||||
* @return bool
|
||||
*/
|
||||
private function isUniqueCookieName(CookieInterface $cookie): bool
|
||||
{
|
||||
$select = $this->getConnection()->select()
|
||||
->from($this->getTable(self::MAIN_TABLE_NAME))
|
||||
->where('name = ? ', $cookie->getName());
|
||||
|
||||
if ($cookie->getId()) {
|
||||
$select->where(self::ID_FIELD_NAME . ' <> ?', $cookie->getId());
|
||||
}
|
||||
|
||||
if ($this->getConnection()->fetchRow($select)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?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\Model\ResourceModel\Cookie\Attribute;
|
||||
|
||||
use Plumrocket\CookieConsent\Model\Cookie;
|
||||
use Plumrocket\CookieConsent\Model\ResourceModel\AbstractAttributeCollection;
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Collection extends AbstractAttributeCollection
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $entityCode = Cookie::ENTITY;
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?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\Model\ResourceModel\Cookie;
|
||||
|
||||
use Magento\Catalog\Model\ResourceModel\Collection\AbstractCollection;
|
||||
use Plumrocket\CookieConsent\Api\Data\CookieInterface;
|
||||
use Plumrocket\CookieConsent\Model\Cookie;
|
||||
use Plumrocket\CookieConsent\Model\ResourceModel\Cookie as CookieResource;
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
* @method CookieInterface[]|Cookie[] getItems()
|
||||
*/
|
||||
class Collection extends AbstractCollection
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $idFieldName = CookieResource::ID_FIELD_NAME;
|
||||
|
||||
/**
|
||||
* Resource initialization.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _construct()
|
||||
{
|
||||
$this->_init(Cookie::class, CookieResource::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?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\Model\ResourceModel\Cookie;
|
||||
|
||||
use Magento\Framework\App\ResourceConnection;
|
||||
use Plumrocket\CookieConsent\Model\ResourceModel\Cookie;
|
||||
|
||||
class GetCategoryKey
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\App\ResourceConnection
|
||||
*/
|
||||
private $resourceConnection;
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
private $categoryKey = [];
|
||||
|
||||
/**
|
||||
* GetIdByName constructor.
|
||||
*
|
||||
* @param \Magento\Framework\App\ResourceConnection $resourceConnection
|
||||
*/
|
||||
public function __construct(ResourceConnection $resourceConnection)
|
||||
{
|
||||
$this->resourceConnection = $resourceConnection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param bool $forceReload
|
||||
* @return string
|
||||
*/
|
||||
public function execute(string $name, bool $forceReload = false): string
|
||||
{
|
||||
if (! isset($this->categoryKey[$name]) || $forceReload) {
|
||||
$connection = $this->resourceConnection->getConnection();
|
||||
|
||||
$select = $connection
|
||||
->select()
|
||||
->from($this->resourceConnection->getTableName(Cookie::MAIN_TABLE_NAME), 'category_key')
|
||||
->where('name = :name');
|
||||
|
||||
$bind = [':name' => $name];
|
||||
|
||||
$this->categoryKey[$name] = (string) $connection->fetchOne($select, $bind);
|
||||
}
|
||||
|
||||
return $this->categoryKey[$name];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?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\Model\ResourceModel\Cookie;
|
||||
|
||||
use Magento\Framework\App\ResourceConnection;
|
||||
use Plumrocket\CookieConsent\Model\ResourceModel\Cookie;
|
||||
|
||||
/**
|
||||
* Get all names with * symbol
|
||||
*
|
||||
* @since 1.1.1
|
||||
*/
|
||||
class GetDynamicNames
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\App\ResourceConnection
|
||||
*/
|
||||
private $resourceConnection;
|
||||
|
||||
/**
|
||||
* GetNames constructor.
|
||||
*
|
||||
* @param \Magento\Framework\App\ResourceConnection $resourceConnection
|
||||
*/
|
||||
public function __construct(ResourceConnection $resourceConnection)
|
||||
{
|
||||
$this->resourceConnection = $resourceConnection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function execute(): array
|
||||
{
|
||||
$connection = $this->resourceConnection->getConnection();
|
||||
|
||||
$select = $connection
|
||||
->select()
|
||||
->from(
|
||||
['main_table' => $this->resourceConnection->getTableName(Cookie::MAIN_TABLE_NAME)],
|
||||
['name']
|
||||
)->where('name LIKE \'%*%\'');
|
||||
|
||||
return $connection->fetchCol($select);
|
||||
}
|
||||
}
|
||||
@@ -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) 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\Model\ResourceModel\Cookie;
|
||||
|
||||
use Magento\Framework\App\ResourceConnection;
|
||||
use Plumrocket\CookieConsent\Api\GetCookieIdByNameInterface;
|
||||
use Plumrocket\CookieConsent\Model\ResourceModel\Cookie;
|
||||
|
||||
/**
|
||||
* Retrieve cookie id by cookie name
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class GetIdByName implements GetCookieIdByNameInterface
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\App\ResourceConnection
|
||||
*/
|
||||
private $resourceConnection;
|
||||
|
||||
/**
|
||||
* @var int[]
|
||||
*/
|
||||
private $ids = [];
|
||||
|
||||
/**
|
||||
* GetIdByName constructor.
|
||||
*
|
||||
* @param \Magento\Framework\App\ResourceConnection $resourceConnection
|
||||
*/
|
||||
public function __construct(ResourceConnection $resourceConnection)
|
||||
{
|
||||
$this->resourceConnection = $resourceConnection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function execute(string $name, bool $forceReload = false): int
|
||||
{
|
||||
if (! isset($this->ids[$name]) || $forceReload) {
|
||||
$connection = $this->resourceConnection->getConnection();
|
||||
|
||||
$select = $connection
|
||||
->select()
|
||||
->from($this->resourceConnection->getTableName(Cookie::MAIN_TABLE_NAME), 'entity_id')
|
||||
->where('name = :name');
|
||||
|
||||
$bind = [':name' => $name];
|
||||
|
||||
$this->ids[$name] = (int) $connection->fetchOne($select, $bind);
|
||||
}
|
||||
|
||||
return $this->ids[$name];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?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\Model\ResourceModel\Cookie;
|
||||
|
||||
use Magento\Framework\App\ResourceConnection;
|
||||
use Plumrocket\CookieConsent\Model\ResourceModel\Cookie;
|
||||
|
||||
class GetNames
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\App\ResourceConnection
|
||||
*/
|
||||
private $resourceConnection;
|
||||
|
||||
/**
|
||||
* GetNames constructor.
|
||||
*
|
||||
* @param \Magento\Framework\App\ResourceConnection $resourceConnection
|
||||
*/
|
||||
public function __construct(ResourceConnection $resourceConnection)
|
||||
{
|
||||
$this->resourceConnection = $resourceConnection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function execute() : array
|
||||
{
|
||||
$connection = $this->resourceConnection->getConnection();
|
||||
|
||||
$select = $connection
|
||||
->select()
|
||||
->from(
|
||||
['main_table' => $this->resourceConnection->getTableName(Cookie::MAIN_TABLE_NAME)],
|
||||
['name']
|
||||
);
|
||||
|
||||
return $connection->fetchCol($select);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
<?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\Model\ResourceModel\Cookie\Grid;
|
||||
|
||||
use Plumrocket\CookieConsent\Model\ResourceModel\Cookie\Collection as CookieCollection;
|
||||
use Magento\Framework\Session\Config\ConfigInterface;
|
||||
use Magento\Framework\Data\Collection\EntityFactory;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Magento\Framework\Data\Collection\Db\FetchStrategyInterface;
|
||||
use Magento\Framework\Event\ManagerInterface;
|
||||
use Magento\Eav\Model\Config;
|
||||
use Magento\Framework\App\ResourceConnection;
|
||||
use Magento\Eav\Model\EntityFactory as EavEntityFactory;
|
||||
use Magento\Eav\Model\ResourceModel\Helper;
|
||||
use Magento\Framework\Validator\UniversalFactory;
|
||||
use Magento\Store\Model\StoreManagerInterface;
|
||||
use Magento\Framework\DB\Adapter\AdapterInterface;
|
||||
use Plumrocket\CookieConsent\Model\Cookie\Attribute\Source\Type;
|
||||
use Plumrocket\CookieConsent\Api\Data\CookieInterface;
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Collection extends CookieCollection
|
||||
{
|
||||
public const DOMAIN_LABEL = 'domain_label';
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Session\Config\ConfigInterface
|
||||
*/
|
||||
private $sessionConfig;
|
||||
|
||||
/**
|
||||
* Collection constructor.
|
||||
*
|
||||
* @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory
|
||||
* @param \Psr\Log\LoggerInterface $logger
|
||||
* @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy
|
||||
* @param \Magento\Framework\Event\ManagerInterface $eventManager
|
||||
* @param \Magento\Eav\Model\Config $eavConfig
|
||||
* @param \Magento\Framework\App\ResourceConnection $resource
|
||||
* @param \Magento\Eav\Model\EntityFactory $eavEntityFactory
|
||||
* @param \Magento\Eav\Model\ResourceModel\Helper $resourceHelper
|
||||
* @param \Magento\Framework\Validator\UniversalFactory $universalFactory
|
||||
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
|
||||
* @param \Magento\Framework\Session\Config\ConfigInterface $sessionConfig
|
||||
* @param \Magento\Framework\DB\Adapter\AdapterInterface|null $connection
|
||||
*/
|
||||
public function __construct(
|
||||
EntityFactory $entityFactory,
|
||||
LoggerInterface $logger,
|
||||
FetchStrategyInterface $fetchStrategy,
|
||||
ManagerInterface $eventManager,
|
||||
Config $eavConfig,
|
||||
ResourceConnection $resource,
|
||||
EavEntityFactory $eavEntityFactory,
|
||||
Helper $resourceHelper,
|
||||
UniversalFactory $universalFactory,
|
||||
StoreManagerInterface $storeManager,
|
||||
ConfigInterface $sessionConfig,
|
||||
?AdapterInterface $connection = null
|
||||
) {
|
||||
$this->sessionConfig = $sessionConfig;
|
||||
parent::__construct(
|
||||
$entityFactory,
|
||||
$logger,
|
||||
$fetchStrategy,
|
||||
$eventManager,
|
||||
$eavConfig,
|
||||
$resource,
|
||||
$eavEntityFactory,
|
||||
$resourceHelper,
|
||||
$universalFactory,
|
||||
$storeManager,
|
||||
$connection
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
protected function _initSelect(): self
|
||||
{
|
||||
parent::_initSelect();
|
||||
|
||||
$cookieDomain = $this->sessionConfig->getCookieDomain();
|
||||
$domainColumn = CookieInterface::DOMAIN;
|
||||
$typeColumn = CookieInterface::TYPE;
|
||||
$expression = 'IF(' . $typeColumn . ' = "' . Type::TYPE_FIRST . '" AND isnull(' . $domainColumn . '), "' .
|
||||
$cookieDomain . '", ' . $domainColumn .') AS ' . self::DOMAIN_LABEL . ' ';
|
||||
|
||||
$this->getSelect()->columns(new \Zend_Db_Expr($expression));
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?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\Model\ResourceModel\Cookie;
|
||||
|
||||
/**
|
||||
* Retrieve if there's cookie with requested name in the database
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class IsKnown
|
||||
{
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Model\ResourceModel\Cookie\GetCategoryKey
|
||||
*/
|
||||
private $getCookieCategoryKey;
|
||||
|
||||
/**
|
||||
* @param \Plumrocket\CookieConsent\Model\ResourceModel\Cookie\GetCategoryKey $getCategoryKey
|
||||
*/
|
||||
public function __construct(GetCategoryKey $getCategoryKey)
|
||||
{
|
||||
$this->getCookieCategoryKey = $getCategoryKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param bool $forceReload
|
||||
* @return bool
|
||||
*/
|
||||
public function execute(string $name, bool $forceReload = false): bool
|
||||
{
|
||||
/**
|
||||
* As category_key is required field for cookie, if GetCategoryKey returns '' it means that cookie unknown
|
||||
* So, we optimize request count to database, because GetCategoryKey has local cache
|
||||
*/
|
||||
return (bool) $this->getCookieCategoryKey->execute($name, $forceReload);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?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\Model\User;
|
||||
|
||||
use Magento\Framework\Exception\NotFoundException;
|
||||
use Magento\Framework\Serialize\SerializerInterface;
|
||||
use Magento\Framework\Stdlib\Cookie\CookieReaderInterface;
|
||||
use Plumrocket\CookieConsent\Api\Data\CategoryInterface;
|
||||
use Plumrocket\CookieConsent\Api\GetUserConsentInterface;
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class GetConsent implements GetUserConsentInterface
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\Stdlib\Cookie\CookieReaderInterface
|
||||
*/
|
||||
private $cookieReader;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Serialize\SerializerInterface
|
||||
*/
|
||||
private $serializer;
|
||||
|
||||
/**
|
||||
* @param \Magento\Framework\Stdlib\Cookie\CookieReaderInterface $cookieReader
|
||||
* @param \Magento\Framework\Serialize\SerializerInterface $serializer
|
||||
*/
|
||||
public function __construct(
|
||||
CookieReaderInterface $cookieReader,
|
||||
SerializerInterface $serializer
|
||||
) {
|
||||
$this->cookieReader = $cookieReader;
|
||||
$this->serializer = $serializer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function execute(): array
|
||||
{
|
||||
$consent = $this->cookieReader->getCookie(self::COOKIE_CONSENT_NAME);
|
||||
if (null === $consent) {
|
||||
throw new NotFoundException(__('User didnt make any consents.'));
|
||||
}
|
||||
|
||||
/**
|
||||
* todo: remove in 2022
|
||||
*
|
||||
* Previously we used "*" for "all categories" but cookie with this value is blocked by mod security
|
||||
* @see REQUEST-942-APPLICATION-ATTACK-SQLI
|
||||
*/
|
||||
$consent = str_replace('*', CategoryInterface::ALL_CATEGORIES, $consent);
|
||||
return $this->serializer->unserialize($consent);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?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\Model\User;
|
||||
|
||||
use Magento\Framework\Exception\NotFoundException;
|
||||
use Plumrocket\CookieConsent\Api\GetUserConsentInterface;
|
||||
use Plumrocket\CookieConsent\Api\IsUserOptInInterface;
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class IsOptIn implements IsUserOptInInterface
|
||||
{
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Api\GetUserConsentInterface
|
||||
*/
|
||||
private $getUserConsent;
|
||||
|
||||
/**
|
||||
* @param \Plumrocket\CookieConsent\Api\GetUserConsentInterface $getUserConsent
|
||||
*/
|
||||
public function __construct(GetUserConsentInterface $getUserConsent)
|
||||
{
|
||||
$this->getUserConsent = $getUserConsent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function execute(): bool
|
||||
{
|
||||
try {
|
||||
$this->getUserConsent->execute();
|
||||
return true;
|
||||
} catch (NotFoundException $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?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\Model\User;
|
||||
|
||||
use Magento\Framework\Stdlib\Cookie\PublicCookieMetadata;
|
||||
use Magento\Framework\Stdlib\CookieManagerInterface;
|
||||
use Magento\Framework\Stdlib\Cookie\PublicCookieMetadataFactory;
|
||||
use Plumrocket\CookieConsent\Helper\Config;
|
||||
|
||||
/**
|
||||
* @since 1.6.0
|
||||
*/
|
||||
class SetCookieConsentId
|
||||
{
|
||||
public const COOKIE_CONSENT_ID = 'pr-cookie-consent-id';
|
||||
|
||||
/**
|
||||
* @var CookieManagerInterface
|
||||
*/
|
||||
private $cookieManager;
|
||||
|
||||
/**
|
||||
* @var PublicCookieMetadataFactory
|
||||
*/
|
||||
private $publicCookieMetadataFactory;
|
||||
|
||||
/**
|
||||
* @var Config
|
||||
*/
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* @param CookieManagerInterface $cookieManager
|
||||
* @param PublicCookieMetadataFactory $publicCookieMetadataFactory
|
||||
* @param Config $config
|
||||
*/
|
||||
public function __construct(
|
||||
CookieManagerInterface $cookieManager,
|
||||
PublicCookieMetadataFactory $publicCookieMetadataFactory,
|
||||
Config $config
|
||||
) {
|
||||
$this->cookieManager = $cookieManager;
|
||||
$this->publicCookieMetadataFactory = $publicCookieMetadataFactory;
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the user's consent id in browser's cookie
|
||||
*
|
||||
* @param int $consentId
|
||||
* @return void
|
||||
* @throws \Magento\Framework\Exception\InputException
|
||||
* @throws \Magento\Framework\Stdlib\Cookie\CookieSizeLimitReachedException
|
||||
* @throws \Magento\Framework\Stdlib\Cookie\FailureToSendException
|
||||
*/
|
||||
public function execute(int $consentId): void
|
||||
{
|
||||
/** @var PublicCookieMetadata $publicCookieMetadata */
|
||||
$publicCookieMetadata = $this->publicCookieMetadataFactory->create(['metadata' => []]);
|
||||
$publicCookieMetadata
|
||||
->setDuration($this->config->getConsentExpiry() * 86400)
|
||||
->setPath('/');
|
||||
$this->cookieManager->setPublicCookie(self::COOKIE_CONSENT_ID, $consentId, $publicCookieMetadata);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user