Options.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * Options for Query Id column
  4. *
  5. * Copyright © Magento, Inc. All rights reserved.
  6. * See COPYING.txt for license details.
  7. */
  8. namespace Magento\AdvancedSearch\Model\Adminhtml\Search\Grid;
  9. /**
  10. * @api
  11. * @since 100.0.2
  12. */
  13. class Options implements \Magento\Framework\Option\ArrayInterface
  14. {
  15. /**
  16. * @var \Magento\Framework\App\RequestInterface
  17. */
  18. protected $_request;
  19. /**
  20. * @var \Magento\Framework\Registry
  21. */
  22. protected $_registryManager;
  23. /**
  24. * @var \Magento\AdvancedSearch\Model\ResourceModel\Recommendations $_searchResourceModel
  25. */
  26. protected $_searchResourceModel;
  27. /**
  28. * @param \Magento\Framework\App\RequestInterface $request
  29. * @param \Magento\Framework\Registry $registry
  30. * @param \Magento\AdvancedSearch\Model\ResourceModel\Recommendations $searchResourceModel
  31. */
  32. public function __construct(
  33. \Magento\Framework\App\RequestInterface $request,
  34. \Magento\Framework\Registry $registry,
  35. \Magento\AdvancedSearch\Model\ResourceModel\Recommendations $searchResourceModel
  36. ) {
  37. $this->_request = $request;
  38. $this->_registryManager = $registry;
  39. $this->_searchResourceModel = $searchResourceModel;
  40. }
  41. /**
  42. * {@inheritdoc}
  43. */
  44. public function toOptionArray()
  45. {
  46. $queries = $this->_request->getPost('selected_queries');
  47. $currentQueryId = $this->_registryManager->registry('current_catalog_search')->getId();
  48. $queryIds = [];
  49. if ($queries === null && !empty($currentQueryId)) {
  50. $queryIds = $this->_searchResourceModel->getRelatedQueries($currentQueryId);
  51. }
  52. return $queryIds;
  53. }
  54. }