Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
FilterList Class Reference

Public Member Functions

 __construct (\Magento\Framework\ObjectManagerInterface $objectManager, FilterableAttributeListInterface $filterableAttributes, array $filters=[])
 
 getFilters (\Magento\Catalog\Model\Layer $layer)
 

Data Fields

const CATEGORY_FILTER = 'category'
 
const ATTRIBUTE_FILTER = 'attribute'
 
const PRICE_FILTER = 'price'
 
const DECIMAL_FILTER = 'decimal'
 

Protected Member Functions

 createAttributeFilter (\Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute, \Magento\Catalog\Model\Layer $layer)
 
 getAttributeFilterClass (\Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute)
 

Protected Attributes

 $objectManager
 
 $filterableAttributes
 
 $filterTypes
 
 $filters = []
 

Detailed Description

Definition at line 9 of file FilterList.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\ObjectManagerInterface  $objectManager,
FilterableAttributeListInterface  $filterableAttributes,
array  $filters = [] 
)
Parameters
\Magento\Framework\ObjectManagerInterface$objectManager
FilterableAttributeListInterface$filterableAttributes
array$filters

Override default filter type models

Definition at line 48 of file FilterList.php.

52  {
53  $this->objectManager = $objectManager;
54  $this->filterableAttributes = $filterableAttributes;
55 
57  $this->filterTypes = array_merge($this->filterTypes, $filters);
58  }

Member Function Documentation

◆ createAttributeFilter()

createAttributeFilter ( \Magento\Catalog\Model\ResourceModel\Eav\Attribute  $attribute,
\Magento\Catalog\Model\Layer  $layer 
)
protected

Create filter

Parameters
\Magento\Catalog\Model\ResourceModel\Eav\Attribute$attribute
\Magento\Catalog\Model\Layer$layer
Returns
\Magento\Catalog\Model\Layer\Filter\AbstractFilter

Definition at line 86 of file FilterList.php.

89  {
90  $filterClassName = $this->getAttributeFilterClass($attribute);
91 
92  $filter = $this->objectManager->create(
93  $filterClassName,
94  ['data' => ['attribute_model' => $attribute], 'layer' => $layer]
95  );
96  return $filter;
97  }
getAttributeFilterClass(\Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute)
Definition: FilterList.php:105

◆ getAttributeFilterClass()

getAttributeFilterClass ( \Magento\Catalog\Model\ResourceModel\Eav\Attribute  $attribute)
protected

Get Attribute Filter Class Name

Parameters
\Magento\Catalog\Model\ResourceModel\Eav\Attribute$attribute
Returns
string

Definition at line 105 of file FilterList.php.

106  {
107  $filterClassName = $this->filterTypes[self::ATTRIBUTE_FILTER];
108 
109  if ($attribute->getAttributeCode() == 'price') {
110  $filterClassName = $this->filterTypes[self::PRICE_FILTER];
111  } elseif ($attribute->getBackendType() == 'decimal') {
112  $filterClassName = $this->filterTypes[self::DECIMAL_FILTER];
113  }
114 
115  return $filterClassName;
116  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17

◆ getFilters()

getFilters ( \Magento\Catalog\Model\Layer  $layer)

Retrieve list of filters

Parameters
\Magento\Catalog\Model\Layer$layer
Returns
array|Filter\AbstractFilter[]

Definition at line 66 of file FilterList.php.

67  {
68  if (!count($this->filters)) {
69  $this->filters = [
70  $this->objectManager->create($this->filterTypes[self::CATEGORY_FILTER], ['layer' => $layer]),
71  ];
72  foreach ($this->filterableAttributes->getList() as $attribute) {
73  $this->filters[] = $this->createAttributeFilter($attribute, $layer);
74  }
75  }
76  return $this->filters;
77  }
createAttributeFilter(\Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute, \Magento\Catalog\Model\Layer $layer)
Definition: FilterList.php:86

Field Documentation

◆ $filterableAttributes

$filterableAttributes
protected

Definition at line 26 of file FilterList.php.

◆ $filters

$filters = []
protected

Definition at line 41 of file FilterList.php.

◆ $filterTypes

$filterTypes
protected
Initial value:
= [
self::CATEGORY_FILTER => \Magento\Catalog\Model\Layer\Filter\Category::class,
self::ATTRIBUTE_FILTER => \Magento\Catalog\Model\Layer\Filter\Attribute::class,
self::PRICE_FILTER => \Magento\Catalog\Model\Layer\Filter\Price::class,
self::DECIMAL_FILTER => \Magento\Catalog\Model\Layer\Filter\Decimal::class,
]

Definition at line 31 of file FilterList.php.

◆ $objectManager

$objectManager
protected

Definition at line 21 of file FilterList.php.

◆ ATTRIBUTE_FILTER

const ATTRIBUTE_FILTER = 'attribute'

Definition at line 12 of file FilterList.php.

◆ CATEGORY_FILTER

const CATEGORY_FILTER = 'category'

Definition at line 11 of file FilterList.php.

◆ DECIMAL_FILTER

const DECIMAL_FILTER = 'decimal'

Definition at line 14 of file FilterList.php.

◆ PRICE_FILTER

const PRICE_FILTER = 'price'

Definition at line 13 of file FilterList.php.


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