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

Public Member Functions

 __construct (\Magento\Framework\View\Element\Template\Context $context, \Magento\Catalog\Model\Session $catalogSession, \Magento\Catalog\Model\Config $catalogConfig, ToolbarModel $toolbarModel, \Magento\Framework\Url\EncoderInterface $urlEncoder, ProductList $productListHelper, \Magento\Framework\Data\Helper\PostHelper $postDataHelper, array $data=[])
 
 disableParamsMemorizing ()
 
 setCollection ($collection)
 
 getCollection ()
 
 getCurrentPage ()
 
 getCurrentOrder ()
 
 getCurrentDirection ()
 
 setDefaultOrder ($field)
 
 setDefaultDirection ($dir)
 
 getAvailableOrders ()
 
 setAvailableOrders ($orders)
 
 addOrderToAvailableOrders ($order, $value)
 
 removeOrderFromAvailableOrders ($order)
 
 isOrderCurrent ($order)
 
 getPagerUrl ($params=[])
 
 getPagerEncodedUrl ($params=[])
 
 getCurrentMode ()
 
 isModeActive ($mode)
 
 getModes ()
 
 setModes ($modes)
 
 disableViewSwitcher ()
 
 enableViewSwitcher ()
 
 isEnabledViewSwitcher ()
 
 disableExpanded ()
 
 enableExpanded ()
 
 isExpanded ()
 
 getDefaultPerPageValue ()
 
 getAvailableLimit ()
 
 getLimit ()
 
 isLimitCurrent ($limit)
 
 getFirstNum ()
 
 getLastNum ()
 
 getTotalNum ()
 
 isFirstPage ()
 
 getLastPageNum ()
 
 getPagerHtml ()
 
 getWidgetOptionsJson (array $customOptions=[])
 
- 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

 _memorizeParam ($param, $value)
 
 getOrderField ()
 
- 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

 $_collection = null
 
 $_availableOrder = null
 
 $_availableMode = []
 
 $_enableViewSwitcher = true
 
 $_isExpanded = true
 
 $_orderField = null
 
 $_direction = ProductList::DEFAULT_SORT_DIRECTION
 
 $_viewMode = null
 
 $_paramsMemorizeAllowed = true
 
 $_template = 'Magento_Catalog::product/list/toolbar.phtml'
 
 $_catalogConfig
 
 $_catalogSession
 
 $_toolbarModel
 
 $_productListHelper
 
 $urlEncoder
 
 $_postDataHelper
 
- 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

Product list toolbar

@api

Author
Magento Core Team core@.nosp@m.mage.nosp@m.ntoco.nosp@m.mmer.nosp@m.ce.co.nosp@m.m @SuppressWarnings(PHPMD.TooManyFields) @SuppressWarnings(PHPMD.CouplingBetweenObjects)
Since
100.0.2

Definition at line 20 of file Toolbar.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\View\Element\Template\Context  $context,
\Magento\Catalog\Model\Session  $catalogSession,
\Magento\Catalog\Model\Config  $catalogConfig,
ToolbarModel  $toolbarModel,
\Magento\Framework\Url\EncoderInterface  $urlEncoder,
ProductList  $productListHelper,
\Magento\Framework\Data\Helper\PostHelper  $postDataHelper,
array  $data = [] 
)
Parameters
\Magento\Framework\View\Element\Template\Context$context
\Magento\Catalog\Model\Session$catalogSession
\Magento\Catalog\Model\Config$catalogConfig
ToolbarModel$toolbarModel
\Magento\Framework\Url\EncoderInterface$urlEncoder
ProductList$productListHelper
\Magento\Framework\Data\Helper\PostHelper$postDataHelper
array$data

Definition at line 132 of file Toolbar.php.

141  {
142  $this->_catalogSession = $catalogSession;
143  $this->_catalogConfig = $catalogConfig;
144  $this->_toolbarModel = $toolbarModel;
145  $this->urlEncoder = $urlEncoder;
146  $this->_productListHelper = $productListHelper;
147  $this->_postDataHelper = $postDataHelper;
148  parent::__construct($context, $data);
149  }

Member Function Documentation

◆ _memorizeParam()

_memorizeParam (   $param,
  $value 
)
protected

Memorize parameter value for session

Parameters
string$paramparameter name
mixed$valueparameter value
Returns
$this

Definition at line 169 of file Toolbar.php.

170  {
171  if ($this->_paramsMemorizeAllowed && !$this->_catalogSession->getParamsMemorizeDisabled()) {
172  $this->_catalogSession->setData($param, $value);
173  }
174  return $this;
175  }
$value
Definition: gender.phtml:16

◆ addOrderToAvailableOrders()

addOrderToAvailableOrders (   $order,
  $value 
)

Add order to available orders

Parameters
string$order
string$value
Returns
\Magento\Catalog\Block\Product\ProductList\Toolbar

Definition at line 345 of file Toolbar.php.

346  {
347  $this->loadAvailableOrders();
348  $this->_availableOrder[$order] = $value;
349  return $this;
350  }
$order
Definition: order.php:55
$value
Definition: gender.phtml:16

◆ disableExpanded()

disableExpanded ( )

Disable Expanded

Returns
\Magento\Catalog\Block\Product\ProductList\Toolbar

Definition at line 500 of file Toolbar.php.

501  {
502  $this->_isExpanded = false;
503  return $this;
504  }

◆ disableParamsMemorizing()

disableParamsMemorizing ( )

Disable list state params memorizing

Returns
$this

Definition at line 156 of file Toolbar.php.

157  {
158  $this->_paramsMemorizeAllowed = false;
159  return $this;
160  }

◆ disableViewSwitcher()

disableViewSwitcher ( )

Disable view switcher

Returns
\Magento\Catalog\Block\Product\ProductList\Toolbar

Definition at line 468 of file Toolbar.php.

469  {
470  $this->_enableViewSwitcher = false;
471  return $this;
472  }

◆ enableExpanded()

enableExpanded ( )

Enable Expanded

Returns
\Magento\Catalog\Block\Product\ProductList\Toolbar

Definition at line 511 of file Toolbar.php.

512  {
513  $this->_isExpanded = true;
514  return $this;
515  }

◆ enableViewSwitcher()

enableViewSwitcher ( )

Enable view switcher

Returns
\Magento\Catalog\Block\Product\ProductList\Toolbar

Definition at line 479 of file Toolbar.php.

480  {
481  $this->_enableViewSwitcher = true;
482  return $this;
483  }

◆ getAvailableLimit()

getAvailableLimit ( )

Retrieve available limits for current view mode

Returns
array

Definition at line 547 of file Toolbar.php.

548  {
549  return $this->_productListHelper->getAvailableLimit($this->getCurrentMode());
550  }

◆ getAvailableOrders()

getAvailableOrders ( )

Retrieve available Order fields list

Returns
array

Definition at line 320 of file Toolbar.php.

321  {
322  $this->loadAvailableOrders();
323  return $this->_availableOrder;
324  }

◆ getCollection()

getCollection ( )

Return products collection instance

Returns
\Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection

Definition at line 212 of file Toolbar.php.

◆ getCurrentDirection()

getCurrentDirection ( )

Retrieve current direction

Returns
string

Definition at line 265 of file Toolbar.php.

266  {
267  $dir = $this->_getData('_current_grid_direction');
268  if ($dir) {
269  return $dir;
270  }
271 
272  $directions = ['asc', 'desc'];
273  $dir = strtolower($this->_toolbarModel->getDirection());
274  if (!$dir || !in_array($dir, $directions)) {
275  $dir = $this->_direction;
276  }
277 
278  if ($dir != $this->_direction) {
279  $this->_memorizeParam('sort_direction', $dir);
280  }
281 
282  $this->setData('_current_grid_direction', $dir);
283  return $dir;
284  }
setData($key, $value=null)
Definition: DataObject.php:72

◆ getCurrentMode()

getCurrentMode ( )

Retrieve current View mode

Returns
string

Definition at line 408 of file Toolbar.php.

409  {
410  $mode = $this->_getData('_current_grid_mode');
411  if ($mode) {
412  return $mode;
413  }
414  $defaultMode = $this->_productListHelper->getDefaultViewMode($this->getModes());
415  $mode = $this->_toolbarModel->getMode();
416  if (!$mode || !isset($this->_availableMode[$mode])) {
417  $mode = $defaultMode;
418  }
419 
420  $this->setData('_current_grid_mode', $mode);
421  return $mode;
422  }
if($exist=($block->getProductCollection() && $block->getProductCollection() ->getSize())) $mode
Definition: grid.phtml:15
setData($key, $value=null)
Definition: DataObject.php:72

◆ getCurrentOrder()

getCurrentOrder ( )

Get grit products sort order field

Returns
string

Definition at line 232 of file Toolbar.php.

233  {
234  $order = $this->_getData('_current_grid_order');
235  if ($order) {
236  return $order;
237  }
238 
239  $orders = $this->getAvailableOrders();
240  $defaultOrder = $this->getOrderField();
241 
242  if (!isset($orders[$defaultOrder])) {
243  $keys = array_keys($orders);
244  $defaultOrder = $keys[0];
245  }
246 
247  $order = $this->_toolbarModel->getOrder();
248  if (!$order || !isset($orders[$order])) {
249  $order = $defaultOrder;
250  }
251 
252  if ($order != $defaultOrder) {
253  $this->_memorizeParam('sort_order', $order);
254  }
255 
256  $this->setData('_current_grid_order', $order);
257  return $order;
258  }
$order
Definition: order.php:55
setData($key, $value=null)
Definition: DataObject.php:72

◆ getCurrentPage()

getCurrentPage ( )

Return current page from request

Returns
int

Definition at line 222 of file Toolbar.php.

223  {
224  return $this->_toolbarModel->getCurrentPage();
225  }

◆ getDefaultPerPageValue()

getDefaultPerPageValue ( )

Retrieve default per page values

Returns
string (comma separated)

Definition at line 532 of file Toolbar.php.

533  {
534  if ($this->getCurrentMode() == 'list' && ($default = $this->getDefaultListPerPage())) {
535  return $default;
536  } elseif ($this->getCurrentMode() == 'grid' && ($default = $this->getDefaultGridPerPage())) {
537  return $default;
538  }
539  return $this->_productListHelper->getDefaultLimitPerPageValue($this->getCurrentMode());
540  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17

◆ getFirstNum()

getFirstNum ( )
Returns
int

Definition at line 596 of file Toolbar.php.

597  {
598  $collection = $this->getCollection();
599  return $collection->getPageSize() * ($collection->getCurPage() - 1) + 1;
600  }

◆ getLastNum()

getLastNum ( )
Returns
int

Definition at line 605 of file Toolbar.php.

606  {
607  $collection = $this->getCollection();
608  return $collection->getPageSize() * ($collection->getCurPage() - 1) + $collection->count();
609  }

◆ getLastPageNum()

getLastPageNum ( )
Returns
int

Definition at line 630 of file Toolbar.php.

631  {
632  return $this->getCollection()->getLastPageNumber();
633  }

◆ getLimit()

getLimit ( )

Get specified products limit display per page

Returns
string

Definition at line 557 of file Toolbar.php.

558  {
559  $limit = $this->_getData('_current_limit');
560  if ($limit) {
561  return $limit;
562  }
563 
564  $limits = $this->getAvailableLimit();
565  $defaultLimit = $this->getDefaultPerPageValue();
566  if (!$defaultLimit || !isset($limits[$defaultLimit])) {
567  $keys = array_keys($limits);
568  $defaultLimit = $keys[0];
569  }
570 
571  $limit = $this->_toolbarModel->getLimit();
572  if (!$limit || !isset($limits[$limit])) {
573  $limit = $defaultLimit;
574  }
575 
576  if ($limit != $defaultLimit) {
577  $this->_memorizeParam('limit_page', $limit);
578  }
579 
580  $this->setData('_current_limit', $limit);
581  return $limit;
582  }
setData($key, $value=null)
Definition: DataObject.php:72

◆ getModes()

getModes ( )

Retrieve available view modes

Returns
array

Definition at line 440 of file Toolbar.php.

441  {
442  if ($this->_availableMode === []) {
443  $this->_availableMode = $this->_productListHelper->getAvailableViewMode();
444  }
445  return $this->_availableMode;
446  }

◆ getOrderField()

getOrderField ( )
protected

Get order field

Returns
null|string

Definition at line 705 of file Toolbar.php.

706  {
707  if ($this->_orderField === null) {
708  $this->_orderField = $this->_productListHelper->getDefaultSortField();
709  }
710  return $this->_orderField;
711  }

◆ getPagerEncodedUrl()

getPagerEncodedUrl (   $params = [])
Parameters
array$params
Returns
string

Definition at line 398 of file Toolbar.php.

399  {
400  return $this->urlEncoder->encode($this->getPagerUrl($params));
401  }
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18

◆ getPagerHtml()

getPagerHtml ( )

Render pagination HTML

Returns
string

Definition at line 640 of file Toolbar.php.

641  {
642  $pagerBlock = $this->getChildBlock('product_list_toolbar_pager');
643 
644  if ($pagerBlock instanceof \Magento\Framework\DataObject) {
645  /* @var $pagerBlock \Magento\Theme\Block\Html\Pager */
646  $pagerBlock->setAvailableLimit($this->getAvailableLimit());
647 
648  $pagerBlock->setUseContainer(
649  false
650  )->setShowPerPage(
651  false
652  )->setShowAmounts(
653  false
654  )->setFrameLength(
655  $this->_scopeConfig->getValue(
656  'design/pagination/pagination_frame',
658  )
659  )->setJump(
660  $this->_scopeConfig->getValue(
661  'design/pagination/pagination_frame_skip',
663  )
664  )->setLimit(
665  $this->getLimit()
666  )->setCollection(
667  $this->getCollection()
668  );
669 
670  return $pagerBlock->toHtml();
671  }
672 
673  return '';
674  }

◆ getPagerUrl()

getPagerUrl (   $params = [])

Return current URL with rewrites and additional parameters

Parameters
array$paramsQuery parameters
Returns
string

Definition at line 384 of file Toolbar.php.

385  {
386  $urlParams = [];
387  $urlParams['_current'] = true;
388  $urlParams['_escape'] = false;
389  $urlParams['_use_rewrite'] = true;
390  $urlParams['_query'] = $params;
391  return $this->getUrl('*/*/*', $urlParams);
392  }
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18

◆ getTotalNum()

getTotalNum ( )
Returns
int

Definition at line 614 of file Toolbar.php.

615  {
616  return $this->getCollection()->getSize();
617  }

◆ getWidgetOptionsJson()

getWidgetOptionsJson ( array  $customOptions = [])

Retrieve widget options in json format

Parameters
array$customOptionsOptional parameter for passing custom selectors from template
Returns
string

Definition at line 682 of file Toolbar.php.

683  {
684  $defaultMode = $this->_productListHelper->getDefaultViewMode($this->getModes());
685  $options = [
686  'mode' => ToolbarModel::MODE_PARAM_NAME,
687  'direction' => ToolbarModel::DIRECTION_PARAM_NAME,
688  'order' => ToolbarModel::ORDER_PARAM_NAME,
689  'limit' => ToolbarModel::LIMIT_PARAM_NAME,
690  'modeDefault' => $defaultMode,
691  'directionDefault' => $this->_direction ?: ProductList::DEFAULT_SORT_DIRECTION,
692  'orderDefault' => $this->getOrderField(),
693  'limitDefault' => $this->_productListHelper->getDefaultLimitPerPageValue($defaultMode),
694  'url' => $this->getPagerUrl(),
695  ];
696  $options = array_replace_recursive($options, $customOptions);
697  return json_encode(['productListToolbarForm' => $options]);
698  }

◆ isEnabledViewSwitcher()

isEnabledViewSwitcher ( )

Is a enabled view switcher

Returns
bool

Definition at line 490 of file Toolbar.php.

◆ isExpanded()

isExpanded ( )

Check is Expanded

Returns
bool

Definition at line 522 of file Toolbar.php.

◆ isFirstPage()

isFirstPage ( )
Returns
bool

Definition at line 622 of file Toolbar.php.

623  {
624  return $this->getCollection()->getCurPage() == 1;
625  }

◆ isLimitCurrent()

isLimitCurrent (   $limit)
Parameters
int$limit
Returns
bool

Definition at line 588 of file Toolbar.php.

589  {
590  return $limit == $this->getLimit();
591  }

◆ isModeActive()

isModeActive (   $mode)

Compare defined view mode with current active mode

Parameters
string$mode
Returns
bool

Definition at line 430 of file Toolbar.php.

431  {
432  return $this->getCurrentMode() == $mode;
433  }
if($exist=($block->getProductCollection() && $block->getProductCollection() ->getSize())) $mode
Definition: grid.phtml:15

◆ isOrderCurrent()

isOrderCurrent (   $order)

Compare defined order field with current order field

Parameters
string$order
Returns
bool

Definition at line 373 of file Toolbar.php.

374  {
375  return $order == $this->getCurrentOrder();
376  }
$order
Definition: order.php:55

◆ removeOrderFromAvailableOrders()

removeOrderFromAvailableOrders (   $order)

Remove order from available orders if exists

Parameters
string$order
Returns
$this

Definition at line 358 of file Toolbar.php.

359  {
360  $this->loadAvailableOrders();
361  if (isset($this->_availableOrder[$order])) {
362  unset($this->_availableOrder[$order]);
363  }
364  return $this;
365  }
$order
Definition: order.php:55

◆ setAvailableOrders()

setAvailableOrders (   $orders)

Set Available order fields list

Parameters
array$orders
Returns
$this

Definition at line 332 of file Toolbar.php.

333  {
334  $this->_availableOrder = $orders;
335  return $this;
336  }

◆ setCollection()

setCollection (   $collection)

Set collection to pager

Parameters
\Magento\Framework\Data\Collection$collection
Returns
$this

Definition at line 183 of file Toolbar.php.

184  {
185  $this->_collection = $collection;
186 
187  $this->_collection->setCurPage($this->getCurrentPage());
188 
189  // we need to set pagination only if passed value integer and more that 0
190  $limit = (int)$this->getLimit();
191  if ($limit) {
192  $this->_collection->setPageSize($limit);
193  }
194  if ($this->getCurrentOrder()) {
195  if (($this->getCurrentOrder()) == 'position') {
196  $this->_collection->addAttributeToSort(
197  $this->getCurrentOrder(),
198  $this->getCurrentDirection()
199  );
200  } else {
201  $this->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());
202  }
203  }
204  return $this;
205  }
$this _collection
Definition: coupons.php:7

◆ setDefaultDirection()

setDefaultDirection (   $dir)

Set default sort direction

Parameters
string$dir
Returns
$this

Definition at line 307 of file Toolbar.php.

308  {
309  if (in_array(strtolower($dir), ['asc', 'desc'])) {
310  $this->_direction = strtolower($dir);
311  }
312  return $this;
313  }

◆ setDefaultOrder()

setDefaultOrder (   $field)

Set default Order field

Parameters
string$field
Returns
$this

Definition at line 292 of file Toolbar.php.

293  {
294  $this->loadAvailableOrders();
295  if (isset($this->_availableOrder[$field])) {
296  $this->_orderField = $field;
297  }
298  return $this;
299  }

◆ setModes()

setModes (   $modes)

Set available view modes list

Parameters
array$modes
Returns
$this

Definition at line 454 of file Toolbar.php.

455  {
456  $this->getModes();
457  if (!isset($this->_availableMode)) {
458  $this->_availableMode = $modes;
459  }
460  return $this;
461  }

Field Documentation

◆ $_availableMode

$_availableMode = []
protected

Definition at line 41 of file Toolbar.php.

◆ $_availableOrder

$_availableOrder = null
protected

Definition at line 34 of file Toolbar.php.

◆ $_catalogConfig

$_catalogConfig
protected

Definition at line 93 of file Toolbar.php.

◆ $_catalogSession

$_catalogSession
protected

Definition at line 100 of file Toolbar.php.

◆ $_collection

$_collection = null
protected

Definition at line 27 of file Toolbar.php.

◆ $_direction

$_direction = ProductList::DEFAULT_SORT_DIRECTION
protected

Definition at line 69 of file Toolbar.php.

◆ $_enableViewSwitcher

$_enableViewSwitcher = true
protected

Definition at line 48 of file Toolbar.php.

◆ $_isExpanded

$_isExpanded = true
protected

Definition at line 55 of file Toolbar.php.

◆ $_orderField

$_orderField = null
protected

Definition at line 62 of file Toolbar.php.

◆ $_paramsMemorizeAllowed

bool $_paramsMemorizeAllowed = true
protected

Definition at line 81 of file Toolbar.php.

◆ $_postDataHelper

$_postDataHelper
protected

Definition at line 120 of file Toolbar.php.

◆ $_productListHelper

$_productListHelper
protected

Definition at line 110 of file Toolbar.php.

◆ $_template

$_template = 'Magento_Catalog::product/list/toolbar.phtml'
protected

Definition at line 86 of file Toolbar.php.

◆ $_toolbarModel

$_toolbarModel
protected

Definition at line 105 of file Toolbar.php.

◆ $_viewMode

$_viewMode = null
protected

Definition at line 76 of file Toolbar.php.

◆ $urlEncoder

$urlEncoder
protected

Definition at line 115 of file Toolbar.php.


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