/** * @param \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute * @param \Magento\Catalog\Model\ResourceModel\Product\Collection $collection * @return $this */ protected function addGlobalAttribute(\Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute, \Magento\Catalog\Model\ResourceModel\Product\Collection $collection) { $storeId = $this->storeManager->getStore()->getId(); switch ($attribute->getBackendType()) { case 'decimal': case 'datetime': case 'int': $alias = 'at_' . $attribute->getAttributeCode(); $collection->addAttributeToSelect($attribute->getAttributeCode(), 'inner'); break; default: $alias = 'at_' . md5($this->getId()) . $attribute->getAttributeCode(); $collection->getSelect()->join([$alias => $collection->getTable('catalog_product_index_eav')], "({$alias}.entity_id = e.entity_id) AND ({$alias}.store_id = {$storeId})" . " AND ({$alias}.attribute_id = {$attribute->getId()})", []); } $this->joinedAttributes[$attribute->getAttributeCode()] = $alias . '.value'; return $this; }
/** * @param ProductCollection $productCollection * @param integer $parentId * @return void */ protected function addFilterByParent(ProductCollection $productCollection, $parentId) { $tableProductRelation = $productCollection->getTable('catalog_product_relation'); $productCollection->getSelect()->join(['pr' => $tableProductRelation], 'e.entity_id = pr.child_id')->where('pr.parent_id = ?', $parentId); }