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