Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
Collection Class Reference
Inheritance diagram for Collection:
Collection AbstractCollection AbstractCollection AbstractDb SourceProviderInterface Collection ArrayInterface CollectionDataSourceInterface OptionSourceInterface ArgumentInterface AssociatedProductsCollection

Public Member Functions

 setLinkModel (\Magento\Catalog\Model\Product\Link $linkModel)
 
 setIsStrongMode ()
 
 getLinkModel ()
 
 setProduct (\Magento\Catalog\Model\Product $product)
 
 getProduct ()
 
 addExcludeProductFilter ($products)
 
 addProductFilter ($products)
 
 setRandomOrder ()
 
 setGroupBy ($groupBy='e.entity_id')
 
 setPositionOrder ($dir=self::SORT_ORDER_ASC)
 
 setAttributeSetIdOrder ($dir=self::SORT_ORDER_ASC)
 
 joinAttributes ()
 
 setOrder ($attribute, $dir=self::SORT_ORDER_ASC)
 
 getLinkAttributes ($type=null)
 
 addLinkAttributeToFilter ($code, $condition)
 
- Public Member Functions inherited from Collection
 __construct (\Magento\Framework\Data\Collection\EntityFactory $entityFactory, \Psr\Log\LoggerInterface $logger, \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy, \Magento\Framework\Event\ManagerInterface $eventManager, \Magento\Eav\Model\Config $eavConfig, \Magento\Framework\App\ResourceConnection $resource, \Magento\Eav\Model\EntityFactory $eavEntityFactory, \Magento\Catalog\Model\ResourceModel\Helper $resourceHelper, \Magento\Framework\Validator\UniversalFactory $universalFactory, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\Module\Manager $moduleManager, \Magento\Catalog\Model\Indexer\Product\Flat\State $catalogProductFlatState, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Catalog\Model\Product\OptionFactory $productOptionFactory, \Magento\Catalog\Model\ResourceModel\Url $catalogUrl, \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate, \Magento\Customer\Model\Session $customerSession, \Magento\Framework\Stdlib\DateTime $dateTime, GroupManagementInterface $groupManagement, \Magento\Framework\DB\Adapter\AdapterInterface $connection=null, ProductLimitationFactory $productLimitationFactory=null, MetadataPool $metadataPool=null, TableMaintainer $tableMaintainer=null, PriceTableResolver $priceTableResolver=null, DimensionFactory $dimensionFactory=null)
 
 getCatalogPreparedSelect ()
 
 getPriceExpression ($select)
 
 getAdditionalPriceExpression ($select)
 
 getCurrencyRate ()
 
 getFlatState ()
 
 isEnabledFlat ()
 
 getNewEmptyItem ()
 
 setEntity ($entity)
 
 setStore ($store)
 
 _loadAttributes ($printQuery=false, $logQuery=false)
 
 addAttributeToSelect ($attribute, $joinType=false)
 
 addIdFilter ($productId, $exclude=false)
 
 addWebsiteNamesToResult ()
 
 load ($printQuery=false, $logQuery=false)
 
 addStoreFilter ($store=null)
 
 addWebsiteFilter ($websites=null)
 
 getLimitationFilters ()
 
 addCategoryFilter (\Magento\Catalog\Model\Category $category)
 
 addCategoriesFilter (array $categoriesFilter)
 
 joinMinimalPrice ()
 
 getMaxAttributeValue ($attribute)
 
 getAttributeValueCountByRange ($attribute, $range)
 
 getAttributeValueCount ($attribute)
 
 getSelectCountSql ()
 
 getAllIds ($limit=null, $offset=null)
 
 getProductCountSelect ()
 
 unsProductCountSelect ()
 
 addCountToCategories ($categoryCollection)
 
 joinUrlRewrite ()
 
 addUrlRewrite ($categoryId='')
 
 addMinimalPrice ()
 
 addFinalPrice ()
 
 getAllIdsCache ($resetCache=false)
 
 setAllIdsCache ($value)
 
 addPriceData ($customerGroupId=null, $websiteId=null)
 
 addAttributeToFilter ($attribute, $condition=null, $joinType='inner')
 
 addTaxPercents ()
 
 requireTaxPercent ()
 
 addOptionsToResult ()
 
 addFilterByRequiredOptions ()
 
 setVisibility ($visibility)
 
 addAttributeToSort ($attribute, $dir=self::SORT_ORDER_ASC)
 
 applyFrontendPriceLimitations ()
 
 addCategoryIds ()
 
 addTierPriceData ()
 
 addTierPriceDataByGroupId ($customerGroupId)
 
 addPriceDataFieldFilter ($comparisonFormat, $fields)
 
 addMediaGalleryData ()
 
 getProductEntityMetadata ()
 
 clear ()
 
 setOrder ($attribute, $dir=Select::SQL_DESC)
 
 getMaxPrice ()
 
 getMinPrice ()
 
 getPriceStandardDeviation ()
 
 getPricesCount ()
 
- Public Member Functions inherited from AbstractCollection
 __construct (\Magento\Framework\Data\Collection\EntityFactory $entityFactory, \Psr\Log\LoggerInterface $logger, \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy, \Magento\Framework\Event\ManagerInterface $eventManager, \Magento\Eav\Model\Config $eavConfig, \Magento\Framework\App\ResourceConnection $resource, \Magento\Eav\Model\EntityFactory $eavEntityFactory, \Magento\Eav\Model\ResourceModel\Helper $resourceHelper, \Magento\Framework\Validator\UniversalFactory $universalFactory, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\DB\Adapter\AdapterInterface $connection=null)
 
 setStore ($store)
 
 setStoreId ($storeId)
 
 getStoreId ()
 
 getDefaultStoreId ()
 
- Public Member Functions inherited from AbstractCollection
 __construct (\Magento\Framework\Data\Collection\EntityFactory $entityFactory, \Psr\Log\LoggerInterface $logger, \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy, \Magento\Framework\Event\ManagerInterface $eventManager, \Magento\Eav\Model\Config $eavConfig, \Magento\Framework\App\ResourceConnection $resource, \Magento\Eav\Model\EntityFactory $eavEntityFactory, \Magento\Eav\Model\ResourceModel\Helper $resourceHelper, \Magento\Framework\Validator\UniversalFactory $universalFactory, \Magento\Framework\DB\Adapter\AdapterInterface $connection=null)
 
 getTable ($table)
 
 setEntity ($entity)
 
 getEntity ()
 
 getResource ()
 
 setObject ($object=null)
 
 addItem (\Magento\Framework\DataObject $object)
 
 getAttribute ($attributeCode)
 
 addAttributeToFilter ($attribute, $condition=null, $joinType='inner')
 
 addFieldToFilter ($attribute, $condition=null)
 
 addAttributeToSort ($attribute, $dir=self::SORT_ORDER_ASC)
 
 addAttributeToSelect ($attribute, $joinType=false)
 
 addEntityTypeToSelect ($entityType, $prefix)
 
 addStaticField ($field)
 
 addExpressionAttributeToSelect ($alias, $expression, $attribute)
 
 groupByAttribute ($attribute)
 
 joinAttribute ($alias, $attribute, $bind, $filter=null, $joinType='inner', $storeId=null)
 
 joinField ($alias, $table, $field, $bind, $cond=null, $joinType='inner')
 
 joinTable ($table, $bind, $fields=null, $cond=null, $joinType='inner')
 
 removeAttributeToSelect ($attribute=null)
 
 setPage ($pageNum, $pageSize)
 
 load ($printQuery=false, $logQuery=false)
 
 getAllIds ($limit=null, $offset=null)
 
 getAllIdsSql ()
 
 save ()
 
 delete ()
 
 importFromArray ($arr)
 
 exportToArray ()
 
 getRowIdFieldName ()
 
 getIdFieldName ()
 
 setRowIdFieldName ($fieldName)
 
 _loadAttributes ($printQuery=false, $logQuery=false)
 
 setOrder ($attribute, $dir=self::SORT_ORDER_ASC)
 
 toArray ($arrAttributes=[])
 
 isAttributeAdded ($attributeCode)
 
 getLoadedIds ()
 
 clear ()
 
 removeAllItems ()
 
 removeItemByKey ($key)
 
 getMainTable ()
 
 addFieldToSelect ($field, $alias=null)
 
 removeFieldFromSelect ($field)
 
 removeAllFieldsFromSelect ()
 
- Public Member Functions inherited from AbstractDb
 __construct (EntityFactoryInterface $entityFactory, Logger $logger, FetchStrategyInterface $fetchStrategy, \Magento\Framework\DB\Adapter\AdapterInterface $connection=null)
 
 getResource ()
 
 addBindParam ($name, $value)
 
 getIdFieldName ()
 
 setConnection (\Magento\Framework\DB\Adapter\AdapterInterface $conn)
 
 getSelect ()
 
 getConnection ()
 
 getSize ()
 
 getSelectCountSql ()
 
 getSelectSql ($stringMode=false)
 
 setOrder ($field, $direction=self::SORT_ORDER_DESC)
 
 addOrder ($field, $direction=self::SORT_ORDER_DESC)
 
 unshiftOrder ($field, $direction=self::SORT_ORDER_DESC)
 
 addFieldToFilter ($field, $condition=null)
 
 distinct ($flag)
 
 load ($printQuery=false, $logQuery=false)
 
 loadWithFilter ($printQuery=false, $logQuery=false)
 
 fetchItem ()
 
 getData ()
 
 resetData ()
 
 loadData ($printQuery=false, $logQuery=false)
 
 printLogQuery ($printQuery=false, $logQuery=false, $sql=null)
 
 addFilterToMap ($filter, $alias, $group='fields')
 
 __clone ()
 
 joinExtensionAttribute (JoinDataInterface $join, JoinProcessorInterface $extensionAttributesJoinProcessor)
 
 getItemObjectClass ()
 
 __sleep ()
 
 __wakeup ()
 
- Public Member Functions inherited from Collection
 __construct (EntityFactoryInterface $entityFactory)
 
 addFilter ($field, $value, $type='and')
 
 addFieldToFilter ($field, $condition)
 
 getFilter ($field)
 
 isLoaded ()
 
 getCurPage ($displacement=0)
 
 getLastPageNumber ()
 
 getPageSize ()
 
 getSize ()
 
 getFirstItem ()
 
 getLastItem ()
 
 getItems ()
 
 getColumnValues ($colName)
 
 getItemsByColumnValue ($column, $value)
 
 getItemByColumnValue ($column, $value)
 
 addItem (\Magento\Framework\DataObject $item)
 
 getAllIds ()
 
 removeItemByKey ($key)
 
 removeAllItems ()
 
 clear ()
 
 walk ($callback, array $args=[])
 
 each ($objMethod, $args=[])
 
 setDataToAll ($key, $value=null)
 
 setCurPage ($page)
 
 setPageSize ($size)
 
 setOrder ($field, $direction=self::SORT_ORDER_DESC)
 
 setItemObjectClass ($className)
 
 getNewEmptyItem ()
 
 distinct ($flag)
 
 loadData ($printQuery=false, $logQuery=false)
 
 load ($printQuery=false, $logQuery=false)
 
 loadWithFilter ($printQuery=false, $logQuery=false)
 
 toXml ()
 
 toArray ($arrRequiredFields=[])
 
 toOptionArray ()
 
 toOptionHash ()
 
 getItemById ($idValue)
 
 getIterator ()
 
 count ()
 
 getFlag ($flag)
 
 setFlag ($flag, $value=null)
 
 hasFlag ($flag)
 
 __sleep ()
 
 __wakeup ()
 
- Public Member Functions inherited from SourceProviderInterface
 getSelect ()
 

Protected Member Functions

 _beforeLoad ()
 
 _joinLinks ()
 
- Protected Member Functions inherited from Collection
 _preparePriceExpressionParameters ($select)
 
 _construct ()
 
 _init ($model, $entityModel)
 
 _initTables ()
 
 _prepareStaticFields ()
 
 _initSelect ()
 
 _afterLoad ()
 
 doAddWebsiteNamesToResult ()
 
 _getSelectCountSql (?Select $select=null, $resetLeftJoins=true)
 
 _prepareStatisticsData ()
 
 _getClearSelect ()
 
 _buildClearSelect ($select=null)
 
 _addUrlRewrite ()
 
 getEntityPkName (\Magento\Eav\Model\Entity\AbstractEntity $entity)
 
 _prepareProductLimitationFilters ()
 
 _productLimitationJoinWebsite ()
 
 _productLimitationJoinStore ()
 
 _productLimitationJoinPrice ()
 
 _productLimitationPrice ($joinLeft=false)
 
 _applyProductLimitations ()
 
 _applyZeroStoreProductLimitations ()
 
- Protected Member Functions inherited from AbstractCollection
 getEntityPkName (\Magento\Eav\Model\Entity\AbstractEntity $entity)
 
 _getLoadAttributesSelect ($table, $attributeIds=[])
 
 _addLoadAttributesSelectValues ($select, $table, $type)
 
 _joinAttributeToSelect ($method, $attribute, $tableAlias, $condition, $fieldCode, $fieldAlias)
 
- Protected Member Functions inherited from AbstractCollection
 _construct ()
 
 _prepareStaticFields ()
 
 _initSelect ()
 
 _init ($model, $entityModel)
 
 _prepareOrderExpression ($field)
 
 _getAllIdsSelect ($limit=null, $offset=null)
 
 _getLoadAttributesSelect ($table, $attributeIds=[])
 
 _addLoadAttributesSelectValues ($select, $table, $type)
 
 _setItemAttributeValue ($valueInfo)
 
 _getAttributeTableAlias ($attributeCode)
 
 _getAttributeFieldName ($attributeCode)
 
 _addAttributeJoin ($attributeCode, $joinType='inner')
 
 getEntityPkName (\Magento\Eav\Model\Entity\AbstractEntity $entity)
 
 _joinAttributeToSelect ($method, $attribute, $tableAlias, $condition, $fieldCode, $fieldAlias)
 
 _getAttributeConditionSql ($attribute, $condition, $joinType='inner')
 
 _renderOrders ()
 
 _afterLoad ()
 
 _reset ()
 
- Protected Member Functions inherited from AbstractDb
 _setIdFieldName ($fieldName)
 
 _getItemId (\Magento\Framework\DataObject $item)
 
 _renderFilters ()
 
 _renderFiltersBefore ()
 
 _translateCondition ($field, $condition)
 
 _getMappedField ($field)
 
 _getMapper ()
 
 _getConditionSql ($fieldName, $condition)
 
 _getConditionFieldName ($fieldName)
 
 _renderOrders ()
 
 _renderLimit ()
 
 _beforeLoad ()
 
 beforeAddLoadedItem (\Magento\Framework\DataObject $item)
 
 _toOptionArray ($valueField=null, $labelField='name', $additional=[])
 
 _toOptionHash ($valueField=null, $labelField='name')
 
 _afterLoadData ()
 
 _afterLoad ()
 
 _logQuery ($sql)
 
 _reset ()
 
 _fetchAll (Select $select)
 
 _initSelect ()
 
- Protected Member Functions inherited from Collection
 _setIsLoaded ($flag=true)
 
 _addItem ($item)
 
 _getItemId (\Magento\Framework\DataObject $item)
 
 _renderFilters ()
 
 _renderOrders ()
 
 _renderLimit ()
 
 _toOptionArray ($valueField='id', $labelField='name', $additional=[])
 
 _toOptionHash ($valueField='id', $labelField='name')
 

Protected Attributes

 $_product
 
 $_linkModel
 
 $_linkTypeId
 
 $_isStrongMode
 
 $_hasLinkFilter = false
 
- Protected Attributes inherited from Collection
 $_idFieldName = 'entity_id'
 
 $_flatEnabled = []
 
 $_productWebsiteTable
 
 $_productCategoryTable
 
 $_addUrlRewrite = false
 
 $_urlRewriteCategory = ''
 
 $_addFinalPrice = false
 
 $_allIdsCache = null
 
 $_addTaxPercents = false
 
 $_productLimitationFilters
 
 $_productCountSelect = null
 
 $_isWebsiteFilter = false
 
 $_priceDataFieldFilters = []
 
 $_priceExpression
 
 $_additionalPriceExpression
 
 $_maxPrice
 
 $_minPrice
 
 $_priceStandardDeviation
 
 $_pricesCount = null
 
 $_catalogPreparePriceSelect = null
 
 $_catalogProductFlatState = null
 
 $moduleManager = null
 
 $_scopeConfig
 
 $_customerSession
 
 $_localeDate
 
 $_catalogUrl
 
 $_productOptionFactory
 
 $_resourceHelper
 
 $dateTime
 
 $_groupManagement
 
 $needToAddWebsiteNamesToResult
 
- Protected Attributes inherited from AbstractCollection
 $_storeId
 
 $_storeManager
 
- Protected Attributes inherited from AbstractCollection
 $_itemsById = []
 
 $_staticFields = []
 
 $_entity
 
 $_selectEntityTypes = []
 
 $_selectAttributes = []
 
 $_filterAttributes = []
 
 $_joinEntities = []
 
 $_joinAttributes = []
 
 $_joinFields = []
 
 $_castToIntMap = ['validate-digits']
 
 $_eventManager = null
 
 $_eavConfig
 
 $_resource
 
 $_eavEntityFactory
 
 $_resourceHelper
 
 $_universalFactory
 
- Protected Attributes inherited from AbstractDb
 $_conn
 
 $_select
 
 $_idFieldName
 
 $_bindParams = []
 
 $_data = null
 
 $_map = null
 
 $_fetchStmt = null
 
 $_isOrdersRendered = false
 
 $_logger
 
 $extensionAttributesJoinProcessor
 
- Protected Attributes inherited from Collection
 $_items = []
 
 $_itemObjectClass = \Magento\Framework\DataObject::class
 
 $_orders = []
 
 $_filters = []
 
 $_isFiltersRendered = false
 
 $_curPage = 1
 
 $_pageSize = false
 
 $_totalRecords
 
 $_isCollectionLoaded
 
 $_flags = []
 
 $_entityFactory
 

Additional Inherited Members

- Data Fields inherited from Collection
const INDEX_TABLE_ALIAS = 'price_index'
 
const MAIN_TABLE_ALIAS = 'e'
 
- Data Fields inherited from AbstractCollection
const ATTRIBUTE_TABLE_ALIAS_PREFIX = 'at_'
 
- Data Fields inherited from Collection
const SORT_ORDER_ASC = 'ASC'
 
const SORT_ORDER_DESC = 'DESC'
 

Detailed Description

Catalog product linked products collection

@api

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

Definition at line 16 of file Collection.php.

Member Function Documentation

◆ _beforeLoad()

_beforeLoad ( )
protected

Join linked products when specified link model

Returns
$this

Definition at line 181 of file Collection.php.

182  {
183  if ($this->getLinkModel()) {
184  $this->_joinLinks();
185  $this->joinProductsToLinks();
186  }
187  return parent::_beforeLoad();
188  }

◆ _joinLinks()

_joinLinks ( )
protected

Join linked products and their attributes

Returns
$this

Definition at line 195 of file Collection.php.

196  {
197  $select = $this->getSelect();
198  $connection = $select->getConnection();
199 
200  $joinCondition = [
201  'links.linked_product_id = e.entity_id',
202  $connection->quoteInto('links.link_type_id = ?', $this->_linkTypeId),
203  ];
204  $joinType = 'join';
205  $linkField = $this->getProductEntityMetadata()->getLinkField();
206  if ($this->getProduct() && $this->getProduct()->getId()) {
207  $linkFieldId = $this->getProduct()->getData(
208  $linkField
209  );
210  if ($this->_isStrongMode) {
211  $this->getSelect()->where('links.product_id = ?', (int)$linkFieldId);
212  } else {
213  $joinType = 'joinLeft';
214  $joinCondition[] = $connection->quoteInto('links.product_id = ?', $linkFieldId);
215  }
216  $this->addFieldToFilter(
217  $linkField,
218  ['neq' => $linkFieldId]
219  );
220  } elseif ($this->_isStrongMode) {
221  $this->addFieldToFilter(
222  $linkField,
223  ['eq' => -1]
224  );
225  }
226  if ($this->_hasLinkFilter) {
227  $select->{$joinType}(
228  ['links' => $this->getTable('catalog_product_link')],
229  implode(' AND ', $joinCondition),
230  ['link_id']
231  );
232  $this->joinAttributes();
233  }
234  return $this;
235  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$connection
Definition: bulk.php:13

◆ addExcludeProductFilter()

addExcludeProductFilter (   $products)

Exclude products from filter

Parameters
array$products
Returns
$this

Definition at line 121 of file Collection.php.

122  {
123  if (!empty($products)) {
124  if (!is_array($products)) {
125  $products = [$products];
126  }
127  $this->_hasLinkFilter = true;
128  $this->getSelect()->where('links.linked_product_id NOT IN (?)', $products);
129  }
130  return $this;
131  }

◆ addLinkAttributeToFilter()

addLinkAttributeToFilter (   $code,
  $condition 
)

Add link attribute to filter.

Parameters
string$code
array$condition
Returns
$this

Definition at line 336 of file Collection.php.

337  {
338  foreach ($this->getLinkAttributes() as $attribute) {
339  if ($attribute['code'] == $code) {
340  $alias = sprintf('link_attribute_%s_%s', $code, $attribute['type']);
341  $whereCondition = $this->_getConditionSql($alias . '.`value`', $condition);
342  $this->getSelect()->where($whereCondition);
343  }
344  }
345  return $this;
346  }
if(!trim($html)) $alias
Definition: details.phtml:20
$code
Definition: info.phtml:12

◆ addProductFilter()

addProductFilter (   $products)

Add products to filter

Parameters
array | int | string$products
Returns
$this

Definition at line 139 of file Collection.php.

140  {
141  if (!empty($products)) {
142  if (!is_array($products)) {
143  $products = [$products];
144  }
145  $identifierField = $this->getProductEntityMetadata()->getIdentifierField();
146  $this->getSelect()->where("product_entity_table.$identifierField IN (?)", $products);
147  $this->_hasLinkFilter = true;
148  }
149 
150  return $this;
151  }

◆ getLinkAttributes()

getLinkAttributes (   $type = null)

Get attributes of specified link type

Parameters
int$type
Returns
array

Definition at line 324 of file Collection.php.

325  {
326  return $this->getLinkModel()->getAttributes($type);
327  }
$type
Definition: item.phtml:13

◆ getLinkModel()

getLinkModel ( )

Retrieve collection link model

Returns
\Magento\Catalog\Model\Product\Link

Definition at line 84 of file Collection.php.

◆ getProduct()

getProduct ( )

Retrieve collection base product object

Returns
\Magento\Catalog\Model\Product

Definition at line 110 of file Collection.php.

◆ joinAttributes()

joinAttributes ( )

Join attributes

Returns
$this

Definition at line 274 of file Collection.php.

275  {
276  if (!$this->getLinkModel()) {
277  return $this;
278  }
279 
280  foreach ($this->getLinkAttributes() as $attribute) {
281  $table = $this->getLinkModel()->getAttributeTypeTable($attribute['type']);
282  $alias = sprintf('link_attribute_%s_%s', $attribute['code'], $attribute['type']);
283 
284  $joinCondiotion = [
285  "{$alias}.link_id = links.link_id",
286  $this->getSelect()->getConnection()
287  ->quoteInto("{$alias}.product_link_attribute_id = ?", $attribute['id']),
288  ];
289  $this->getSelect()->joinLeft(
290  [$alias => $table],
291  implode(' AND ', $joinCondiotion),
292  [$attribute['code'] => 'value']
293  );
294  }
295 
296  return $this;
297  }
if(!trim($html)) $alias
Definition: details.phtml:20
$table
Definition: trigger.php:14

◆ setAttributeSetIdOrder()

setAttributeSetIdOrder (   $dir = self::SORT_ORDER_ASC)

Enable sorting products by its attribute set name

Parameters
string$dirsort type asc|desc
Returns
$this

Definition at line 257 of file Collection.php.

258  {
259  $this->getSelect()->joinLeft(
260  ['set' => $this->getTable('eav_attribute_set')],
261  'e.attribute_set_id = set.attribute_set_id',
262  ['attribute_set_name']
263  )->order(
264  'set.attribute_set_name ' . $dir
265  );
266  return $this;
267  }

◆ setGroupBy()

setGroupBy (   $groupBy = 'e.entity_id')

Setting group by to exclude duplications in collection

Parameters
string$groupBy
Returns
$this

Definition at line 170 of file Collection.php.

171  {
172  $this->getSelect()->group($groupBy);
173  return $this;
174  }

◆ setIsStrongMode()

setIsStrongMode ( )

Enable strong mode for inner join of linked products

Returns
$this

Definition at line 73 of file Collection.php.

74  {
75  $this->_isStrongMode = true;
76  return $this;
77  }

◆ setLinkModel()

setLinkModel ( \Magento\Catalog\Model\Product\Link  $linkModel)

Declare link model and initialize type attributes join

Parameters
\Magento\Catalog\Model\Product\Link$linkModel
Returns
$this

Definition at line 59 of file Collection.php.

60  {
61  $this->_linkModel = $linkModel;
62  if ($linkModel->getLinkTypeId()) {
63  $this->_linkTypeId = $linkModel->getLinkTypeId();
64  }
65  return $this;
66  }

◆ setOrder()

setOrder (   $attribute,
  $dir = self::SORT_ORDER_ASC 
)

Set sorting order

$attribute can also be an array of attributes

Parameters
string | array$attribute
string$dir
Returns
$this

Definition at line 308 of file Collection.php.

309  {
310  if ($attribute == 'position') {
311  return $this->setPositionOrder($dir);
312  } elseif ($attribute == 'attribute_set_id') {
313  return $this->setAttributeSetIdOrder($dir);
314  }
315  return parent::setOrder($attribute, $dir);
316  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17

◆ setPositionOrder()

setPositionOrder (   $dir = self::SORT_ORDER_ASC)

Enable sorting products by its position

Parameters
string$dirsort type asc|desc
Returns
$this

Definition at line 243 of file Collection.php.

244  {
245  if ($this->_hasLinkFilter) {
246  $this->getSelect()->order('position ' . $dir);
247  }
248  return $this;
249  }

◆ setProduct()

setProduct ( \Magento\Catalog\Model\Product  $product)

Initialize collection parent product and add limitation join

Parameters
\Magento\Catalog\Model\Product$product
Returns
$this

Definition at line 95 of file Collection.php.

96  {
97  $this->_product = $product;
98  if ($product && $product->getId()) {
99  $this->_hasLinkFilter = true;
100  $this->setStore($product->getStore());
101  }
102  return $this;
103  }

◆ setRandomOrder()

setRandomOrder ( )

Add random sorting order

Returns
$this

Definition at line 158 of file Collection.php.

159  {
160  $this->getSelect()->orderRand('main_table.entity_id');
161  return $this;
162  }

Field Documentation

◆ $_hasLinkFilter

$_hasLinkFilter = false
protected

Definition at line 51 of file Collection.php.

◆ $_isStrongMode

$_isStrongMode
protected

Definition at line 44 of file Collection.php.

◆ $_linkModel

$_linkModel
protected

Definition at line 30 of file Collection.php.

◆ $_linkTypeId

$_linkTypeId
protected

Definition at line 37 of file Collection.php.

◆ $_product

$_product
protected

Definition at line 23 of file Collection.php.


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