Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Static Public Member Functions | Data Fields | Protected Attributes
Visibility Class Reference
Inheritance diagram for Visibility:
DataObject OptionSourceInterface

Public Member Functions

 __construct (\Magento\Eav\Model\ResourceModel\Entity\Attribute $eavEntityAttribute, array $data=[])
 
 getVisibleInCatalogIds ()
 
 getVisibleInSearchIds ()
 
 getVisibleInSiteIds ()
 
 getFlatColumns ()
 
 getFlatIndexes ()
 
 getFlatUpdateSelect ($store)
 
 setAttribute ($attribute)
 
 getAttribute ()
 
 addValueSortToCollection ($collection, $dir='asc')
 
 toOptionArray ()
 
- 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)
 

Static Public Member Functions

static getOptionArray ()
 
static getAllOption ()
 
static getAllOptions ()
 
static getOptionText ($optionId)
 

Data Fields

const VISIBILITY_NOT_VISIBLE = 1
 
const VISIBILITY_IN_CATALOG = 2
 
const VISIBILITY_IN_SEARCH = 3
 
const VISIBILITY_BOTH = 4
 

Protected Attributes

 $_attribute
 
 $_eavEntityAttribute
 
- Protected Attributes inherited from DataObject
 $_data = []
 

Additional Inherited Members

- Protected Member Functions inherited from DataObject
 _getData ($key)
 
 _underscore ($name)
 
- Static Protected Attributes inherited from DataObject
static $_underscoreCache = []
 

Detailed Description

Catalog Product visibility model and attribute source model

@api

Since
100.0.2

Definition at line 17 of file Visibility.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Eav\Model\ResourceModel\Entity\Attribute  $eavEntityAttribute,
array  $data = [] 
)

Construct

Parameters
\Magento\Eav\Model\ResourceModel\Entity\Attribute$eavEntityAttribute
array$data

Definition at line 47 of file Visibility.php.

50  {
51  $this->_eavEntityAttribute = $eavEntityAttribute;
52  parent::__construct($data);
53  }

Member Function Documentation

◆ addValueSortToCollection()

addValueSortToCollection (   $collection,
  $dir = 'asc' 
)

Add Value Sort To Collection Select

Parameters
\Magento\Eav\Model\Entity\Collection\AbstractCollection$collection
string$dirdirection
Returns
$this

Definition at line 209 of file Visibility.php.

210  {
211  $attributeCode = $this->getAttribute()->getAttributeCode();
212  $attributeId = $this->getAttribute()->getId();
213  $attributeTable = $this->getAttribute()->getBackend()->getTable();
214  $linkField = $this->getAttribute()->getEntity()->getLinkField();
215 
216  if ($this->getAttribute()->isScopeGlobal()) {
217  $tableName = $attributeCode . '_t';
218  $collection->getSelect()->joinLeft(
219  [$tableName => $attributeTable],
220  "e.{$linkField}={$tableName}.{$linkField}" .
221  " AND {$tableName}.attribute_id='{$attributeId}'" .
222  " AND {$tableName}.store_id='0'",
223  []
224  );
225  $valueExpr = $tableName . '.value';
226  } else {
227  $valueTable1 = $attributeCode . '_t1';
228  $valueTable2 = $attributeCode . '_t2';
229  $collection->getSelect()->joinLeft(
230  [$valueTable1 => $attributeTable],
231  "e.{$linkField}={$valueTable1}.{$linkField}" .
232  " AND {$valueTable1}.attribute_id='{$attributeId}'" .
233  " AND {$valueTable1}.store_id='0'",
234  []
235  )->joinLeft(
236  [$valueTable2 => $attributeTable],
237  "e.{$linkField}={$valueTable2}.{$linkField}" .
238  " AND {$valueTable2}.attribute_id='{$attributeId}'" .
239  " AND {$valueTable2}.store_id='{$collection->getStoreId()}'",
240  []
241  );
242  $valueExpr = $collection->getConnection()->getCheckSql(
243  $valueTable2 . '.value_id > 0',
244  $valueTable2 . '.value',
245  $valueTable1 . '.value'
246  );
247  }
248 
249  $collection->getSelect()->order($valueExpr . ' ' . $dir);
250  return $this;
251  }
$tableName
Definition: trigger.php:13
$attributeCode
Definition: extend.phtml:12

◆ getAllOption()

static getAllOption ( )
static

Retrieve all options

Returns
array

Definition at line 105 of file Visibility.php.

106  {
108  array_unshift($options, ['value' => '', 'label' => '']);
109  return $options;
110  }

◆ getAllOptions()

static getAllOptions ( )
static

Retrieve all options

Returns
array

Definition at line 117 of file Visibility.php.

118  {
119  $res = [];
120  foreach (self::getOptionArray() as $index => $value) {
121  $res[] = ['value' => $index, 'label' => $value];
122  }
123  return $res;
124  }
$value
Definition: gender.phtml:16
$index
Definition: list.phtml:44

◆ getAttribute()

getAttribute ( )

Get attribute instance

Returns
\Magento\Catalog\Model\ResourceModel\Eav\Attribute

Definition at line 197 of file Visibility.php.

◆ getFlatColumns()

getFlatColumns ( )

Retrieve flat column definition

Returns
array

Definition at line 143 of file Visibility.php.

144  {
145  $attributeCode = $this->getAttribute()->getAttributeCode();
146 
147  return [
148  $attributeCode => [
149  'unsigned' => true,
150  'default' => null,
151  'extra' => null,
152  'type' => Table::TYPE_SMALLINT,
153  'nullable' => true,
154  'comment' => 'Catalog Product Visibility ' . $attributeCode . ' column',
155  ],
156  ];
157  }
$attributeCode
Definition: extend.phtml:12

◆ getFlatIndexes()

getFlatIndexes ( )

Retrieve Indexes for Flat

Returns
array

Definition at line 164 of file Visibility.php.

165  {
166  return [];
167  }

◆ getFlatUpdateSelect()

getFlatUpdateSelect (   $store)

Retrieve Select For Flat Attribute update

Parameters
int$store
Returns
\Magento\Framework\DB\Select|null

Definition at line 175 of file Visibility.php.

176  {
177  return $this->_eavEntityAttribute->getFlatUpdateSelect($this->getAttribute(), $store);
178  }

◆ getOptionArray()

static getOptionArray ( )
static

Retrieve option array

Returns
array

Definition at line 90 of file Visibility.php.

91  {
92  return [
93  self::VISIBILITY_NOT_VISIBLE => __('Not Visible Individually'),
94  self::VISIBILITY_IN_CATALOG => __('Catalog'),
95  self::VISIBILITY_IN_SEARCH => __('Search'),
96  self::VISIBILITY_BOTH => __('Catalog, Search')
97  ];
98  }
__()
Definition: __.php:13

◆ getOptionText()

static getOptionText (   $optionId)
static

Retrieve option text

Parameters
int$optionId
Returns
string

Definition at line 132 of file Visibility.php.

133  {
135  return isset($options[$optionId]) ? $options[$optionId] : null;
136  }

◆ getVisibleInCatalogIds()

getVisibleInCatalogIds ( )

Retrieve visible in catalog ids array

Returns
string[]

Definition at line 60 of file Visibility.php.

◆ getVisibleInSearchIds()

getVisibleInSearchIds ( )

Retrieve visible in search ids array

Returns
string[]

Definition at line 70 of file Visibility.php.

◆ getVisibleInSiteIds()

getVisibleInSiteIds ( )

Retrieve visible in site ids array

Returns
string[]

Definition at line 80 of file Visibility.php.

◆ setAttribute()

setAttribute (   $attribute)

Set attribute instance

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

Definition at line 186 of file Visibility.php.

187  {
188  $this->_attribute = $attribute;
189  return $this;
190  }

◆ toOptionArray()

toOptionArray ( )

{Return array of options as value-label pairs

Returns
array Format: array(array('value' => '

', 'label' => '<label>'), ...)}

Implements OptionSourceInterface.

Definition at line 256 of file Visibility.php.

257  {
258  return $this->getAllOptions();
259  }

Field Documentation

◆ $_attribute

$_attribute
protected

Definition at line 32 of file Visibility.php.

◆ $_eavEntityAttribute

$_eavEntityAttribute
protected

Definition at line 39 of file Visibility.php.

◆ VISIBILITY_BOTH

const VISIBILITY_BOTH = 4

Definition at line 25 of file Visibility.php.

◆ VISIBILITY_IN_CATALOG

const VISIBILITY_IN_CATALOG = 2

Definition at line 21 of file Visibility.php.

◆ VISIBILITY_IN_SEARCH

const VISIBILITY_IN_SEARCH = 3

Definition at line 23 of file Visibility.php.

◆ VISIBILITY_NOT_VISIBLE

const VISIBILITY_NOT_VISIBLE = 1

Definition at line 19 of file Visibility.php.


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