-
Notifications
You must be signed in to change notification settings - Fork 9.3k
/
Index.php
96 lines (84 loc) · 2.54 KB
/
Index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
/**
*
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\CatalogSearch\Controller\Result;
use Magento\Catalog\Model\Layer\Resolver;
use Magento\Catalog\Model\Session;
use Magento\Framework\App\Action\Context;
use Magento\Framework\App\ResourceConnection;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Search\Model\QueryFactory;
class Index extends \Magento\Framework\App\Action\Action
{
/**
* Catalog session
*
* @var Session
*/
protected $_catalogSession;
/**
* @var StoreManagerInterface
*/
protected $_storeManager;
/**
* @var QueryFactory
*/
private $_queryFactory;
/**
* Catalog Layer Resolver
*
* @var Resolver
*/
private $layerResolver;
/**
* @param Context $context
* @param Session $catalogSession
* @param StoreManagerInterface $storeManager
* @param QueryFactory $queryFactory
* @param Resolver $layerResolver
*/
public function __construct(
Context $context,
Session $catalogSession,
StoreManagerInterface $storeManager,
QueryFactory $queryFactory,
Resolver $layerResolver
) {
parent::__construct($context);
$this->_storeManager = $storeManager;
$this->_catalogSession = $catalogSession;
$this->_queryFactory = $queryFactory;
$this->layerResolver = $layerResolver;
}
/**
* Display search result
*
* @return void
*/
public function execute()
{
$this->layerResolver->create(Resolver::CATALOG_LAYER_SEARCH);
/* @var $query \Magento\Search\Model\Query */
$query = $this->_queryFactory->get();
$query->setStoreId($this->_storeManager->getStore()->getId());
if ($query->getQueryText() != '') {
if ($this->_objectManager->get('Magento\CatalogSearch\Helper\Data')->isMinQueryLength()) {
$query->setId(0)->setIsActive(1)->setIsProcessed(1);
} else {
$query->saveIncrementalPopularity();
if ($query->getRedirect()) {
$this->getResponse()->setRedirect($query->getRedirect());
return;
}
}
$this->_objectManager->get('Magento\CatalogSearch\Helper\Data')->checkNotes();
$this->_view->loadLayout();
$this->_view->renderLayout();
} else {
$this->getResponse()->setRedirect($this->_redirect->getRedirectUrl());
}
}
}