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

Public Member Functions

 clearAll ()
 
 getFilters ()
 
 applyFilter ($filter, $linkPattern)
 
 isCategoryVisible (Category $category, $qty)
 
 getFilterContents ($attributeLabel)
 

Protected Attributes

 $loadedNarrowByList = '#narrow-by-list[role="tablist"]'
 
 $clearAll = '.action.clear'
 
 $optionTitle = './/div[@class="filter-options-title" and contains(text(),"%s")]'
 
 $filterLink = './/div[@class="filter-options-title" and contains(text(),"%s")]/following-sibling::div//a'
 
 $expandFilterButton = '[data]'
 

Detailed Description

Catalog layered navigation view block.

Definition at line 16 of file Navigation.php.

Member Function Documentation

◆ applyFilter()

applyFilter (   $filter,
  $linkPattern 
)

Apply Layered Navigation filter.

Parameters
string$filter
string$linkPattern
Returns
void
Exceptions

Definition at line 103 of file Navigation.php.

104  {
105  $links = sprintf($this->filterLink, $filter);
106  $this->openFilterContainer($filter, $links);
107 
108  $links = $this->_rootElement->getElements($links, Locator::SELECTOR_XPATH);
109  foreach ($links as $link) {
110  if (preg_match($linkPattern, trim($link->getText()))) {
111  $link->click();
112  return;
113  }
114  }
115  throw new \Exception("Can't find {$filter} filter link by pattern: {$linkPattern}");
116  }

◆ clearAll()

clearAll ( )

Remove all applied filters.

Returns
void

Definition at line 72 of file Navigation.php.

73  {
74  $this->_rootElement->find($this->clearAll)->click();
75  }

◆ getFilterContents()

getFilterContents (   $attributeLabel)

Get Layered Navigation filter options.

Parameters
string$attributeLabel
Returns
array

Definition at line 139 of file Navigation.php.

140  {
141  $data = [];
142 
143  if (trim($attributeLabel) === '') {
144  return $data;
145  }
146 
147  $link = sprintf($this->filterLink, $attributeLabel);
148  $this->openFilterContainer($attributeLabel, $link);
149 
150  $optionContents = $this->_rootElement->getElements($link, Locator::SELECTOR_XPATH);
151 
152  foreach ($optionContents as $optionContent) {
153  $data[] = trim(strtoupper($optionContent->getText()));
154  }
155 
156  return $data;
157  }

◆ getFilters()

getFilters ( )

Get all available filters.

Returns
array

Definition at line 82 of file Navigation.php.

83  {
84  $this->waitForElementVisible($this->loadedNarrowByList);
85 
86  $options = $this->_rootElement->getElements(sprintf($this->optionTitle, ''), Locator::SELECTOR_XPATH);
87  $data = [];
88  foreach ($options as $option) {
89  $data[] = strtoupper($option->getText());
90  }
91 
92  return $data;
93  }

◆ isCategoryVisible()

isCategoryVisible ( Category  $category,
  $qty 
)

Check that category with product quantity can be displayed on layered navigation.

Parameters
Category$category
int$qty
Returns
bool

Definition at line 125 of file Navigation.php.

126  {
127  return $this->_rootElement->find(
128  sprintf($this->categoryName, $category->getName()) . sprintf($this->productQty, $qty),
129  Locator::SELECTOR_XPATH
130  )->isVisible();
131  }

Field Documentation

◆ $clearAll

$clearAll = '.action.clear'
protected

Definition at line 30 of file Navigation.php.

◆ $expandFilterButton

$expandFilterButton = '[data]'
protected

Definition at line 51 of file Navigation.php.

◆ $filterLink

$filterLink = './/div[@class="filter-options-title" and contains(text(),"%s")]/following-sibling::div//a'
protected

Definition at line 44 of file Navigation.php.

◆ $loadedNarrowByList

$loadedNarrowByList = '#narrow-by-list[role="tablist"]'
protected

Definition at line 23 of file Navigation.php.

◆ $optionTitle

$optionTitle = './/div[@class="filter-options-title" and contains(text(),"%s")]'
protected

Definition at line 37 of file Navigation.php.


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