Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
Result Class Reference
Inheritance diagram for Result:
Template AbstractBlock DataObject BlockInterface

Public Member Functions

 __construct (Context $context, Advanced $catalogSearchAdvanced, LayerResolver $layerResolver, UrlFactory $urlFactory, array $data=[])
 
 setListOrders ()
 
 setListModes ()
 
 setListCollection ()
 
 getSearchModel ()
 
 getResultCount ()
 
 getProductListHtml ()
 
 getFormUrl ()
 
 getSearchCriterias ()
 
- Public Member Functions inherited from Template
 __construct (Template\Context $context, array $data=[])
 
 setTemplateContext ($templateContext)
 
 getTemplate ()
 
 setTemplate ($template)
 
 getTemplateFile ($template=null)
 
 getArea ()
 
 assign ($key, $value=null)
 
 fetchView ($fileName)
 
 getBaseUrl ()
 
 getObjectData (\Magento\Framework\DataObject $object, $key)
 
 getCacheKeyInfo ()
 
- Public Member Functions inherited from AbstractBlock
 __construct (\Magento\Framework\View\Element\Context $context, array $data=[])
 
 getJsLayout ()
 
 getRequest ()
 
 getParentBlock ()
 
 setLayout (\Magento\Framework\View\LayoutInterface $layout)
 
 getLayout ()
 
 setNameInLayout ($name)
 
 getChildNames ()
 
 setAttribute ($name, $value=null)
 
 setChild ($alias, $block)
 
 addChild ($alias, $block, $data=[])
 
 unsetChild ($alias)
 
 unsetCallChild ($alias, $callback, $result, $params)
 
 unsetChildren ()
 
 getChildBlock ($alias)
 
 getChildHtml ($alias='', $useCache=true)
 
 getChildChildHtml ($alias, $childChildAlias='', $useCache=true)
 
 getBlockHtml ($name)
 
 insert ($element, $siblingName=0, $after=true, $alias='')
 
 append ($element, $alias='')
 
 getGroupChildNames ($groupName)
 
 getChildData ($alias, $key='')
 
 getUiId ($arg1=null, $arg2=null, $arg3=null, $arg4=null, $arg5=null)
 
 getJsId ($arg1=null, $arg2=null, $arg3=null, $arg4=null, $arg5=null)
 
 getUrl ($route='', $params=[])
 
 getViewFileUrl ($fileId, array $params=[])
 
 formatDate ( $date=null, $format=\IntlDateFormatter::SHORT, $showTime=false, $timezone=null)
 
 formatTime ( $time=null, $format=\IntlDateFormatter::SHORT, $showDate=false)
 
 getModuleName ()
 
 escapeHtml ($data, $allowedTags=null)
 
 escapeJs ($string)
 
 escapeHtmlAttr ($string, $escapeSingleQuote=true)
 
 escapeCss ($string)
 
 stripTags ($data, $allowableTags=null, $allowHtmlEntities=false)
 
 escapeUrl ($string)
 
 escapeXssInUrl ($data)
 
 escapeQuote ($data, $addSlashes=false)
 
 escapeJsQuote ($data, $quote='\'')
 
 getNameInLayout ()
 
 getCacheKeyInfo ()
 
 getCacheKey ()
 
 getVar ($name, $module=null)
 
 isScopePrivate ()
 
- Public Member Functions inherited from DataObject
 __construct (array $data=[])
 
 addData (array $arr)
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 getData ($key='', $index=null)
 
 getDataByPath ($path)
 
 getDataByKey ($key)
 
 setDataUsingMethod ($key, $args=[])
 
 getDataUsingMethod ($key, $args=null)
 
 hasData ($key='')
 
 toArray (array $keys=[])
 
 convertToArray (array $keys=[])
 
 toXml (array $keys=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 convertToXml (array $arrAttributes=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 toJson (array $keys=[])
 
 convertToJson (array $keys=[])
 
 toString ($format='')
 
 __call ($method, $args)
 
 isEmpty ()
 
 serialize ($keys=[], $valueSeparator='=', $fieldSeparator=' ', $quote='"')
 
 debug ($data=null, &$objects=[])
 
 offsetSet ($offset, $value)
 
 offsetExists ($offset)
 
 offsetUnset ($offset)
 
 offsetGet ($offset)
 
- Public Member Functions inherited from BlockInterface
 toHtml ()
 

Protected Member Functions

 _prepareLayout ()
 
 _getProductCollection ()
 
- Protected Member Functions inherited from Template
 _construct ()
 
 _toHtml ()
 
 getRootDirectory ()
 
 getMediaDirectory ()
 
- Protected Member Functions inherited from AbstractBlock
 _construct ()
 
 _prepareLayout ()
 
 _beforeToHtml ()
 
 _afterToHtml ($html)
 
 _toHtml ()
 
 _getNotFoundUrl ($route='', $params=['_direct'=> 'core/index/notFound'])
 
 getCacheTags ()
 
 getCacheLifetime ()
 
 _loadCache ()
 
 _saveCache ($data)
 
 _getSidPlaceholder ($cacheKey=null)
 
- Protected Member Functions inherited from DataObject
 _getData ($key)
 
 _underscore ($name)
 

Protected Attributes

 $_urlFactory
 
 $_catalogLayer
 
 $_catalogSearchAdvanced
 
- Protected Attributes inherited from Template
 $_viewVars = []
 
 $_baseUrl
 
 $_jsUrl
 
 $_allowSymlinks
 
 $_filesystem
 
 $_template
 
 $templateEnginePool
 
 $_storeManager
 
 $_appState
 
 $directory
 
 $templateContext
 
 $pageConfig
 
 $resolver
 
 $validator
 
- Protected Attributes inherited from AbstractBlock
 $_design
 
 $_session
 
 $_sidResolver
 
 $_nameInLayout
 
 $_layout
 
 $jsLayout = []
 
 $_request
 
 $_urlBuilder
 
 $_eventManager
 
 $_frontController
 
 $_assetRepo
 
 $_viewConfig
 
 $_cacheState
 
 $_logger
 
 $_escaper
 
 $filterManager
 
 $_localeDate
 
 $inlineTranslation
 
 $_isScopePrivate = false
 
 $_scopeConfig
 
 $_cache
 
- Protected Attributes inherited from DataObject
 $_data = []
 

Additional Inherited Members

- Static Public Member Functions inherited from AbstractBlock
static extractModuleName ($className)
 
- Data Fields inherited from Template
const XML_PATH_TEMPLATE_ALLOW_SYMLINK = 'dev/template/allow_symlink'
 
- Data Fields inherited from AbstractBlock
const CACHE_GROUP = \Magento\Framework\App\Cache\Type\Block::TYPE_IDENTIFIER
 
const CACHE_KEY_PREFIX = 'BLOCK_'
 
- Static Protected Attributes inherited from DataObject
static $_underscoreCache = []
 

Detailed Description

Advanced search result

@api

Since
100.0.2

Definition at line 22 of file Result.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( Context  $context,
Advanced  $catalogSearchAdvanced,
LayerResolver  $layerResolver,
UrlFactory  $urlFactory,
array  $data = [] 
)
Parameters
Context$context
Advanced$catalogSearchAdvanced
LayerResolver$layerResolver
UrlFactory$urlFactory
array$data

Definition at line 52 of file Result.php.

58  {
59  $this->_catalogSearchAdvanced = $catalogSearchAdvanced;
60  $this->_catalogLayer = $layerResolver->get();
61  $this->_urlFactory = $urlFactory;
62  parent::__construct($context, $data);
63  }

Member Function Documentation

◆ _getProductCollection()

_getProductCollection ( )
protected

Get product collection.

Returns
Collection

Definition at line 142 of file Result.php.

143  {
144  return $this->getSearchModel()->getProductCollection();
145  }

◆ _prepareLayout()

_prepareLayout ( )
protected

Definition at line 68 of file Result.php.

69  {
70  $this->pageConfig->getTitle()->set($this->getPageTitle());
71  $breadcrumbs = $this->getLayout()->getBlock('breadcrumbs');
72  if ($breadcrumbs) {
73  $breadcrumbs->addCrumb(
74  'home',
75  [
76  'label' => __('Home'),
77  'title' => __('Go to Home Page'),
78  'link' => $this->_storeManager->getStore()->getBaseUrl()
79  ]
80  )->addCrumb(
81  'search',
82  ['label' => __('Catalog Advanced Search'), 'link' => $this->getUrl('*/*/')]
83  )->addCrumb(
84  'search_result',
85  ['label' => __('Results')]
86  );
87  }
88  return parent::_prepareLayout();
89  }
__()
Definition: __.php:13

◆ getFormUrl()

getFormUrl ( )

Get form URL.

Returns
string

Definition at line 186 of file Result.php.

187  {
188  return $this->_urlFactory->create()->addQueryParams(
189  $this->getRequest()->getQueryValue()
190  )->getUrl(
191  '*/*/',
192  ['_escape' => true]
193  );
194  }

◆ getProductListHtml()

getProductListHtml ( )

Get product list HTML.

Returns
string

Definition at line 176 of file Result.php.

177  {
178  return $this->getChildHtml('search_result_list');
179  }

◆ getResultCount()

getResultCount ( )

Get result count.

Returns
mixed

Definition at line 162 of file Result.php.

163  {
164  if (!$this->getData('result_count')) {
165  $size = $this->getSearchModel()->getProductCollection()->getSize();
166  $this->setResultCount($size);
167  }
168  return $this->getData('result_count');
169  }
getData($key='', $index=null)
Definition: DataObject.php:119

◆ getSearchCriterias()

getSearchCriterias ( )

Get search criteria.

Returns
array

Definition at line 201 of file Result.php.

202  {
203  $searchCriterias = $this->getSearchModel()->getSearchCriterias();
204  $middle = ceil(count($searchCriterias) / 2);
205  $left = array_slice($searchCriterias, 0, $middle);
206  $right = array_slice($searchCriterias, $middle);
207 
208  return ['left' => $left, 'right' => $right];
209  }
$middle
Definition: name.phtml:26
$searchCriterias
Definition: result.phtml:31

◆ getSearchModel()

getSearchModel ( )

Set search model.

Returns
Advanced

Definition at line 152 of file Result.php.

◆ setListCollection()

setListCollection ( )

Initialize list collection.

Returns
void

Definition at line 132 of file Result.php.

133  {
134  $this->getChildBlock('search_result_list')->setCollection($this->_getProductCollection());
135  }

◆ setListModes()

setListModes ( )

Set view mode options

Returns
void

Definition at line 122 of file Result.php.

123  {
124  $this->getChildBlock('search_result_list')->setModes(['grid' => __('Grid'), 'list' => __('List')]);
125  }
__()
Definition: __.php:13

◆ setListOrders()

setListOrders ( )

Set order options

Returns
void

Definition at line 106 of file Result.php.

107  {
108  /* @var $category \Magento\Catalog\Model\Category */
109  $category = $this->_catalogLayer->getCurrentCategory();
110 
111  $availableOrders = $category->getAvailableSortByOptions();
112  unset($availableOrders['position']);
113 
114  $this->getChildBlock('search_result_list')->setAvailableOrders($availableOrders);
115  }

Field Documentation

◆ $_catalogLayer

$_catalogLayer
protected

Definition at line 36 of file Result.php.

◆ $_catalogSearchAdvanced

$_catalogSearchAdvanced
protected

Definition at line 43 of file Result.php.

◆ $_urlFactory

$_urlFactory
protected

Definition at line 29 of file Result.php.


The documentation for this class was generated from the following file: