diff --git a/src/Model/Layer/Filter/Category.php b/src/Model/Layer/Filter/Category.php deleted file mode 100644 index 2cd74fe..0000000 --- a/src/Model/Layer/Filter/Category.php +++ /dev/null @@ -1,180 +0,0 @@ - - * @copyright Copyright (c) 2018 Scandiweb, Ltd (https://scandiweb.com) - */ - -namespace ScandiPWA\CatalogGraphQl\Model\Layer\Filter; - -use Magento\Catalog\Model\Layer; -use Magento\Catalog\Model\Layer\Filter\AbstractFilter; -use Magento\Catalog\Model\Layer\Filter\DataProvider\Category as CategoryDataProvider; -use Magento\Catalog\Model\Layer\Filter\DataProvider\CategoryFactory; -use Magento\Catalog\Model\Layer\Filter\Item\DataBuilder; -use Magento\Catalog\Model\Layer\Filter\ItemFactory; -use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory; -use Magento\Framework\App\RequestInterface; -use Magento\Framework\Escaper; -use Magento\Framework\Exception\LocalizedException; -use Magento\Framework\Phrase; -use Magento\Framework\Registry; -use Magento\Store\Model\StoreManagerInterface; - -/** - * Layer category filter - */ -class Category extends AbstractFilter -{ - /** - * Active Category Id - * - * @var int - */ - protected $_categoryId; - - /** - * Applied Category - * - * @var \Magento\Catalog\Model\Category - */ - protected $_appliedCategory; - - /** - * Core data - * - * @var Escaper - */ - protected $_escaper; - - /** - * Core registry - * - * @var Registry - */ - protected $_coreRegistry; - - /** - * @var CategoryDataProvider - */ - private $dataProvider; - - /** - * @var CollectionFactory - */ - protected $categoryCollectionFactory; - - /** - * Construct - * - * @param ItemFactory $filterItemFactory - * @param StoreManagerInterface $storeManager - * @param Layer $layer - * @param DataBuilder $itemDataBuilder - * @param Escaper $escaper - * @param CategoryFactory $categoryDataProviderFactory - * @param CollectionFactory $categoryCollectionFactory - * @param array $data - * @throws LocalizedException - */ - public function __construct( - ItemFactory $filterItemFactory, - StoreManagerInterface $storeManager, - Layer $layer, - DataBuilder $itemDataBuilder, - Escaper $escaper, - CategoryFactory $categoryDataProviderFactory, - CollectionFactory $categoryCollectionFactory, - array $data = [] - ) { - parent::__construct($filterItemFactory, $storeManager, $layer, $itemDataBuilder, $data); - $this->_escaper = $escaper; - $this->_requestVar = 'cat'; - $this->categoryCollectionFactory = $categoryCollectionFactory; - $this->dataProvider = $categoryDataProviderFactory->create(['layer' => $this->getLayer()]); - } - - /** - * Get filter value for reset current filter state - * - * @return mixed|null - */ - public function getResetValue() - { - return $this->dataProvider->getResetValue(); - } - - /** - * Apply category filter to layer - * - * @param RequestInterface $request - * @return Category - */ - public function apply(RequestInterface $request) - { - $categoryId = (int)$request->getParam($this->getRequestVar()); - if (!$categoryId) { - return $this; - } - - $this->dataProvider->setCategoryId($categoryId); - - if ($this->dataProvider->isValid()) { - $category = $this->dataProvider->getCategory(); - $this->getLayer()->getProductCollection()->addCategoryFilter($category); - $this->getLayer()->getState()->addFilter($this->_createItem($category->getName(), $categoryId)); - } - - return $this; - } - - /** - * Get filter name - * - * @return Phrase - */ - public function getName() - { - return __('Category'); - } - - /** - * Get data array for building category filter items - * - * @return array - * @throws LocalizedException - */ - protected function _getItemsData() - { - $category = $this->dataProvider->getCategory(); - - $categories = $this->categoryCollectionFactory->create() - ->addPathsFilter($category->getPath().'/') - ->addLevelFilter($category->getLevel() + 1) - ->addAttributeToSelect('*') - ->addAttributeToSelect('is_active') - ->addNameToResult(); - - if ($category->getIsActive()) { - foreach ($categories as $category) { - if ($category->getIsActive() && $category->getProductCount()) { - $this->itemDataBuilder->addItemData( - $this->_escaper->escapeHtml($category->getName()), - parse_url($category->getUrl(), PHP_URL_PATH), - $category->getProductCount() - ); - } - } - } - - return $this->itemDataBuilder->build(); - } -} diff --git a/src/Model/Layer/Filter/Price.php b/src/Model/Layer/Filter/Price.php deleted file mode 100644 index ab3f207..0000000 --- a/src/Model/Layer/Filter/Price.php +++ /dev/null @@ -1,127 +0,0 @@ - - * @copyright Copyright (c) 2018 Scandiweb, Ltd (https://scandiweb.com) - */ - -namespace ScandiPWA\CatalogGraphQl\Model\Layer\Filter; - -use Magento\Catalog\Model\Layer; -use Magento\Catalog\Model\Layer\Filter\AbstractFilter; -use Magento\Catalog\Model\Layer\Filter\Item\DataBuilder; -use Magento\Catalog\Model\Layer\Filter\ItemFactory; -use Magento\Catalog\Model\ResourceModel\Layer\Filter\Attribute; -use Magento\Catalog\Model\ResourceModel\Layer\Filter\AttributeFactory; -use Magento\Framework\App\RequestInterface; -use Magento\Framework\Exception\LocalizedException; -use Magento\Framework\Filter\StripTags; -use Magento\Framework\Stdlib\StringUtils; -use Magento\Store\Model\StoreManagerInterface; - -/** - * Layer attribute filter - * - * @SuppressWarnings(PHPMD.LongVariable) - */ -class Price extends AbstractFilter -{ - /** - * Resource instance - * - * @var Attribute - */ - protected $_resource; - - /** - * Magento string lib - * - * @var StringUtils - */ - protected $string; - - /** - * @var StripTags - */ - protected $tagFilter; - - /** - * @param ItemFactory $filterItemFactory - * @param StoreManagerInterface $storeManager - * @param Layer $layer - * @param DataBuilder $itemDataBuilder - * @param AttributeFactory $filterAttributeFactory - * @param StringUtils $string - * @param StripTags $tagFilter - * @param array $data - * @throws LocalizedException - */ - public function __construct( - ItemFactory $filterItemFactory, - StoreManagerInterface $storeManager, - Layer $layer, - DataBuilder $itemDataBuilder, - AttributeFactory $filterAttributeFactory, - StringUtils $string, - StripTags $tagFilter, - array $data = [] - ) { - $this->_resource = $filterAttributeFactory->create(); - $this->string = $string; - $this->_requestVar = 'attribute'; - $this->tagFilter = $tagFilter; - - parent::__construct($filterItemFactory, $storeManager, $layer, $itemDataBuilder, $data); - } - - /** - * Retrieve resource instance - * - * @return Attribute - */ - protected function _getResource() - { - return $this->_resource; - } - - /** - * Apply attribute option filter to product collection - * - * @param RequestInterface $request - * @return $this - * @throws LocalizedException - */ - public function apply(RequestInterface $request) - { - $filter = $request->getParam($this->_requestVar); - if (is_array($filter)) { - return $this; - } - $text = $this->getOptionText($filter); - if ($filter && strlen($text)) { - $this->_getResource()->applyFilterToCollection($this, $filter); - $this->getLayer()->getState()->addFilter($this->_createItem($text, $filter)); - $this->_items = []; - } - return $this; - } - - /** - * Get data array for building attribute filter items - * - * @return array - */ - protected function _getItemsData() - { - $this->itemDataBuilder->addItemData( - 'mock', - 0, - 1 - ); - - return $this->itemDataBuilder->build(); - } -} diff --git a/src/Model/Resolver/Layer/DataProvider/Filters.php b/src/Model/Resolver/Layer/DataProvider/Filters.php deleted file mode 100644 index ee4d859..0000000 --- a/src/Model/Resolver/Layer/DataProvider/Filters.php +++ /dev/null @@ -1,112 +0,0 @@ - - * @author Aivars Arbidans - * @copyright Copyright (c) 2019 Scandiweb, Ltd (https://scandiweb.com) - */ -declare (strict_types=1); - -namespace ScandiPWA\CatalogGraphQl\Model\Resolver\Layer\DataProvider; - -use Magento\Catalog\Model\Layer\Filter\Item; -use Magento\CatalogGraphQl\Model\Resolver\Layer\DataProvider\Filters as CoreFilters; -use Magento\CatalogGraphQl\Model\Resolver\Layer\FiltersProvider; -use Magento\Catalog\Model\Layer\Filter\AbstractFilter; -use Magento\Framework\Exception\LocalizedException; - -/** - * Layered navigation filters data provider. - */ -class Filters extends CoreFilters -{ - /** - * @var FiltersProvider - */ - private $filtersProvider; - - /** - * @var array - */ - private $mappings; - - /** - * Filters constructor. - * - * @param FiltersProvider $filtersProvider - */ - public function __construct( - FiltersProvider $filtersProvider - ) { - $this->filtersProvider = $filtersProvider; - $this->mappings = [ - 'Category' => 'category' - ]; - } - - /** - * Get layered navigation filters data - * - * @param string $layerType - * @param array|null $attributesToFilter - * @return array - * @throws LocalizedException - */ - public function getData(string $layerType, array $attributesToFilter = null): array - { - $filtersData = []; - /** @var AbstractFilter $filter */ - foreach ($this->filtersProvider->getFilters($layerType) as $filter) { - if ($this->isNeedToAddFilter($filter, $attributesToFilter)) { - $filterGroup = [ - 'name' => (string) $filter->getName(), - 'filter_items_count' => $filter->getItemsCount(), - 'request_var' => $filter->getRequestVar(), - ]; - /** @var Item $filterItem */ - foreach ($filter->getItems() as $filterItem) { - $filterGroup['filter_items'][] = [ - 'label' => (string) $filterItem->getLabel(), - 'value_string' => $filterItem->getValueString(), - 'items_count' => $filterItem->getCount(), - ]; - } - $filtersData[] = $filterGroup; - } - } - - return $filtersData; - } - - /** - * Check for adding filter to the list - * - * @param AbstractFilter $filter - * @param $attributesToFilter - * @return bool - * @throws LocalizedException - */ - private function isNeedToAddFilter(AbstractFilter $filter, $attributesToFilter): bool - { - if ($attributesToFilter === null) { - $result = (bool)$filter->getItemsCount(); - } else { - if ($filter->hasAttributeModel()) { - $filterAttribute = $filter->getAttributeModel(); - $result = in_array($filterAttribute->getAttributeCode(), $attributesToFilter); - } else { - $name = (string)$filter->getName(); - if (array_key_exists($name, $this->mappings)) { - $result = in_array($this->mappings[$name], $attributesToFilter); - } else { - $result = true; - } - } - } - - return $result; - } -} diff --git a/src/Model/Resolver/LayerFilters.php b/src/Model/Resolver/LayerFilters.php deleted file mode 100644 index 38fc94e..0000000 --- a/src/Model/Resolver/LayerFilters.php +++ /dev/null @@ -1,81 +0,0 @@ - - * @author Aivars Arbidans - * @copyright Copyright (c) 2019 Scandiweb, Ltd (https://scandiweb.com) - */ -declare (strict_types=1); - -namespace ScandiPWA\CatalogGraphQl\Model\Resolver; - -use Magento\CatalogGraphQl\Model\Resolver\LayerFilters as CoreLayerFilters; -use Magento\Framework\GraphQl\Config\Element\Field; -use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; -use ScandiPWA\CatalogGraphQl\Model\Resolver\Layer\DataProvider\Filters; - -/** - * Layered navigation filters resolver, used for GraphQL request processing. - */ -class LayerFilters extends CoreLayerFilters -{ - /** - * @var Layer\DataProvider\Filters - */ - private $filtersDataProvider; - - /** - * @param Filters $filtersDataProvider - */ - public function __construct( - Filters $filtersDataProvider - ) { - $this->filtersDataProvider = $filtersDataProvider; - } - - /** - * @inheritdoc - */ - public function resolve( - Field $field, - $context, - ResolveInfo $info, - array $value = null, - array $args = null - ) { - if (!isset($value['layer_type'])) { - return null; - } - - $attributes = $this->prepareAttributesResults($value); - - return $this->filtersDataProvider->getData($value['layer_type'], $attributes); - } - - /** - * Get attributes available to filtering from the search result - * - * @param array $value - * @return array|null - */ - private function prepareAttributesResults(array $value): ?array - { - $attributes = []; - - if (!empty($value['search_result'])) { - $buckets = $value['search_result']->getSearchAggregation()->getBuckets(); - foreach ($buckets as $bucket) { - if (!empty($bucket->getValues())) { - $attributes[] = str_replace('_bucket', '', $bucket->getName()); - } - } - } else { - $attributes = null; - } - - return $attributes; - } -} diff --git a/src/Model/Resolver/Product.php b/src/Model/Resolver/Product.php index 42b7b73..40bb652 100644 --- a/src/Model/Resolver/Product.php +++ b/src/Model/Resolver/Product.php @@ -19,7 +19,6 @@ use Magento\Framework\GraphQl\Query\ResolverInterface; /** - * @deprecated * @inheritdoc */ class Product implements ResolverInterface diff --git a/src/etc/di.xml b/src/etc/di.xml index 0aa79a1..09b0d6b 100755 --- a/src/etc/di.xml +++ b/src/etc/di.xml @@ -59,9 +59,6 @@ - - - ScandiPWA\CatalogGraphQl\Model\Search\PageSizeProvider diff --git a/src/etc/graphql/di.xml b/src/etc/graphql/di.xml index 4b19985..27aebad 100644 --- a/src/etc/graphql/di.xml +++ b/src/etc/graphql/di.xml @@ -41,18 +41,12 @@ - - - -