ltsecurityinc安防产品在线商城代码
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user