CollectionProvider.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\CatalogGraphQl\Model\Layer;
  8. use Magento\Catalog\Model\ResourceModel\Product\Collection;
  9. /**
  10. * Collection Provider for graphql layered navigation.
  11. */
  12. class CollectionProvider implements \Magento\Catalog\Model\Layer\ItemCollectionProviderInterface
  13. {
  14. /**
  15. * @var \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory
  16. */
  17. private $collectionFactory;
  18. /**
  19. * @var Collection
  20. */
  21. private $collection;
  22. /**
  23. * @var \Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface
  24. */
  25. private $collectionProcessor;
  26. /**
  27. * @param \Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface $collectionProcessor
  28. * @param \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $collectionFactory
  29. */
  30. public function __construct(
  31. \Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface $collectionProcessor,
  32. \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $collectionFactory
  33. ) {
  34. $this->collectionProcessor = $collectionProcessor;
  35. $this->collectionFactory = $collectionFactory;
  36. }
  37. /**
  38. * @param \Magento\Catalog\Model\Category $category
  39. * @return Collection
  40. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  41. */
  42. public function getCollection(\Magento\Catalog\Model\Category $category) : Collection
  43. {
  44. if (!$this->collection) {
  45. $this->collection = $this->collectionFactory->create();
  46. }
  47. return $this->collection;
  48. }
  49. }