ltsecurityinc安防产品在线商城代码
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
<?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\Api\SortOrderBuilder;
|
||||
use Magento\Framework\View\Element\Block\ArgumentInterface;
|
||||
use Plumrocket\CookieConsent\Api\CategoryRepositoryInterface;
|
||||
use Plumrocket\CookieConsent\Api\Data\CategoryInterface;
|
||||
use Plumrocket\CookieConsent\Model\ResourceModel\Category as CategoryResource;
|
||||
|
||||
/**
|
||||
* @since 1.7.0
|
||||
*/
|
||||
class CategoryProvider implements ArgumentInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @var null|\Plumrocket\CookieConsent\Api\Data\CategoryInterface[]
|
||||
*/
|
||||
private $categories;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\CookieConsent\Api\CategoryRepositoryInterface
|
||||
*/
|
||||
private $categoryRepository;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Api\SearchCriteriaBuilder
|
||||
*/
|
||||
private $searchCriteriaBuilder;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Api\SortOrderBuilder
|
||||
*/
|
||||
private $sortOrderBuilder;
|
||||
|
||||
/**
|
||||
* @param \Plumrocket\CookieConsent\Api\CategoryRepositoryInterface $categoryRepository
|
||||
* @param \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder
|
||||
* @param \Magento\Framework\Api\SortOrderBuilder $sortOrderBuilder
|
||||
*/
|
||||
public function __construct(
|
||||
CategoryRepositoryInterface $categoryRepository,
|
||||
SearchCriteriaBuilder $searchCriteriaBuilder,
|
||||
SortOrderBuilder $sortOrderBuilder
|
||||
) {
|
||||
$this->categoryRepository = $categoryRepository;
|
||||
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
|
||||
$this->sortOrderBuilder = $sortOrderBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get active categories.
|
||||
*
|
||||
* @return \Plumrocket\CookieConsent\Api\Data\CategoryInterface[]
|
||||
*/
|
||||
public function get(): array
|
||||
{
|
||||
if (null === $this->categories) {
|
||||
$this->searchCriteriaBuilder->addFilter('status', 1);
|
||||
$this->searchCriteriaBuilder->addSortOrder(
|
||||
$this->sortOrderBuilder
|
||||
->setField(CategoryInterface::SORT_ORDER)
|
||||
->setAscendingDirection()
|
||||
->create()
|
||||
);
|
||||
$this->searchCriteriaBuilder->addSortOrder(
|
||||
$this->sortOrderBuilder
|
||||
->setField(CategoryInterface::CREATED_AT)
|
||||
->setAscendingDirection()
|
||||
->create()
|
||||
);
|
||||
// During installation all categories will have same created_at
|
||||
// so order by id keep right order for this case
|
||||
$this->searchCriteriaBuilder->addSortOrder(
|
||||
$this->sortOrderBuilder
|
||||
->setField(CategoryResource::ID_FIELD_NAME)
|
||||
->setAscendingDirection()
|
||||
->create()
|
||||
);
|
||||
$this->categories = $this->categoryRepository->getList($this->searchCriteriaBuilder->create())->getItems();
|
||||
}
|
||||
return $this->categories;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user