{ Hello Magento 2 }

解决 Magento 2 应用问题,更注重深度挖掘。(ง •̀_•́)ง

0%

getFlatColumns

After we turn on Use Flat Catalog Product, we activate the catalog_product_flat index. Run bin/magento indexer:reindex catalog_product_flat A new table catalog_product_flat_<storeId> will be created. In this table, product eav attributes which are configured as Used in Product Listing are added as columns. Let’s see how this worked.

1
2
3
4
<indexer id="catalog_product_flat" view_id="catalog_product_flat" class="Magento\Catalog\Model\Indexer\Product\Flat">
<title translate="true">Product Flat Data</title>
<description translate="true">Reorganize EAV product structure to flat structure</description>
</indexer>

Magento\Catalog\Model\Indexer\Product\Flat:executeFull > Magento\Catalog\Model\Indexer\Product\Flat\AbstractAction:_updateRelationProducts > Magento\Catalog\Helper\Product\Flat\Indexer:getFlatColumns

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
public function getFlatColumns()
{
if ($this->_columns === null) {
$this->_columns = $this->getFlatColumnsDdlDefinition();
foreach ($this->getAttributes() as $attribute) {
/** @var $attribute \Magento\Eav\Model\Entity\Attribute\AbstractAttribute */
$columns = $attribute->setFlatAddFilterableAttributes(
$this->isAddFilterableAttributes()
)->setFlatAddChildData(
$this->isAddChildData()
)->getFlatColumns();
if ($columns !== null) {
$this->_columns = array_merge($this->_columns, $columns);
}
}
}
return $this->_columns;
}

Practice Tests

What is the purpose of the getFlatColumns method in an EAV’s Source model? A. It returns a list of columns in the entity’s _text table. B. It converts option values into row values for the attribute value tables. C. It flattens an array attribute value into a JSON string. D. It returns columns that will be added to the EAV model’s flat table. Answer D