ltsecurityinc安防产品在线商城代码
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
<?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\ViewModel;
|
||||
|
||||
use Magento\Framework\Api\SearchCriteriaBuilder;
|
||||
use Magento\Framework\View\Element\Block\ArgumentInterface;
|
||||
use Plumrocket\CookieConsent\Api\CookieRepositoryInterface;
|
||||
use Plumrocket\CookieConsent\Api\Data\CategoryInterface;
|
||||
use Plumrocket\CookieConsent\Api\Data\CookieInterface;
|
||||
|
||||
/**
|
||||
* @since 1.7.0
|
||||
*/
|
||||
class CookieProvider implements ArgumentInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @var null|\Plumrocket\CookieConsent\Api\Data\CookieInterface[]
|
||||
*/
|
||||
private $cookies;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Api\SearchCriteriaBuilder
|
||||
*/
|
||||
private $searchCriteriaBuilder;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Api\CookieRepositoryInterface
|
||||
*/
|
||||
private $cookieRepository;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\ViewModel\CategoryProvider
|
||||
*/
|
||||
private $categoryProvider;
|
||||
|
||||
/**
|
||||
* @param \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder
|
||||
* @param \Plumrocket\CookieConsent\Api\CookieRepositoryInterface $cookieRepository
|
||||
* @param \Plumrocket\CookieConsent\ViewModel\CategoryProvider $categoryProvider
|
||||
*/
|
||||
public function __construct(
|
||||
SearchCriteriaBuilder $searchCriteriaBuilder,
|
||||
CookieRepositoryInterface $cookieRepository,
|
||||
CategoryProvider $categoryProvider
|
||||
) {
|
||||
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
|
||||
$this->cookieRepository = $cookieRepository;
|
||||
$this->categoryProvider = $categoryProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cookie data for render.
|
||||
*
|
||||
* @return \Plumrocket\CookieConsent\Api\Data\CookieInterface[]
|
||||
*/
|
||||
public function get(): array
|
||||
{
|
||||
if (null === $this->cookies) {
|
||||
$categoriesKeys = array_map(static function (CategoryInterface $category) {
|
||||
return $category->getKey();
|
||||
}, $this->categoryProvider->get());
|
||||
$this->searchCriteriaBuilder->addFilter(
|
||||
CookieInterface::CATEGORY_KEY,
|
||||
$categoriesKeys,
|
||||
'in'
|
||||
);
|
||||
$this->cookies = $this->cookieRepository->getList($this->searchCriteriaBuilder->create())->getItems();
|
||||
}
|
||||
return $this->cookies;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user