diff --git a/vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/AbstractIndexer.php b/vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/AbstractIndexer.php index 4259504b8f0f..c1525d16275d 100644 --- a/vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/AbstractIndexer.php +++ b/vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/AbstractIndexer.php @@ -6,10 +6,16 @@ namespace Magento\Catalog\Model\ResourceModel\Product\Indexer; use Magento\Catalog\Api\Data\ProductInterface; +use Magento\Eav\Model\Config; +use Magento\Framework\EntityManager\MetadataPool; +use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Indexer\Table\StrategyInterface; +use Magento\Framework\Model\ResourceModel\Db\Context; /** * Catalog Product Indexer Abstract Resource Model * + * phpcs:disable Magento2.Classes.AbstractApi * @api * * @author Magento Core Team @@ -18,8 +24,6 @@ abstract class AbstractIndexer extends \Magento\Indexer\Model\ResourceModel\AbstractResource { /** - * Eav config - * * @var \Magento\Eav\Model\Config */ protected $_eavConfig; @@ -33,18 +37,22 @@ abstract class AbstractIndexer extends \Magento\Indexer\Model\ResourceModel\Abst /** * Class constructor * - * @param \Magento\Framework\Model\ResourceModel\Db\Context $context - * @param \Magento\Framework\Indexer\Table\StrategyInterface $tableStrategy - * @param \Magento\Eav\Model\Config $eavConfig - * @param string $connectionName + * @param Context $context + * @param StrategyInterface $tableStrategy + * @param Config $eavConfig + * @param string|null $connectionName + * @param MetadataPool|null $metadataPool */ public function __construct( \Magento\Framework\Model\ResourceModel\Db\Context $context, \Magento\Framework\Indexer\Table\StrategyInterface $tableStrategy, \Magento\Eav\Model\Config $eavConfig, - $connectionName = null + $connectionName = null, + ?\Magento\Framework\EntityManager\MetadataPool $metadataPool = null ) { $this->_eavConfig = $eavConfig; + $this->metadataPool = $metadataPool ?: \Magento\Framework\App\ObjectManager::getInstance() + ->get(\Magento\Framework\EntityManager\MetadataPool::class); parent::__construct($context, $tableStrategy, $connectionName); } @@ -65,12 +73,13 @@ protected function _getAttribute($attributeCode) * If $condition is not empty apply limitation for select * * @param \Magento\Framework\DB\Select $select - * @param string $attrCode the attribute code - * @param string|\Zend_Db_Expr $entity the entity field or expression for condition - * @param string|\Zend_Db_Expr $store the store field or expression for condition - * @param \Zend_Db_Expr $condition the limitation condition - * @param bool $required if required or has condition used INNER join, else - LEFT - * @return \Zend_Db_Expr the attribute value expression + * @param string $attrCode the attribute code + * @param string|\Zend_Db_Expr $entity the entity field or expression for condition + * @param string|\Zend_Db_Expr $store the store field or expression for condition + * @param \Zend_Db_Expr $condition the limitation condition + * @param bool $required if required or has condition used INNER join, else - LEFT + * @return \Zend_Db_Expr the attribute value expression + * @throws LocalizedException */ protected function _addAttributeToSelect($select, $attrCode, $entity, $store, $condition = null, $required = false) { @@ -158,6 +167,7 @@ protected function _addWebsiteJoinToSelect($select, $store = true, $joinConditio /** * Add join for catalog/product_website table + * * Joined table has alias pw * * @param \Magento\Framework\DB\Select $select the select object @@ -234,15 +244,13 @@ public function getRelationsByParent($parentIds) } /** + * Returns table metadata entity + * * @return \Magento\Framework\EntityManager\MetadataPool * @since 101.0.0 */ protected function getMetadataPool() { - if (null === $this->metadataPool) { - $this->metadataPool = \Magento\Framework\App\ObjectManager::getInstance() - ->get(\Magento\Framework\EntityManager\MetadataPool::class); - } return $this->metadataPool; } } diff --git a/vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/Eav/AbstractEav.php b/vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/Eav/AbstractEav.php index e024f0d30f1d..5486d4ad8d29 100644 --- a/vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/Eav/AbstractEav.php +++ b/vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/Eav/AbstractEav.php @@ -29,16 +29,18 @@ abstract class AbstractEav extends \Magento\Catalog\Model\ResourceModel\Product\ * @param \Magento\Eav\Model\Config $eavConfig * @param \Magento\Framework\Event\ManagerInterface $eventManager * @param string $connectionName + * @param \Magento\Framework\EntityManager\MetadataPool|null $metadataPool */ public function __construct( \Magento\Framework\Model\ResourceModel\Db\Context $context, \Magento\Framework\Indexer\Table\StrategyInterface $tableStrategy, \Magento\Eav\Model\Config $eavConfig, \Magento\Framework\Event\ManagerInterface $eventManager, - $connectionName = null + $connectionName = null, + ?\Magento\Framework\EntityManager\MetadataPool $metadataPool = null ) { $this->_eventManager = $eventManager; - parent::__construct($context, $tableStrategy, $eavConfig, $connectionName); + parent::__construct($context, $tableStrategy, $eavConfig, $connectionName, $metadataPool); } /** @@ -112,8 +114,8 @@ public function reindexAttribute($attributeId, $isIndexable = true) /** * Prepare data index for indexable attributes * - * @param array $entityIds the entity ids limitation - * @param int $attributeId the attribute id limitation + * @param array $entityIds the entity ids limitation + * @param int $attributeId the attribute id limitation * @return $this */ abstract protected function _prepareIndex($entityIds = null, $attributeId = null); diff --git a/vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/Eav/Source.php b/vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/Eav/Source.php index b32c34678fe2..98ccb4f544ca 100644 --- a/vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/Eav/Source.php +++ b/vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/Eav/Source.php @@ -8,8 +8,16 @@ use Magento\Catalog\Model\Product\Attribute\Source\Status as ProductStatus; use Magento\Catalog\Api\Data\ProductInterface; use Magento\Catalog\Api\Data\ProductAttributeInterface; +use Magento\Catalog\Model\ResourceModel\Helper; +use Magento\Eav\Api\AttributeRepositoryInterface; +use Magento\Eav\Model\Config; +use Magento\Framework\Api\SearchCriteriaBuilder; use Magento\Framework\DB\Select; use Magento\Framework\DB\Sql\UnionExpression; +use Magento\Framework\EntityManager\MetadataPool; +use Magento\Framework\Event\ManagerInterface; +use Magento\Framework\Indexer\Table\StrategyInterface; +use Magento\Framework\Model\ResourceModel\Db\Context; /** * Catalog Product Eav Select and Multiply Select Attributes Indexer resource model @@ -40,14 +48,15 @@ class Source extends AbstractEav /** * Construct * - * @param \Magento\Framework\Model\ResourceModel\Db\Context $context - * @param \Magento\Framework\Indexer\Table\StrategyInterface $tableStrategy - * @param \Magento\Eav\Model\Config $eavConfig - * @param \Magento\Framework\Event\ManagerInterface $eventManager - * @param \Magento\Catalog\Model\ResourceModel\Helper $resourceHelper + * @param Context $context + * @param StrategyInterface $tableStrategy + * @param Config $eavConfig + * @param ManagerInterface $eventManager + * @param Helper $resourceHelper * @param null|string $connectionName - * @param \Magento\Eav\Api\AttributeRepositoryInterface|null $attributeRepository - * @param \Magento\Framework\Api\SearchCriteriaBuilder|null $criteriaBuilder + * @param AttributeRepositoryInterface|null $attributeRepository + * @param SearchCriteriaBuilder|null $criteriaBuilder + * @param MetadataPool|null $metadataPool */ public function __construct( \Magento\Framework\Model\ResourceModel\Db\Context $context, @@ -55,16 +64,18 @@ public function __construct( \Magento\Eav\Model\Config $eavConfig, \Magento\Framework\Event\ManagerInterface $eventManager, \Magento\Catalog\Model\ResourceModel\Helper $resourceHelper, - $connectionName = null, + ?string $connectionName = null, \Magento\Eav\Api\AttributeRepositoryInterface $attributeRepository = null, - \Magento\Framework\Api\SearchCriteriaBuilder $criteriaBuilder = null + \Magento\Framework\Api\SearchCriteriaBuilder $criteriaBuilder = null, + ?\Magento\Framework\EntityManager\MetadataPool $metadataPool = null ) { parent::__construct( $context, $tableStrategy, $eavConfig, $eventManager, - $connectionName + $connectionName, + $metadataPool ); $this->_resourceHelper = $resourceHelper; $this->attributeRepository = $attributeRepository @@ -75,6 +86,19 @@ public function __construct( ->get(\Magento\Framework\Api\SearchCriteriaBuilder::class); } + /** + * @inheritDoc + */ + public function reindexEntities($processIds) + { + $this->clearTemporaryIndexTable(); + + $this->_prepareIndex($processIds); + $this->_prepareRelationIndex($processIds); + + return $this; + } + /** * Initialize connection and define main index table * @@ -135,6 +159,7 @@ protected function _prepareIndex($entityIds = null, $attributeId = null) * @param int $attributeId the attribute id limitation * @return $this * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + * @throws \Exception */ protected function _prepareSelectIndex($entityIds = null, $attributeId = null) { @@ -149,7 +174,7 @@ protected function _prepareSelectIndex($entityIds = null, $attributeId = null) $attrIdsFlat = implode(',', array_map('intval', $attrIds)); $ifNullSql = $connection->getIfNullSql('pis.value', 'COALESCE(ds.value, dd.value)'); - /**@var $select \Magento\Framework\DB\Select*/ + /**@var $select Select */ $select = $connection->select()->distinct(true)->from( ['s' => $this->getTable('store')], [] @@ -204,6 +229,17 @@ protected function _prepareSelectIndex($entityIds = null, $attributeId = null) 'cpe.entity_id AS source_id', ] ); + $visibilityCondition = $connection->quoteInto( + '>?', + \Magento\Catalog\Model\Product\Visibility::VISIBILITY_NOT_VISIBLE + ); + $this->_addAttributeToSelect( + $select, + 'visibility', + "cpe.{$productIdField}", + 's.store_id', + $visibilityCondition + ); if ($entityIds !== null) { $ids = implode(',', array_map('intval', $entityIds)); @@ -239,6 +275,14 @@ protected function _prepareSelectIndex($entityIds = null, $attributeId = null) ->where('wd.store_id != 0') ->where("cpe.entity_id IN({$ids})"); $select->where("cpe.entity_id IN({$ids})"); + $this->_addAttributeToSelect( + $selectWithoutDefaultStore, + 'visibility', + "cpe.{$productIdField}", + 'wd.store_id', + $visibilityCondition + ); + $selects = new UnionExpression( [$select, $selectWithoutDefaultStore], Select::SQL_UNION, @@ -272,6 +316,7 @@ protected function _prepareSelectIndex($entityIds = null, $attributeId = null) * @param array $entityIds the entity ids limitation * @param int $attributeId the attribute id limitation * @return $this + * @throws \Exception */ protected function _prepareMultiselectIndex($entityIds = null, $attributeId = null) { @@ -358,6 +403,13 @@ protected function _prepareMultiselectIndex($entityIds = null, $attributeId = nu ] ); + $this->_addAttributeToSelect( + $select, + 'visibility', + "cpe.{$productIdField}", + 'cs.store_id', + $connection->quoteInto('>?', \Magento\Catalog\Model\Product\Visibility::VISIBILITY_NOT_VISIBLE) + ); $this->saveDataFromSelect($select, $options); return $this; @@ -431,11 +483,11 @@ public function getIdxTable($table = null) /** * Save data from select * - * @param \Magento\Framework\DB\Select $select + * @param Select $select * @param array $options * @return void */ - private function saveDataFromSelect(\Magento\Framework\DB\Select $select, array $options) + private function saveDataFromSelect(Select $select, array $options) { $i = 0; $data = [];