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

Public Member Functions

 __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 ()
 

Data Fields

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'
 

Protected Member Functions

 _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

 $_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
 

Detailed Description

Product collection

@api @SuppressWarnings(PHPMD.ExcessivePublicCount) @SuppressWarnings(PHPMD.TooManyFields) @SuppressWarnings(PHPMD.ExcessiveClassComplexity) @SuppressWarnings(PHPMD.NumberOfChildren) @SuppressWarnings(PHPMD.CouplingBetweenObjects)

Since
100.0.2

Definition at line 36 of file Collection.php.

Constructor & Destructor Documentation

◆ __construct()

__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 
)

Collection constructor

Parameters
\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 | null$connection
ProductLimitationFactory | null$productLimitationFactory
MetadataPool | null$metadataPool
TableMaintainer | null$tableMaintainer
PriceTableResolver | null$priceTableResolver
DimensionFactory | null$dimensionFactory@SuppressWarnings(PHPMD.ExcessiveParameterList)

Definition at line 322 of file Collection.php.

348  {
349  $this->moduleManager = $moduleManager;
350  $this->_catalogProductFlatState = $catalogProductFlatState;
351  $this->_scopeConfig = $scopeConfig;
352  $this->_productOptionFactory = $productOptionFactory;
353  $this->_catalogUrl = $catalogUrl;
354  $this->_localeDate = $localeDate;
355  $this->_customerSession = $customerSession;
356  $this->_resourceHelper = $resourceHelper;
357  $this->dateTime = $dateTime;
358  $this->_groupManagement = $groupManagement;
359  $productLimitationFactory = $productLimitationFactory ?: ObjectManager::getInstance()->get(
360  \Magento\Catalog\Model\ResourceModel\Product\Collection\ProductLimitationFactory::class
361  );
362  $this->_productLimitationFilters = $productLimitationFactory->create();
363  $this->metadataPool = $metadataPool ?: ObjectManager::getInstance()->get(MetadataPool::class);
364  parent::__construct(
365  $entityFactory,
366  $logger,
367  $fetchStrategy,
369  $eavConfig,
370  $resource,
371  $eavEntityFactory,
372  $resourceHelper,
373  $universalFactory,
376  );
377  $this->tableMaintainer = $tableMaintainer ?: ObjectManager::getInstance()->get(TableMaintainer::class);
378  $this->priceTableResolver = $priceTableResolver ?: ObjectManager::getInstance()->get(PriceTableResolver::class);
379  $this->dimensionFactory = $dimensionFactory
380  ?: ObjectManager::getInstance()->get(DimensionFactory::class);
381  }
$storeManager
$resource
Definition: bulk.php:12
$logger
$connection
Definition: bulk.php:13

Member Function Documentation

◆ _addUrlRewrite()

_addUrlRewrite ( )
protected

Add URL rewrites to collection

Returns
void

Definition at line 1403 of file Collection.php.

1404  {
1405  $productIds = [];
1406  foreach ($this->getItems() as $item) {
1407  $productIds[] = $item->getEntityId();
1408  }
1409  if (!$productIds) {
1410  return;
1411  }
1412 
1413  $select = $this->getConnection()
1414  ->select()
1415  ->from(['u' => $this->getTable('url_rewrite')], ['u.entity_id', 'u.request_path'])
1416  ->where('u.store_id = ?', $this->_storeManager->getStore($this->getStoreId())->getId())
1417  ->where('u.is_autogenerated = 1')
1418  ->where('u.entity_type = ?', ProductUrlRewriteGenerator::ENTITY_TYPE)
1419  ->where('u.entity_id IN(?)', $productIds);
1420 
1421  if ($this->_urlRewriteCategory) {
1422  $select->joinInner(
1423  ['cu' => $this->getTable('catalog_url_rewrite_product_category')],
1424  'u.url_rewrite_id=cu.url_rewrite_id'
1425  )->where('cu.category_id IN (?)', $this->_urlRewriteCategory);
1426  }
1427 
1428  // more priority is data with category id
1429  $urlRewrites = [];
1430 
1431  foreach ($this->getConnection()->fetchAll($select) as $row) {
1432  if (!isset($urlRewrites[$row['entity_id']])) {
1433  $urlRewrites[$row['entity_id']] = $row['request_path'];
1434  }
1435  }
1436 
1437  foreach ($this->getItems() as $item) {
1438  if (isset($urlRewrites[$item->getEntityId()])) {
1439  $item->setData('request_path', $urlRewrites[$item->getEntityId()]);
1440  } else {
1441  $item->setData('request_path', false);
1442  }
1443  }
1444  }

◆ _afterLoad()

_afterLoad ( )
protected

Processing collection items after loading. Adding url rewrites, minimal prices, final prices, tax percents.

Returns
$this

Definition at line 673 of file Collection.php.

674  {
675  if ($this->_addUrlRewrite) {
676  $this->_addUrlRewrite();
677  }
678 
679  $this->_prepareUrlDataObject();
680  $this->prepareStoreId();
681 
682  if (count($this)) {
683  $this->_eventManager->dispatch('catalog_product_collection_load_after', ['collection' => $this]);
684  }
685 
686  return $this;
687  }

◆ _applyProductLimitations()

_applyProductLimitations ( )
protected

Apply limitation filters to collection Method allows using one time category product index table (or product website table) for different combinations of store_id/category_id/visibility filter states Method supports multiple changes in one collection object for this parameters

Returns
$this

Definition at line 2002 of file Collection.php.

2003  {
2006  $this->_productLimitationJoinPrice();
2008 
2009  if (!isset($filters['category_id']) && !isset($filters['visibility'])) {
2010  return $this;
2011  }
2012 
2013  $conditions = [
2014  'cat_index.product_id=e.entity_id',
2015  $this->getConnection()->quoteInto('cat_index.store_id=?', $filters['store_id']),
2016  ];
2017  if (isset($filters['visibility']) && !isset($filters['store_table'])) {
2018  $conditions[] = $this->getConnection()->quoteInto('cat_index.visibility IN(?)', $filters['visibility']);
2019  }
2020  $conditions[] = $this->getConnection()->quoteInto('cat_index.category_id=?', $filters['category_id']);
2021  if (isset($filters['category_is_anchor'])) {
2022  $conditions[] = $this->getConnection()->quoteInto('cat_index.is_parent=?', $filters['category_is_anchor']);
2023  }
2024 
2025  $joinCond = join(' AND ', $conditions);
2026  $fromPart = $this->getSelect()->getPart(\Magento\Framework\DB\Select::FROM);
2027  if (isset($fromPart['cat_index'])) {
2028  $fromPart['cat_index']['joinCondition'] = $joinCond;
2029  $this->getSelect()->setPart(\Magento\Framework\DB\Select::FROM, $fromPart);
2030  } else {
2031  $this->getSelect()->join(
2032  ['cat_index' => $this->tableMaintainer->getMainTable($this->getStoreId())],
2033  $joinCond,
2034  ['cat_index_position' => 'position']
2035  );
2036  }
2037 
2038  $this->_productLimitationJoinStore();
2039  $this->_eventManager->dispatch(
2040  'catalog_product_collection_apply_limitations_after',
2041  ['collection' => $this]
2042  );
2043  return $this;
2044  }
const FROM
Definition: Select.php:49
$filters
Definition: uploader.phtml:11

◆ _applyZeroStoreProductLimitations()

_applyZeroStoreProductLimitations ( )
protected

Apply limitation filters to collection base on API Method allows using one time category product table for combinations of category_id filter states

Returns
$this

Definition at line 2053 of file Collection.php.

2054  {
2056 
2057  $conditions = [
2058  'cat_pro.product_id=e.entity_id',
2059  $this->getConnection()->quoteInto(
2060  'cat_pro.category_id=?',
2061  $filters['category_id']
2062  ),
2063  ];
2064  $joinCond = join(' AND ', $conditions);
2065 
2066  $fromPart = $this->getSelect()->getPart(\Magento\Framework\DB\Select::FROM);
2067  if (isset($fromPart['cat_pro'])) {
2068  $fromPart['cat_pro']['joinCondition'] = $joinCond;
2069  $this->getSelect()->setPart(\Magento\Framework\DB\Select::FROM, $fromPart);
2070  } else {
2071  $this->getSelect()->join(
2072  ['cat_pro' => $this->getTable('catalog_category_product')],
2073  $joinCond,
2074  ['cat_index_position' => 'position']
2075  );
2076  }
2077  $this->_joinFields['position'] = ['table' => 'cat_pro', 'field' => 'position'];
2078 
2079  return $this;
2080  }
const FROM
Definition: Select.php:49
$filters
Definition: uploader.phtml:11

◆ _buildClearSelect()

_buildClearSelect (   $select = null)
protected

Build clear select

Parameters
\Magento\Framework\DB\Select$select
Returns
\Magento\Framework\DB\Select

Definition at line 1189 of file Collection.php.

1190  {
1191  if (null === $select) {
1192  $select = clone $this->getSelect();
1193  }
1194  $select->reset(\Magento\Framework\DB\Select::ORDER);
1195  $select->reset(\Magento\Framework\DB\Select::LIMIT_COUNT);
1196  $select->reset(\Magento\Framework\DB\Select::LIMIT_OFFSET);
1197  $select->reset(\Magento\Framework\DB\Select::COLUMNS);
1198 
1199  return $select;
1200  }
const ORDER
Definition: Select.php:54
const COLUMNS
Definition: Select.php:48
const LIMIT_OFFSET
Definition: Select.php:56
const LIMIT_COUNT
Definition: Select.php:55

◆ _construct()

_construct ( )
protected

Initialize resources

Returns
void

Definition at line 494 of file Collection.php.

495  {
496  if ($this->isEnabledFlat()) {
497  $this->_init(
498  \Magento\Catalog\Model\Product::class,
499  \Magento\Catalog\Model\ResourceModel\Product\Flat::class
500  );
501  } else {
502  $this->_init(\Magento\Catalog\Model\Product::class, \Magento\Catalog\Model\ResourceModel\Product::class);
503  }
504  $this->_initTables();
505  }

◆ _getClearSelect()

_getClearSelect ( )
protected

Retrieve clear select

Returns
\Magento\Framework\DB\Select

Definition at line 1178 of file Collection.php.

1179  {
1180  return $this->_buildClearSelect();
1181  }

◆ _getSelectCountSql()

_getSelectCountSql ( ?Select  $select = null,
  $resetLeftJoins = true 
)
protected

Get SQL for get record count

Parameters
Select$select
bool$resetLeftJoins
Returns
Select

Definition at line 1134 of file Collection.php.

1135  {
1136  $this->_renderFilters();
1137  $countSelect = $select === null ? $this->_getClearSelect() : $this->_buildClearSelect($select);
1138  $countSelect->columns('COUNT(DISTINCT e.entity_id)');
1139  if ($resetLeftJoins) {
1140  $countSelect->resetJoinLeft();
1141  }
1142  return $countSelect;
1143  }

◆ _init()

_init (   $model,
  $entityModel 
)
protected

Standard resource collection initialization. Needed for child classes.

Parameters
string$model
string$entityModel
Returns
$this

Definition at line 514 of file Collection.php.

515  {
516  if ($this->isEnabledFlat()) {
517  $entityModel = \Magento\Catalog\Model\ResourceModel\Product\Flat::class;
518  }
519  return parent::_init($model, $entityModel);
520  }

◆ _initSelect()

_initSelect ( )
protected

Initialize collection select Redeclared for remove entity_type_id condition in catalog_product_entity we store just products

Returns
$this

Definition at line 597 of file Collection.php.

598  {
599  if ($this->isEnabledFlat()) {
600  $this->getSelect()->from(
601  [self::MAIN_TABLE_ALIAS => $this->getEntity()->getFlatTableName()],
602  null
603  )->columns(
604  ['status' => new \Zend_Db_Expr(ProductStatus::STATUS_ENABLED)]
605  );
607  if ($this->_catalogProductFlatState->getFlatIndexerHelper()->isAddChildData()) {
608  $this->getSelect()->where('e.is_child=?', 0);
609  $this->addAttributeToSelect(['child_id', 'is_child']);
610  }
611  } else {
612  $this->getSelect()->from([self::MAIN_TABLE_ALIAS => $this->getEntity()->getEntityTable()]);
613  }
614  return $this;
615  }

◆ _initTables()

_initTables ( )
protected

Define product website and category product tables

Returns
void

Definition at line 527 of file Collection.php.

528  {
529  $this->_productWebsiteTable = $this->getResource()->getTable('catalog_product_website');
530  $this->_productCategoryTable = $this->getResource()->getTable('catalog_category_product');
531  }

◆ _loadAttributes()

_loadAttributes (   $printQuery = false,
  $logQuery = false 
)

Load attributes into loaded entities

Parameters
bool$printQuery
bool$logQuery
Returns
$this

Definition at line 624 of file Collection.php.

625  {
626  if ($this->isEnabledFlat()) {
627  return $this;
628  }
629  return parent::_loadAttributes($printQuery, $logQuery);
630  }

◆ _preparePriceExpressionParameters()

_preparePriceExpressionParameters (   $select)
protected

Prepare additional price expression sql part

Parameters
\Magento\Framework\DB\Select$select
Returns
$this

Definition at line 399 of file Collection.php.

400  {
401  // prepare response object for event
402  $response = new \Magento\Framework\DataObject();
403  $response->setAdditionalCalculations([]);
404  $tableAliases = array_keys($select->getPart(\Magento\Framework\DB\Select::FROM));
405  if (in_array(self::INDEX_TABLE_ALIAS, $tableAliases)) {
407  } else {
408  $table = reset($tableAliases);
409  }
410 
411  // prepare event arguments
412  $eventArgs = [
413  'select' => $select,
414  'table' => $table,
415  'store_id' => $this->getStoreId(),
416  'response_object' => $response,
417  ];
418 
419  $this->_eventManager->dispatch('catalog_prepare_price_select', $eventArgs);
420 
421  $additional = join('', $response->getAdditionalCalculations());
422  $this->_priceExpression = $table . '.min_price';
423  $this->_additionalPriceExpression = $additional;
424  $this->_catalogPreparePriceSelect = clone $select;
425 
426  return $this;
427  }
$response
Definition: 404.php:11
const FROM
Definition: Select.php:49
$table
Definition: trigger.php:14

◆ _prepareProductLimitationFilters()

_prepareProductLimitationFilters ( )
protected

Prepare limitation filters

Returns
$this

Definition at line 1754 of file Collection.php.

1755  {
1756  if (isset(
1757  $this->_productLimitationFilters['visibility']
1758  ) && !isset(
1759  $this->_productLimitationFilters['store_id']
1760  )
1761  ) {
1762  $this->_productLimitationFilters['store_id'] = $this->getStoreId();
1763  }
1764  if (isset(
1765  $this->_productLimitationFilters['category_id']
1766  ) && !isset(
1767  $this->_productLimitationFilters['store_id']
1768  )
1769  ) {
1770  $this->_productLimitationFilters['store_id'] = $this->getStoreId();
1771  }
1772  if (isset(
1773  $this->_productLimitationFilters['store_id']
1774  ) && isset(
1775  $this->_productLimitationFilters['visibility']
1776  ) && !isset(
1777  $this->_productLimitationFilters['category_id']
1778  )
1779  ) {
1780  $this->_productLimitationFilters['category_id'] = $this->_storeManager->getStore(
1781  $this->_productLimitationFilters['store_id']
1782  )->getRootCategoryId();
1783  }
1784 
1785  return $this;
1786  }

◆ _prepareStaticFields()

_prepareStaticFields ( )
protected

Prepare static entity fields

Returns
$this

Definition at line 538 of file Collection.php.

539  {
540  if ($this->isEnabledFlat()) {
541  return $this;
542  }
543  return parent::_prepareStaticFields();
544  }

◆ _prepareStatisticsData()

_prepareStatisticsData ( )
protected

Prepare statistics data

Returns
$this

Definition at line 1150 of file Collection.php.

1151  {
1152  $select = clone $this->getSelect();
1153  $priceExpression = $this->getPriceExpression($select) . ' ' . $this->getAdditionalPriceExpression($select);
1154  $sqlEndPart = ') * ' . $this->getCurrencyRate() . ', 2)';
1155  $select = $this->_getSelectCountSql($select, false);
1156  $select->columns(
1157  [
1158  'max' => 'ROUND(MAX(' . $priceExpression . $sqlEndPart,
1159  'min' => 'ROUND(MIN(' . $priceExpression . $sqlEndPart,
1160  'std' => $this->getConnection()->getStandardDeviationSql('ROUND((' . $priceExpression . $sqlEndPart),
1161  ]
1162  );
1163  $select->where($this->getPriceExpression($select) . ' IS NOT NULL');
1164  $row = $this->getConnection()->fetchRow($select, $this->_bindParams, \Zend_Db::FETCH_NUM);
1165  $this->_pricesCount = (int)$row[0];
1166  $this->_maxPrice = (double)$row[1];
1167  $this->_minPrice = (double)$row[2];
1168  $this->_priceStandardDeviation = (double)$row[3];
1169 
1170  return $this;
1171  }
_getSelectCountSql(?Select $select=null, $resetLeftJoins=true)
const FETCH_NUM
Definition: Db.php:153

◆ _productLimitationJoinPrice()

_productLimitationJoinPrice ( )
protected

Join Product Price Table

Returns
$this

Definition at line 1883 of file Collection.php.

1884  {
1885  return $this->_productLimitationPrice();
1886  }

◆ _productLimitationJoinStore()

_productLimitationJoinStore ( )
protected

Join additional (alternative) store visibility filter

Returns
$this @SuppressWarnings(PHPMD.CyclomaticComplexity) @SuppressWarnings(PHPMD.NPathComplexity)

Definition at line 1848 of file Collection.php.

1849  {
1851  if (!isset($filters['store_table'])) {
1852  return $this;
1853  }
1854 
1855  $hasColumn = false;
1856  foreach ($this->getSelect()->getPart(\Magento\Framework\DB\Select::COLUMNS) as $columnEntry) {
1857  list(, , $alias) = $columnEntry;
1858  if ($alias == 'visibility') {
1859  $hasColumn = true;
1860  }
1861  }
1862  if (!$hasColumn) {
1863  $this->getSelect()->columns('visibility', 'cat_index');
1864  }
1865 
1866  // Avoid column duplication problems
1867  $this->_resourceHelper->prepareColumnsList($this->getSelect());
1868 
1869  $whereCond = $this->getConnection()->quoteInto('cat_index.visibility IN(?)', $filters['visibility']);
1870  $wherePart = $this->getSelect()->getPart(\Magento\Framework\DB\Select::WHERE);
1871  if (array_search('(' . $whereCond . ')', $wherePart) === false) {
1872  $this->getSelect()->where($whereCond);
1873  }
1874 
1875  return $this;
1876  }
const COLUMNS
Definition: Select.php:48
const WHERE
Definition: Select.php:51
$filters
Definition: uploader.phtml:11
if(!trim($html)) $alias
Definition: details.phtml:20

◆ _productLimitationJoinWebsite()

_productLimitationJoinWebsite ( )
protected

Join website product limitation

Returns
$this @SuppressWarnings(PHPMD.CyclomaticComplexity)

Definition at line 1794 of file Collection.php.

1795  {
1796  $joinWebsite = false;
1798  $conditions = ['product_website.product_id = e.entity_id'];
1799 
1800  if (isset($filters['website_ids'])) {
1801  $joinWebsite = true;
1802  if (count($filters['website_ids']) > 1) {
1803  $this->getSelect()->distinct(true);
1804  }
1805  $conditions[] = $this->getConnection()->quoteInto(
1806  'product_website.website_id IN(?)',
1807  $filters['website_ids']
1808  );
1809  } elseif (isset(
1810  $filters['store_id']
1811  ) && (!isset(
1812  $filters['visibility']
1813  ) && !isset(
1814  $filters['category_id']
1815  )) && !$this->isEnabledFlat()
1816  ) {
1817  $joinWebsite = true;
1818  $websiteId = $this->_storeManager->getStore($filters['store_id'])->getWebsiteId();
1819  $conditions[] = $this->getConnection()->quoteInto('product_website.website_id = ?', $websiteId);
1820  }
1821 
1822  $fromPart = $this->getSelect()->getPart(\Magento\Framework\DB\Select::FROM);
1823  if (isset($fromPart['product_website'])) {
1824  if (!$joinWebsite) {
1825  unset($fromPart['product_website']);
1826  } else {
1827  $fromPart['product_website']['joinCondition'] = join(' AND ', $conditions);
1828  }
1829  $this->getSelect()->setPart(\Magento\Framework\DB\Select::FROM, $fromPart);
1830  } elseif ($joinWebsite) {
1831  $this->getSelect()->join(
1832  ['product_website' => $this->getTable('catalog_product_website')],
1833  join(' AND ', $conditions),
1834  []
1835  );
1836  }
1837 
1838  return $this;
1839  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
const FROM
Definition: Select.php:49
$filters
Definition: uploader.phtml:11

◆ _productLimitationPrice()

_productLimitationPrice (   $joinLeft = false)
protected

Join Product Price Table with left-join possibility

See also
\Magento\Catalog\Model\ResourceModel\Product\Collection::_productLimitationJoinPrice()
Parameters
bool$joinLeft
Returns
$this

Definition at line 1895 of file Collection.php.

1896  {
1898  if (!$filters->isUsingPriceIndex() ||
1899  !isset($filters['website_id']) ||
1900  (string)$filters['website_id'] === '' ||
1901  !isset($filters['customer_group_id']) ||
1902  (string)$filters['customer_group_id'] === ''
1903  ) {
1904  return $this;
1905  }
1906 
1907  // Preventing overriding price loaded from EAV because we want to use the one from index
1908  $this->removeAttributeToSelect('price');
1909 
1910  $connection = $this->getConnection();
1911  $select = $this->getSelect();
1912  $joinCond = join(
1913  ' AND ',
1914  [
1915  'price_index.entity_id = e.entity_id',
1916  $connection->quoteInto('price_index.website_id = ?', $filters['website_id']),
1917  $connection->quoteInto('price_index.customer_group_id = ?', $filters['customer_group_id'])
1918  ]
1919  );
1920 
1921  $fromPart = $select->getPart(\Magento\Framework\DB\Select::FROM);
1922  if (!isset($fromPart['price_index'])) {
1923  $least = $connection->getLeastSql(['price_index.min_price', 'price_index.tier_price']);
1924  $minimalExpr = $connection->getCheckSql(
1925  'price_index.tier_price IS NOT NULL',
1926  $least,
1927  'price_index.min_price'
1928  );
1929  $colls = [
1930  'price',
1931  'tax_class_id',
1932  'final_price',
1933  'minimal_price' => $minimalExpr,
1934  'min_price',
1935  'max_price',
1936  'tier_price',
1937  ];
1938 
1939  $tableName = [
1940  'price_index' => $this->priceTableResolver->resolve(
1941  'catalog_product_index_price',
1942  [
1943  $this->dimensionFactory->create(
1944  CustomerGroupDimensionProvider::DIMENSION_NAME,
1945  (string)$filters['customer_group_id']
1946  ),
1947  $this->dimensionFactory->create(
1948  WebsiteDimensionProvider::DIMENSION_NAME,
1949  (string)$filters['website_id']
1950  )
1951  ]
1952  )
1953  ];
1954 
1955  if ($joinLeft) {
1956  $select->joinLeft($tableName, $joinCond, $colls);
1957  } else {
1958  $select->join($tableName, $joinCond, $colls);
1959  }
1960  // Set additional field filters
1961  foreach ($this->_priceDataFieldFilters as $filterData) {
1962  $select->where(call_user_func_array('sprintf', $filterData));
1963  }
1964  } else {
1965  $fromPart['price_index']['joinCondition'] = $joinCond;
1966  $select->setPart(\Magento\Framework\DB\Select::FROM, $fromPart);
1967  }
1968  //Clean duplicated fields
1969  $this->_resourceHelper->prepareColumnsList($select);
1970 
1971  return $this;
1972  }
$tableName
Definition: trigger.php:13
const FROM
Definition: Select.php:49
$filters
Definition: uploader.phtml:11
$connection
Definition: bulk.php:13

◆ addAttributeToFilter()

addAttributeToFilter (   $attribute,
  $condition = null,
  $joinType = 'inner' 
)

Add attribute to filter

Parameters
\Magento\Eav\Model\Entity\Attribute\AbstractAttribute | string$attribute
array$condition
string$joinType
Returns
$this @SuppressWarnings(PHPMD.CyclomaticComplexity)

Definition at line 1538 of file Collection.php.

1539  {
1540  if ($this->isEnabledFlat()) {
1541  if ($attribute instanceof \Magento\Eav\Model\Entity\Attribute\AbstractAttribute) {
1542  $attribute = $attribute->getAttributeCode();
1543  }
1544 
1545  if (is_array($attribute)) {
1546  $sqlArr = [];
1547  foreach ($attribute as $condition) {
1548  $sqlArr[] = $this->_getAttributeConditionSql($condition['attribute'], $condition, $joinType);
1549  }
1550  $conditionSql = '(' . join(') OR (', $sqlArr) . ')';
1551  $this->getSelect()->where($conditionSql);
1552  return $this;
1553  }
1554 
1555  if (!isset($this->_selectAttributes[$attribute])) {
1556  $this->addAttributeToSelect($attribute);
1557  }
1558 
1559  if (isset($this->_selectAttributes[$attribute])) {
1560  $this->getSelect()->where($this->_getConditionSql('e.' . $attribute, $condition));
1561  }
1562 
1563  return $this;
1564  }
1565 
1566  $this->_allIdsCache = null;
1567 
1568  if (is_string($attribute) && $attribute == 'is_saleable') {
1569  $columns = $this->getSelect()->getPart(\Magento\Framework\DB\Select::COLUMNS);
1570  foreach ($columns as $columnEntry) {
1571  list($correlationName, $column, $alias) = $columnEntry;
1572  if ($alias == 'is_saleable') {
1573  if ($column instanceof \Zend_Db_Expr) {
1574  $field = $column;
1575  } else {
1576  $connection = $this->getSelect()->getConnection();
1577  if (empty($correlationName)) {
1578  $field = $connection->quoteColumnAs($column, $alias, true);
1579  } else {
1580  $field = $connection->quoteColumnAs([$correlationName, $column], $alias, true);
1581  }
1582  }
1583  $this->getSelect()->where("{$field} = ?", $condition);
1584  break;
1585  }
1586  }
1587 
1588  return $this;
1589  } else {
1590  return parent::addAttributeToFilter($attribute, $condition, $joinType);
1591  }
1592  }
$columns
Definition: default.phtml:15
_getAttributeConditionSql($attribute, $condition, $joinType='inner')
const COLUMNS
Definition: Select.php:48
if(!trim($html)) $alias
Definition: details.phtml:20
$connection
Definition: bulk.php:13

◆ addAttributeToSelect()

addAttributeToSelect (   $attribute,
  $joinType = false 
)

Add attribute to entities in collection. If $attribute=='*' select all attributes.

Parameters
array | string | integer | \Magento\Framework\App\Config\Element$attribute
bool | string$joinType
Returns
$this

Definition at line 639 of file Collection.php.

640  {
641  if ($this->isEnabledFlat()) {
642  if (!is_array($attribute)) {
644  }
645  foreach ($attribute as $attributeCode) {
646  if ($attributeCode == '*') {
647  foreach ($this->getEntity()->getAllTableColumns() as $column) {
648  $this->getSelect()->columns('e.' . $column);
649  $this->_selectAttributes[$column] = $column;
650  $this->_staticFields[$column] = $column;
651  }
652  } else {
653  $columns = $this->getEntity()->getAttributeForSelect($attributeCode);
654  if ($columns) {
655  foreach ($columns as $alias => $column) {
656  $this->getSelect()->columns([$alias => 'e.' . $column]);
657  $this->_selectAttributes[$column] = $column;
658  $this->_staticFields[$column] = $column;
659  }
660  }
661  }
662  }
663  return $this;
664  }
665  return parent::addAttributeToSelect($attribute, $joinType);
666  }
$columns
Definition: default.phtml:15
$attributeCode
Definition: extend.phtml:12
if(!trim($html)) $alias
Definition: details.phtml:20

◆ addAttributeToSort()

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

Add attribute to sort order

Parameters
string$attribute
string$dir
Returns
$this @SuppressWarnings(PHPMD.CyclomaticComplexity) @SuppressWarnings(PHPMD.NPathComplexity)

Definition at line 1695 of file Collection.php.

1696  {
1697  if ($attribute == 'position') {
1698  if (isset($this->_joinFields[$attribute])) {
1699  $this->getSelect()->order($this->_getAttributeFieldName($attribute) . ' ' . $dir);
1700  return $this;
1701  }
1702  if ($this->isEnabledFlat()) {
1703  $this->getSelect()->order("cat_index_position {$dir}");
1704  }
1705  // optimize if using cat index
1707  if (isset($filters['category_id']) || isset($filters['visibility'])) {
1708  $this->getSelect()->order('cat_index.position ' . $dir);
1709  } else {
1710  $this->getSelect()->order('e.entity_id ' . $dir);
1711  }
1712 
1713  return $this;
1714  } elseif ($attribute == 'is_saleable') {
1715  $this->getSelect()->order("is_salable " . $dir);
1716  return $this;
1717  }
1718 
1719  $storeId = $this->getStoreId();
1720  if ($attribute == 'price' && $storeId != 0) {
1721  $this->addPriceData();
1722  if ($this->_productLimitationFilters->isUsingPriceIndex()) {
1723  $this->getSelect()->order("price_index.min_price {$dir}");
1724  return $this;
1725  }
1726  }
1727 
1728  if ($this->isEnabledFlat()) {
1729  $column = $this->getEntity()->getAttributeSortColumn($attribute);
1730 
1731  if ($column) {
1732  $this->getSelect()->order("e.{$column} {$dir}");
1733  } elseif (isset($this->_joinFields[$attribute])) {
1734  $this->getSelect()->order($this->_getAttributeFieldName($attribute) . ' ' . $dir);
1735  }
1736 
1737  return $this;
1738  } else {
1739  $attrInstance = $this->getEntity()->getAttribute($attribute);
1740  if ($attrInstance && $attrInstance->usesSource()) {
1741  $attrInstance->getSource()->addValueSortToCollection($this, $dir);
1742  return $this;
1743  }
1744  }
1745 
1746  return parent::addAttributeToSort($attribute, $dir);
1747  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
addPriceData($customerGroupId=null, $websiteId=null)
$filters
Definition: uploader.phtml:11

◆ addCategoriesFilter()

addCategoriesFilter ( array  $categoriesFilter)

Filter Product by Categories

Parameters
array$categoriesFilter
Returns
$this

Definition at line 920 of file Collection.php.

921  {
922  foreach ($categoriesFilter as $conditionType => $values) {
923  $categorySelect = $this->getConnection()->select()->from(
924  ['cat' => $this->getTable('catalog_category_product')],
925  'cat.product_id'
926  )->where($this->getConnection()->prepareSqlCondition('cat.category_id', ['in' => $values]));
927  $selectCondition = [
928  $this->mapConditionType($conditionType) => $categorySelect
929  ];
930  $this->getSelect()->where($this->getConnection()->prepareSqlCondition('e.entity_id', $selectCondition));
931  }
932  return $this;
933  }
$values
Definition: options.phtml:88

◆ addCategoryFilter()

addCategoryFilter ( \Magento\Catalog\Model\Category  $category)

Specify category filter for product collection

Parameters
\Magento\Catalog\Model\Category$category
Returns
$this

Definition at line 896 of file Collection.php.

897  {
898  $this->_productLimitationFilters['category_id'] = $category->getId();
899  if ($category->getIsAnchor()) {
900  unset($this->_productLimitationFilters['category_is_anchor']);
901  } else {
902  $this->_productLimitationFilters['category_is_anchor'] = 1;
903  }
904 
905  if ($this->getStoreId() == Store::DEFAULT_STORE_ID) {
907  } else {
908  $this->_applyProductLimitations();
909  }
910 
911  return $this;
912  }

◆ addCategoryIds()

addCategoryIds ( )

Add category ids to loaded items

Returns
$this

Definition at line 2087 of file Collection.php.

2088  {
2089  if ($this->getFlag('category_ids_added')) {
2090  return $this;
2091  }
2092  $ids = array_keys($this->_items);
2093  if (empty($ids)) {
2094  return $this;
2095  }
2096 
2097  $select = $this->getConnection()->select();
2098 
2099  $select->from($this->_productCategoryTable, ['product_id', 'category_id']);
2100  $select->where('product_id IN (?)', $ids);
2101 
2102  $data = $this->getConnection()->fetchAll($select);
2103 
2104  $categoryIds = [];
2105  foreach ($data as $info) {
2106  if (isset($categoryIds[$info['product_id']])) {
2107  $categoryIds[$info['product_id']][] = $info['category_id'];
2108  } else {
2109  $categoryIds[$info['product_id']] = [$info['category_id']];
2110  }
2111  }
2112 
2113  foreach ($this->getItems() as $item) {
2114  $productId = $item->getId();
2115  if (isset($categoryIds[$productId])) {
2116  $item->setCategoryIds($categoryIds[$productId]);
2117  } else {
2118  $item->setCategoryIds([]);
2119  }
2120  }
2121 
2122  $this->setFlag('category_ids_added', true);
2123  return $this;
2124  }
foreach( $_productCollection as $_product)() ?>" class $info
Definition: listing.phtml:52

◆ addCountToCategories()

addCountToCategories (   $categoryCollection)

Adding product count to categories collection

Parameters
\Magento\Eav\Model\Entity\Collection\AbstractCollection$categoryCollection
Returns
$this

Definition at line 1271 of file Collection.php.

1272  {
1273  $isAnchor = [];
1274  $isNotAnchor = [];
1275  foreach ($categoryCollection as $category) {
1276  if ($category->getIsAnchor()) {
1277  $isAnchor[] = $category->getId();
1278  } else {
1279  $isNotAnchor[] = $category->getId();
1280  }
1281  }
1282  $productCounts = [];
1283  if ($isAnchor || $isNotAnchor) {
1284  $select = $this->getProductCountSelect();
1285 
1286  $this->_eventManager->dispatch(
1287  'catalog_product_collection_before_add_count_to_categories',
1288  ['collection' => $this]
1289  );
1290 
1291  if ($isAnchor) {
1292  $anchorStmt = clone $select;
1293  $anchorStmt->limit();
1294  //reset limits
1295  $anchorStmt->where('count_table.category_id IN (?)', $isAnchor);
1296  $productCounts += $this->getConnection()->fetchPairs($anchorStmt);
1297  $anchorStmt = null;
1298  }
1299  if ($isNotAnchor) {
1300  $notAnchorStmt = clone $select;
1301  $notAnchorStmt->limit();
1302  //reset limits
1303  $notAnchorStmt->where('count_table.category_id IN (?)', $isNotAnchor);
1304  $notAnchorStmt->where('count_table.is_parent = 1');
1305  $productCounts += $this->getConnection()->fetchPairs($notAnchorStmt);
1306  $notAnchorStmt = null;
1307  }
1308  $select = null;
1309  $this->unsProductCountSelect();
1310  }
1311 
1312  foreach ($categoryCollection as $category) {
1313  $_count = 0;
1314  if (isset($productCounts[$category->getId()])) {
1315  $_count = $productCounts[$category->getId()];
1316  }
1317  $category->setProductCount($_count);
1318  }
1319 
1320  return $this;
1321  }
$_count
Definition: left.phtml:19

◆ addFilterByRequiredOptions()

addFilterByRequiredOptions ( )

Filter products with required options

Returns
$this

Definition at line 1666 of file Collection.php.

1667  {
1668  $this->addAttributeToFilter('required_options', [['neq' => 1], ['null' => true]], 'left');
1669  return $this;
1670  }
addAttributeToFilter($attribute, $condition=null, $joinType='inner')

◆ addFinalPrice()

addFinalPrice ( )

Add price data for calculate final price

Returns
$this

Definition at line 1461 of file Collection.php.

1462  {
1463  return $this->addPriceData();
1464  }
addPriceData($customerGroupId=null, $websiteId=null)

◆ addIdFilter()

addIdFilter (   $productId,
  $exclude = false 
)

Add collection filters by identifiers

Parameters
mixed$productId
boolean$exclude
Returns
$this

Definition at line 744 of file Collection.php.

745  {
746  if (empty($productId)) {
747  $this->_setIsLoaded(true);
748  return $this;
749  }
750  if (is_array($productId)) {
751  if (!empty($productId)) {
752  if ($exclude) {
753  $condition = ['nin' => $productId];
754  } else {
755  $condition = ['in' => $productId];
756  }
757  } else {
758  $condition = '';
759  }
760  } else {
761  if ($exclude) {
762  $condition = ['neq' => $productId];
763  } else {
764  $condition = $productId;
765  }
766  }
767  $this->addFieldToFilter('entity_id', $condition);
768  return $this;
769  }

◆ addMediaGalleryData()

addMediaGalleryData ( )

Add media gallery data to loaded items

Returns
$this @SuppressWarnings(PHPMD.CyclomaticComplexity) @SuppressWarnings(PHPMD.NPathComplexity)
Since
101.0.1
Exceptions

Definition at line 2286 of file Collection.php.

2287  {
2288  if ($this->getFlag('media_gallery_added')) {
2289  return $this;
2290  }
2291 
2292  if (!$this->getSize()) {
2293  return $this;
2294  }
2295 
2296  $items = $this->getItems();
2297  $linkField = $this->getProductEntityMetadata()->getLinkField();
2298 
2299  $select = $this->getMediaGalleryResource()
2300  ->createBatchBaseSelect(
2301  $this->getStoreId(),
2302  $this->getAttribute('media_gallery')->getAttributeId()
2303  )->reset(
2304  Select::ORDER // we don't care what order is in current scenario
2305  )->where(
2306  'entity.' . $linkField . ' IN (?)',
2307  array_map(
2308  function ($item) use ($linkField) {
2309  return (int) $item->getOrigData($linkField);
2310  },
2311  $items
2312  )
2313  );
2314 
2315  $mediaGalleries = [];
2316  foreach ($this->getConnection()->fetchAll($select) as $row) {
2317  $mediaGalleries[$row[$linkField]][] = $row;
2318  }
2319 
2320  foreach ($items as $item) {
2321  $this->getGalleryReadHandler()
2322  ->addMediaDataToProduct(
2323  $item,
2324  $mediaGalleries[$item->getOrigData($linkField)] ?? []
2325  );
2326  }
2327 
2328  $this->setFlag('media_gallery_added', true);
2329  return $this;
2330  }
const ORDER
Definition: Select.php:54
$items

◆ addMinimalPrice()

addMinimalPrice ( )

Add minimal price data to result

Returns
$this

Definition at line 1451 of file Collection.php.

1452  {
1453  return $this->addPriceData();
1454  }
addPriceData($customerGroupId=null, $websiteId=null)

◆ addOptionsToResult()

addOptionsToResult ( )

Adding product custom options to result collection

Returns
$this

Definition at line 1630 of file Collection.php.

1631  {
1632  $productsByLinkId = [];
1633 
1634  foreach ($this as $product) {
1635  $productId = $product->getData(
1636  $product->getResource()->getLinkField()
1637  );
1638 
1639  $productsByLinkId[$productId] = $product;
1640  }
1641 
1642  if (!empty($productsByLinkId)) {
1643  $options = $this->_productOptionFactory->create()->getCollection()->addTitleToResult(
1644  $this->_storeManager->getStore()->getId()
1645  )->addPriceToResult(
1646  $this->_storeManager->getStore()->getId()
1647  )->addProductToFilter(
1648  array_keys($productsByLinkId)
1649  )->addValuesToResult();
1650 
1651  foreach ($options as $option) {
1652  if (isset($productsByLinkId[$option->getProductId()])) {
1653  $productsByLinkId[$option->getProductId()]->addOption($option);
1654  }
1655  }
1656  }
1657 
1658  return $this;
1659  }

◆ addPriceData()

addPriceData (   $customerGroupId = null,
  $websiteId = null 
)

Add Price Data to result

Parameters
int$customerGroupId
int$websiteId
Returns
$this

Definition at line 1506 of file Collection.php.

1507  {
1508  $this->_productLimitationFilters->setUsePriceIndex(true);
1509 
1510  if (!isset($this->_productLimitationFilters['customer_group_id']) && $customerGroupId === null) {
1511  $customerGroupId = $this->_customerSession->getCustomerGroupId();
1512  }
1513  if (!isset($this->_productLimitationFilters['website_id']) && $websiteId === null) {
1514  $websiteId = $this->_storeManager->getStore($this->getStoreId())->getWebsiteId();
1515  }
1516 
1517  if ($customerGroupId !== null) {
1518  $this->_productLimitationFilters['customer_group_id'] = $customerGroupId;
1519  }
1520  if ($websiteId !== null) {
1521  $this->_productLimitationFilters['website_id'] = $websiteId;
1522  }
1523 
1524  $this->_applyProductLimitations();
1525 
1526  return $this;
1527  }

◆ addPriceDataFieldFilter()

addPriceDataFieldFilter (   $comparisonFormat,
  $fields 
)

Add field comparison expression

Parameters
string$comparisonFormat- expression for sprintf()
array$fields- list of fields
Returns
$this
Exceptions

Definition at line 2260 of file Collection.php.

2261  {
2262  if (!preg_match('/^%s( (<|>|=|<=|>=|<>) %s)*$/', $comparisonFormat)) {
2263  throw new \Exception('Invalid comparison format.');
2264  }
2265 
2266  if (!is_array($fields)) {
2267  $fields = [$fields];
2268  }
2269  foreach ($fields as $key => $field) {
2270  $fields[$key] = $this->_getMappedField($field);
2271  }
2272 
2273  $this->_priceDataFieldFilters[] = array_merge([$comparisonFormat], $fields);
2274  return $this;
2275  }
$fields
Definition: details.phtml:14

◆ addStoreFilter()

addStoreFilter (   $store = null)

Add store availability filter. Include availability product for store website.

Parameters
null | string | bool | int | Store$store
Returns
$this

Definition at line 846 of file Collection.php.

847  {
848  if ($store === null) {
849  $store = $this->getStoreId();
850  }
851  $store = $this->_storeManager->getStore($store);
852 
853  if ($store->getId() != Store::DEFAULT_STORE_ID) {
854  $this->setStoreId($store);
855  $this->_productLimitationFilters['store_id'] = $store->getId();
856  $this->_applyProductLimitations();
857  }
858 
859  return $this;
860  }

◆ addTaxPercents()

addTaxPercents ( )

Add require tax percent flag for product collection

Returns
$this

Definition at line 1609 of file Collection.php.

1610  {
1611  $this->_addTaxPercents = true;
1612  return $this;
1613  }

◆ addTierPriceData()

addTierPriceData ( )

Add tier price data to loaded items.

Returns
$this

Definition at line 2131 of file Collection.php.

2132  {
2133  if ($this->getFlag('tier_price_added')) {
2134  return $this;
2135  }
2136 
2137  $productIds = [];
2138  foreach ($this->getItems() as $item) {
2139  $productIds[] = $item->getData($this->getLinkField());
2140  }
2141  if (!$productIds) {
2142  return $this;
2143  }
2144  $select = $this->getTierPriceSelect($productIds);
2145  $this->fillTierPriceData($select);
2146 
2147  $this->setFlag('tier_price_added', true);
2148  return $this;
2149  }

◆ addTierPriceDataByGroupId()

addTierPriceDataByGroupId (   $customerGroupId)

Load collection items filtered by customer group id and add tier price data.

Parameters
int$customerGroupId
Returns
$this
Since
102.0.0

Definition at line 2158 of file Collection.php.

2159  {
2160  if ($this->getFlag('tier_price_added')) {
2161  return $this;
2162  }
2163 
2164  $productIds = [];
2165  foreach ($this->getItems() as $item) {
2166  $productIds[] = $item->getData($this->getLinkField());
2167  }
2168  if (!$productIds) {
2169  return $this;
2170  }
2171  $select = $this->getTierPriceSelect($productIds);
2172  $select->where(
2173  '(customer_group_id=? AND all_groups=0) OR all_groups=1',
2174  $customerGroupId
2175  );
2176  $this->fillTierPriceData($select);
2177 
2178  $this->setFlag('tier_price_added', true);
2179  return $this;
2180  }

◆ addUrlRewrite()

addUrlRewrite (   $categoryId = '')

Add URL rewrites data to product. If collection loadded - run processing else set flag.

Parameters
int | string$categoryId
Returns
$this

Definition at line 1377 of file Collection.php.

1378  {
1379  $this->_addUrlRewrite = true;
1380  $useCategoryUrl = $this->_scopeConfig->getValue(
1381  \Magento\Catalog\Helper\Product::XML_PATH_PRODUCT_URL_USE_CATEGORY,
1382  \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
1383  $this->getStoreId()
1384  );
1385  if ($useCategoryUrl) {
1386  $this->_urlRewriteCategory = $categoryId;
1387  } else {
1388  $this->_urlRewriteCategory = 0;
1389  }
1390 
1391  if ($this->isLoaded()) {
1392  $this->_addUrlRewrite();
1393  }
1394 
1395  return $this;
1396  }

◆ addWebsiteFilter()

addWebsiteFilter (   $websites = null)

Add website filter to collection

Parameters
null | bool | int | string | array$websites
Returns
$this

Definition at line 868 of file Collection.php.

869  {
870  if (!is_array($websites)) {
871  $websites = [$this->_storeManager->getWebsite($websites)->getId()];
872  }
873 
874  $this->_productLimitationFilters['website_ids'] = $websites;
875  $this->_applyProductLimitations();
876 
877  return $this;
878  }

◆ addWebsiteNamesToResult()

addWebsiteNamesToResult ( )

Adding product website names to result collection. Add for each product websites information.

Returns
$this

Definition at line 776 of file Collection.php.

777  {
778  $this->needToAddWebsiteNamesToResult = true;
779  return $this;
780  }

◆ applyFrontendPriceLimitations()

applyFrontendPriceLimitations ( )

Apply front-end price limitation filters to the collection

Returns
$this

Definition at line 1979 of file Collection.php.

1980  {
1981  $this->_productLimitationFilters->setUsePriceIndex(true);
1982  if (!isset($this->_productLimitationFilters['customer_group_id'])) {
1983  $customerGroupId = $this->_customerSession->getCustomerGroupId();
1984  $this->_productLimitationFilters['customer_group_id'] = $customerGroupId;
1985  }
1986  if (!isset($this->_productLimitationFilters['website_id'])) {
1987  $websiteId = $this->_storeManager->getStore($this->getStoreId())->getWebsiteId();
1988  $this->_productLimitationFilters['website_id'] = $websiteId;
1989  }
1990  $this->_applyProductLimitations();
1991  return $this;
1992  }

◆ clear()

clear ( )

Clear collection

Returns
$this

Definition at line 2377 of file Collection.php.

2378  {
2379  foreach ($this->_items as $i => $item) {
2380  if ($item->hasStockItem()) {
2381  $item->unsStockItem();
2382  }
2383  $this->_items[$i] = null;
2384  }
2385 
2386  foreach ($this->_itemsById as $i => $item) {
2387  $this->_itemsById[$i] = null;
2388  }
2389 
2390  unset($this->_items, $this->_data, $this->_itemsById);
2391  $this->_data = [];
2392  return parent::clear();
2393  }
$i
Definition: gallery.phtml:31

◆ doAddWebsiteNamesToResult()

doAddWebsiteNamesToResult ( )
protected

Processs adding product website names to result collection

Returns
$this

Definition at line 803 of file Collection.php.

804  {
805  $productWebsites = [];
806  foreach ($this as $product) {
807  $productWebsites[$product->getId()] = [];
808  }
809 
810  if (!empty($productWebsites)) {
811  $select = $this->getConnection()->select()->from(
812  ['product_website' => $this->_productWebsiteTable]
813  )->join(
814  ['website' => $this->getResource()->getTable('store_website')],
815  'website.website_id = product_website.website_id',
816  ['name']
817  )->where(
818  'product_website.product_id IN (?)',
819  array_keys($productWebsites)
820  )->where(
821  'website.website_id > ?',
822  0
823  );
824 
825  $data = $this->getConnection()->fetchAll($select);
826  foreach ($data as $row) {
827  $productWebsites[$row['product_id']][] = $row['website_id'];
828  }
829  }
830 
831  foreach ($this as $product) {
832  if (isset($productWebsites[$product->getId()])) {
833  $product->setData('websites', $productWebsites[$product->getId()]);
834  $product->setData('website_ids', $productWebsites[$product->getId()]);
835  }
836  }
837  return $this;
838  }

◆ getAdditionalPriceExpression()

getAdditionalPriceExpression (   $select)

Get additional price expression sql part

Parameters
\Magento\Framework\DB\Select$select
Returns
string

Definition at line 448 of file Collection.php.

449  {
450  if (null === $this->_additionalPriceExpression) {
452  }
454  }

◆ getAllIds()

getAllIds (   $limit = null,
  $offset = null 
)

Retrieve all ids for collection

Parameters
int | string$limit
int | string$offset
Returns
array

Definition at line 1209 of file Collection.php.

1210  {
1211  $idsSelect = $this->_getClearSelect();
1212  $idsSelect->columns('e.' . $this->getEntity()->getIdFieldName());
1213  $idsSelect->limit($limit, $offset);
1214  $idsSelect->resetJoinLeft();
1215 
1216  return $this->getConnection()->fetchCol($idsSelect, $this->_bindParams);
1217  }

◆ getAllIdsCache()

getAllIdsCache (   $resetCache = false)

Retrieve all ids

Parameters
boolean$resetCache
Returns
array

Definition at line 1472 of file Collection.php.

1473  {
1474  $ids = null;
1475  if (!$resetCache) {
1476  $ids = $this->_allIdsCache;
1477  }
1478 
1479  if ($ids === null) {
1480  $ids = $this->getAllIds();
1481  $this->setAllIdsCache($ids);
1482  }
1483 
1484  return $ids;
1485  }

◆ getAttributeValueCount()

getAttributeValueCount (   $attribute)

Retrieve product count by some value of attribute

Parameters
string$attribute
Returns
array ($value => $count)

Definition at line 1041 of file Collection.php.

1042  {
1043  $select = clone $this->getSelect();
1044  $attribute = $this->getEntity()->getAttribute($attribute);
1045  $attributeCode = $attribute->getAttributeCode();
1046  $tableAlias = $attributeCode . '_value_count';
1047 
1048  $select->reset(\Magento\Framework\DB\Select::GROUP);
1049  $condition = 'e.entity_id=' . $tableAlias . '.entity_id AND ' . $this->_getConditionSql(
1050  $tableAlias . '.attribute_id',
1051  $attribute->getId()
1052  );
1053 
1054  $select->join(
1055  [$tableAlias => $attribute->getBackend()->getTable()],
1056  $condition,
1057  [
1058  'count_' . $attributeCode => new \Zend_Db_Expr('COUNT(DISTINCT e.entity_id)'),
1059  'value_' . $attributeCode => new \Zend_Db_Expr($tableAlias . '.value')
1060  ]
1061  )->group(
1062  'value_' . $attributeCode
1063  );
1064 
1065  $data = $this->getConnection()->fetchAll($select);
1066  $res = [];
1067 
1068  foreach ($data as $row) {
1069  $res[$row['value_' . $attributeCode]] = $row['count_' . $attributeCode];
1070  }
1071  return $res;
1072  }
$attributeCode
Definition: extend.phtml:12
const GROUP
Definition: Select.php:52

◆ getAttributeValueCountByRange()

getAttributeValueCountByRange (   $attribute,
  $range 
)

Retrieve ranging product count for arrtibute range

Parameters
string$attribute
int$range
Returns
array

Definition at line 1002 of file Collection.php.

1003  {
1004  $select = clone $this->getSelect();
1005  $attribute = $this->getEntity()->getAttribute($attribute);
1006  $attributeCode = $attribute->getAttributeCode();
1007  $tableAlias = $attributeCode . '_range_count_value';
1008 
1009  $condition = 'e.entity_id = ' . $tableAlias . '.entity_id AND ' . $this->_getConditionSql(
1010  $tableAlias . '.attribute_id',
1011  $attribute->getId()
1012  );
1013 
1014  $select->reset(\Magento\Framework\DB\Select::GROUP);
1015  $select->join(
1016  [$tableAlias => $attribute->getBackend()->getTable()],
1017  $condition,
1018  [
1019  'count_' . $attributeCode => new \Zend_Db_Expr('COUNT(DISTINCT e.entity_id)'),
1020  'range_' . $attributeCode => new \Zend_Db_Expr('CEIL((' . $tableAlias . '.value+0.01)/' . $range . ')')
1021  ]
1022  )->group(
1023  'range_' . $attributeCode
1024  );
1025 
1026  $data = $this->getConnection()->fetchAll($select);
1027  $res = [];
1028 
1029  foreach ($data as $row) {
1030  $res[$row['range_' . $attributeCode]] = $row['count_' . $attributeCode];
1031  }
1032  return $res;
1033  }
$attributeCode
Definition: extend.phtml:12
const GROUP
Definition: Select.php:52

◆ getCatalogPreparedSelect()

getCatalogPreparedSelect ( )

Get cloned Select after dispatching 'catalog_prepare_price_select' event

Returns
\Magento\Framework\DB\Select

Definition at line 388 of file Collection.php.

◆ getCurrencyRate()

getCurrencyRate ( )

Get currency rate

Returns
float

Definition at line 461 of file Collection.php.

462  {
463  return $this->_storeManager->getStore($this->getStoreId())->getCurrentCurrencyRate();
464  }

◆ getEntityPkName()

getEntityPkName ( \Magento\Eav\Model\Entity\AbstractEntity  $entity)
protected
Since
101.0.0

Definition at line 1599 of file Collection.php.

1600  {
1601  return $entity->getLinkField();
1602  }
$entity
Definition: element.phtml:22

◆ getFlatState()

getFlatState ( )

Retrieve Catalog Product Flat Helper object

Returns
\Magento\Catalog\Model\Indexer\Product\Flat\State

Definition at line 471 of file Collection.php.

◆ getLimitationFilters()

getLimitationFilters ( )

Get filters applied to collection

Returns
\Magento\Catalog\Model\ResourceModel\Product\Collection\ProductLimitation

Definition at line 885 of file Collection.php.

◆ getMaxAttributeValue()

getMaxAttributeValue (   $attribute)

Retrieve max value by attribute

Parameters
string$attribute
Returns
array|null

Definition at line 967 of file Collection.php.

968  {
969  $select = clone $this->getSelect();
970  $attribute = $this->getEntity()->getAttribute($attribute);
971  $attributeCode = $attribute->getAttributeCode();
972  $tableAlias = $attributeCode . '_max_value';
973  $fieldAlias = 'max_' . $attributeCode;
974  $condition = 'e.entity_id = ' . $tableAlias . '.entity_id AND ' . $this->_getConditionSql(
975  $tableAlias . '.attribute_id',
976  $attribute->getId()
977  );
978 
979  $select->join(
980  [$tableAlias => $attribute->getBackend()->getTable()],
981  $condition,
982  [$fieldAlias => new \Zend_Db_Expr('MAX(' . $tableAlias . '.value)')]
983  )->group(
984  'e.entity_type_id'
985  );
986 
987  $data = $this->getConnection()->fetchRow($select);
988  if (isset($data[$fieldAlias])) {
989  return $data[$fieldAlias];
990  }
991 
992  return null;
993  }
$attributeCode
Definition: extend.phtml:12

◆ getMaxPrice()

getMaxPrice ( )

Get products max price

Returns
float

Definition at line 2417 of file Collection.php.

2418  {
2419  if ($this->_maxPrice === null) {
2420  $this->_prepareStatisticsData();
2421  }
2422 
2423  return $this->_maxPrice;
2424  }

◆ getMinPrice()

getMinPrice ( )

Get products min price

Returns
float

Definition at line 2431 of file Collection.php.

2432  {
2433  if ($this->_minPrice === null) {
2434  $this->_prepareStatisticsData();
2435  }
2436 
2437  return $this->_minPrice;
2438  }

◆ getNewEmptyItem()

getNewEmptyItem ( )

Get collection empty item. Redeclared for specifying id field name without getting resource model inside model.

Returns
\Magento\Framework\DataObject

Definition at line 551 of file Collection.php.

552  {
553  $object = parent::getNewEmptyItem();
554  if ($this->isEnabledFlat()) {
555  $object->setIdFieldName($this->getEntity()->getIdFieldName());
556  }
557  return $object;
558  }

◆ getPriceExpression()

getPriceExpression (   $select)

Get price expression sql part

Parameters
\Magento\Framework\DB\Select$select
Returns
string

Definition at line 435 of file Collection.php.

◆ getPricesCount()

getPricesCount ( )

Get count of product prices

Returns
int

Definition at line 2459 of file Collection.php.

2460  {
2461  if ($this->_pricesCount === null) {
2462  $this->_prepareStatisticsData();
2463  }
2464 
2465  return $this->_pricesCount;
2466  }

◆ getPriceStandardDeviation()

getPriceStandardDeviation ( )

Get standard deviation of products price

Returns
float

Definition at line 2445 of file Collection.php.

2446  {
2447  if ($this->_priceStandardDeviation === null) {
2448  $this->_prepareStatisticsData();
2449  }
2450 
2452  }

◆ getProductCountSelect()

getProductCountSelect ( )

Retrieve product count select for categories

Returns
\Magento\Framework\DB\Select

Definition at line 1224 of file Collection.php.

1225  {
1226  if ($this->_productCountSelect === null) {
1227  $this->_productCountSelect = clone $this->getSelect();
1228  $this->_productCountSelect->reset(
1229  \Magento\Framework\DB\Select::COLUMNS
1230  )->reset(
1231  \Magento\Framework\DB\Select::GROUP
1232  )->reset(
1233  \Magento\Framework\DB\Select::ORDER
1234  )->distinct(
1235  false
1236  )->join(
1237  ['count_table' => $this->tableMaintainer->getMainTable($this->getStoreId())],
1238  'count_table.product_id = e.entity_id',
1239  [
1240  'count_table.category_id',
1241  'product_count' => new \Zend_Db_Expr('COUNT(DISTINCT count_table.product_id)')
1242  ]
1243  )->where(
1244  'count_table.store_id = ?',
1245  $this->getStoreId()
1246  )->group(
1247  'count_table.category_id'
1248  );
1249  }
1250 
1252  }
const ORDER
Definition: Select.php:54
const COLUMNS
Definition: Select.php:48
const GROUP
Definition: Select.php:52

◆ getProductEntityMetadata()

getProductEntityMetadata ( )

Get product entity metadata

Returns
\Magento\Framework\EntityManager\EntityMetadataInterface
Since
102.0.0

Definition at line 2338 of file Collection.php.

2339  {
2340  return $this->metadataPool->getMetadata(ProductInterface::class);
2341  }

◆ getSelectCountSql()

getSelectCountSql ( )

Get SQL for get record count without left JOINs

Returns
\Magento\Framework\DB\Select

Definition at line 1122 of file Collection.php.

1123  {
1124  return $this->_getSelectCountSql();
1125  }
_getSelectCountSql(?Select $select=null, $resetLeftJoins=true)

◆ isEnabledFlat()

isEnabledFlat ( )

Retrieve is flat enabled. Return always false if magento run admin.

Returns
bool

Definition at line 481 of file Collection.php.

482  {
483  if (!isset($this->_flatEnabled[$this->getStoreId()])) {
484  $this->_flatEnabled[$this->getStoreId()] = $this->getFlatState()->isAvailable();
485  }
486  return $this->_flatEnabled[$this->getStoreId()];
487  }

◆ joinMinimalPrice()

joinMinimalPrice ( )

Join minimal price attribute to result

Returns
$this

Definition at line 955 of file Collection.php.

956  {
957  $this->addAttributeToSelect('price')->addAttributeToSelect('minimal_price');
958  return $this;
959  }

◆ joinUrlRewrite()

joinUrlRewrite ( )

Joins url rewrite rules to collection

Returns
$this

Definition at line 1359 of file Collection.php.

1360  {
1361  $this->joinTable(
1362  'url_rewrite',
1363  'entity_id = entity_id',
1364  ['request_path'],
1365  '{{table}}.entity_type = \'' . ProductUrlRewriteGenerator::ENTITY_TYPE . '\'',
1366  'left'
1367  );
1368  return $this;
1369  }
joinTable($table, $bind, $fields=null, $cond=null, $joinType='inner')

◆ load()

load (   $printQuery = false,
  $logQuery = false 
)

Definition at line 785 of file Collection.php.

786  {
787  if ($this->isLoaded()) {
788  return $this;
789  }
790  parent::load($printQuery, $logQuery);
791 
792  if ($this->needToAddWebsiteNamesToResult) {
793  $this->doAddWebsiteNamesToResult();
794  }
795  return $this;
796  }

◆ requireTaxPercent()

requireTaxPercent ( )

Get require tax percent flag value

Returns
bool

Definition at line 1620 of file Collection.php.

◆ setAllIdsCache()

setAllIdsCache (   $value)

Set all ids

Parameters
array$value
Returns
$this

Definition at line 1493 of file Collection.php.

1494  {
1495  $this->_allIdsCache = $value;
1496  return $this;
1497  }
$value
Definition: gender.phtml:16

◆ setEntity()

setEntity (   $entity)

Set entity to use for attributes

Parameters
\Magento\Eav\Model\Entity\AbstractEntity$entity
Returns
$this

Definition at line 566 of file Collection.php.

567  {
568  if ($this->isEnabledFlat() && $entity instanceof \Magento\Framework\Model\ResourceModel\Db\AbstractDb) {
569  $this->_entity = $entity;
570  return $this;
571  }
572  return parent::setEntity($entity);
573  }
$entity
Definition: element.phtml:22

◆ setOrder()

setOrder (   $attribute,
  $dir = Select::SQL_DESC 
)

Set Order field

Parameters
string$attribute
string$dir
Returns
$this

Definition at line 2402 of file Collection.php.

2403  {
2404  if ($attribute == 'price') {
2405  $this->addAttributeToSort($attribute, $dir);
2406  } else {
2407  parent::setOrder($attribute, $dir);
2408  }
2409  return $this;
2410  }
addAttributeToSort($attribute, $dir=self::SORT_ORDER_ASC)

◆ setStore()

setStore (   $store)

Set Store scope for collection

Parameters
mixed$store
Returns
$this

Definition at line 581 of file Collection.php.

◆ setVisibility()

setVisibility (   $visibility)

Set product visibility filter for enabled products

Parameters
array$visibility
Returns
$this

Definition at line 1678 of file Collection.php.

1679  {
1680  $this->_productLimitationFilters['visibility'] = $visibility;
1681  $this->_applyProductLimitations();
1682 
1683  return $this;
1684  }

◆ unsProductCountSelect()

unsProductCountSelect ( )

Destruct product count select

Returns
$this

Definition at line 1259 of file Collection.php.

1260  {
1261  $this->_productCountSelect = null;
1262  return $this;
1263  }

Field Documentation

◆ $_addFinalPrice

$_addFinalPrice = false
protected

Definition at line 93 of file Collection.php.

◆ $_additionalPriceExpression

$_additionalPriceExpression
protected

Definition at line 145 of file Collection.php.

◆ $_addTaxPercents

$_addTaxPercents = false
protected

Definition at line 107 of file Collection.php.

◆ $_addUrlRewrite

$_addUrlRewrite = false
protected

Definition at line 79 of file Collection.php.

◆ $_allIdsCache

$_allIdsCache = null
protected

Definition at line 100 of file Collection.php.

◆ $_catalogPreparePriceSelect

$_catalogPreparePriceSelect = null
protected

Definition at line 180 of file Collection.php.

◆ $_catalogProductFlatState

$_catalogProductFlatState = null
protected

Definition at line 187 of file Collection.php.

◆ $_catalogUrl

$_catalogUrl
protected

Definition at line 220 of file Collection.php.

◆ $_customerSession

$_customerSession
protected

Definition at line 208 of file Collection.php.

◆ $_flatEnabled

$_flatEnabled = []
protected

Definition at line 58 of file Collection.php.

◆ $_groupManagement

$_groupManagement
protected

Definition at line 244 of file Collection.php.

◆ $_idFieldName

$_idFieldName = 'entity_id'
protected

Definition at line 51 of file Collection.php.

◆ $_isWebsiteFilter

$_isWebsiteFilter = false
protected

Definition at line 124 of file Collection.php.

◆ $_localeDate

$_localeDate
protected

Definition at line 213 of file Collection.php.

◆ $_maxPrice

$_maxPrice
protected

Definition at line 152 of file Collection.php.

◆ $_minPrice

$_minPrice
protected

Definition at line 159 of file Collection.php.

◆ $_priceDataFieldFilters

$_priceDataFieldFilters = []
protected

Definition at line 131 of file Collection.php.

◆ $_priceExpression

$_priceExpression
protected

Definition at line 138 of file Collection.php.

◆ $_pricesCount

$_pricesCount = null
protected

Definition at line 173 of file Collection.php.

◆ $_priceStandardDeviation

$_priceStandardDeviation
protected

Definition at line 166 of file Collection.php.

◆ $_productCategoryTable

$_productCategoryTable
protected

Definition at line 72 of file Collection.php.

◆ $_productCountSelect

$_productCountSelect = null
protected

Definition at line 119 of file Collection.php.

◆ $_productLimitationFilters

$_productLimitationFilters
protected

Definition at line 112 of file Collection.php.

◆ $_productOptionFactory

$_productOptionFactory
protected

Definition at line 227 of file Collection.php.

◆ $_productWebsiteTable

$_productWebsiteTable
protected

Definition at line 65 of file Collection.php.

◆ $_resourceHelper

$_resourceHelper
protected

Definition at line 234 of file Collection.php.

◆ $_scopeConfig

$_scopeConfig
protected

Definition at line 201 of file Collection.php.

◆ $_urlRewriteCategory

$_urlRewriteCategory = ''
protected

Definition at line 86 of file Collection.php.

◆ $dateTime

$dateTime
protected

Definition at line 239 of file Collection.php.

◆ $moduleManager

$moduleManager = null
protected

Definition at line 194 of file Collection.php.

◆ $needToAddWebsiteNamesToResult

$needToAddWebsiteNamesToResult
protected

Definition at line 251 of file Collection.php.

◆ INDEX_TABLE_ALIAS

const INDEX_TABLE_ALIAS = 'price_index'

Alias for index table

Definition at line 41 of file Collection.php.

◆ MAIN_TABLE_ALIAS

const MAIN_TABLE_ALIAS = 'e'

Alias for main table

Definition at line 46 of file Collection.php.


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