/** * Retrieve Select for update Flat data * * @param \Magento\Eav\Model\Entity\Attribute\AbstractAttribute $attribute * @param int $store * @param bool $hasValueField flag which require option value * @return \Magento\Framework\DB\Select */ public function getFlatUpdateSelect(\Magento\Eav\Model\Entity\Attribute\AbstractAttribute $attribute, $store, $hasValueField = true) { $adapter = $this->_getReadAdapter(); $attributeTable = $attribute->getBackend()->getTable(); $attributeCode = $attribute->getAttributeCode(); $joinConditionTemplate = "%s.entity_id = %s.entity_id" . " AND %s.entity_type_id = " . $attribute->getEntityTypeId() . " AND %s.attribute_id = " . $attribute->getId() . " AND %s.store_id = %d"; $joinCondition = sprintf($joinConditionTemplate, 'e', 't1', 't1', 't1', 't1', \Magento\Store\Model\Store::DEFAULT_STORE_ID); if ($attribute->getFlatAddChildData()) { $joinCondition .= ' AND e.child_id = t1.entity_id'; } $valueExpr = $adapter->getCheckSql('t2.value_id > 0', 't2.value', 't1.value'); /** @var $select \Magento\Framework\DB\Select */ $select = $adapter->select()->joinLeft(['t1' => $attributeTable], $joinCondition, [])->joinLeft(['t2' => $attributeTable], sprintf($joinConditionTemplate, 't1', 't2', 't2', 't2', 't2', $store), [$attributeCode => $valueExpr]); if ($attribute->getFrontend()->getInputType() != 'multiselect' && $hasValueField) { $valueIdExpr = $adapter->getCheckSql('to2.value_id > 0', 'to2.value', 'to1.value'); $select->joinLeft(['to1' => $this->getTable('eav_attribute_option_value')], "to1.option_id = {$valueExpr} AND to1.store_id = 0", [])->joinLeft(['to2' => $this->getTable('eav_attribute_option_value')], $adapter->quoteInto("to2.option_id = {$valueExpr} AND to2.store_id = ?", $store), [$attributeCode . '_value' => $valueIdExpr]); } if ($attribute->getFlatAddChildData()) { $select->where('e.is_child = 0'); } return $select; }
/** * Retrieve attribute input type * * @param AbstractAttribute $attribute * @return string */ public function getAttributeInputType($attribute) { $dataType = $attribute->getBackend()->getType(); $imputType = $attribute->getFrontend()->getInputType(); if ($imputType == 'select' || $imputType == 'multiselect') { return 'select'; } if ($imputType == 'boolean') { return 'yesno'; } if ($imputType == 'price') { return 'price'; } if ($dataType == 'int' || $dataType == 'decimal') { return 'number'; } if ($dataType == 'datetime') { return 'date'; } return 'string'; }