本文整理汇总了PHP中Mage_Eav_Model_Entity_Attribute::getFlatColumns方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Eav_Model_Entity_Attribute::getFlatColumns方法的具体用法?PHP Mage_Eav_Model_Entity_Attribute::getFlatColumns怎么用?PHP Mage_Eav_Model_Entity_Attribute::getFlatColumns使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mage_Eav_Model_Entity_Attribute
的用法示例。
在下文中一共展示了Mage_Eav_Model_Entity_Attribute::getFlatColumns方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: updateAttribute
/**
* Update attribute flat data
*
* @param Mage_Eav_Model_Entity_Attribute $attribute
* @param int $storeId
* @param int|array $productIds update only product(s)
* @return Mage_Catalog_Model_Resource_Product_Flat_Indexer
*/
public function updateAttribute($attribute, $storeId, $productIds = null)
{
if (!$this->_isFlatTableExists($storeId)) {
return $this;
}
$adapter = $this->_getWriteAdapter();
$flatTableName = $this->getFlatTableName($storeId);
$describe = $adapter->describeTable($flatTableName);
if ($attribute->getBackend()->getType() == 'static') {
if (!isset($describe[$attribute->getAttributeCode()])) {
return $this;
}
$select = $adapter->select()->join(array('main_table' => $this->getTable('catalog/product')), 'main_table.entity_id = e.entity_id', array($attribute->getAttributeCode() => 'main_table.' . $attribute->getAttributeCode()));
if ($this->getFlatHelper()->isAddChildData()) {
$select->where('e.is_child = ?', 0);
}
if ($productIds !== null) {
$select->where('main_table.entity_id IN(?)', $productIds);
}
$sql = $select->crossUpdateFromSelect(array('e' => $flatTableName));
$adapter->query($sql);
} else {
$columns = $attribute->getFlatColumns();
if (!$columns) {
return $this;
}
foreach (array_keys($columns) as $columnName) {
if (!isset($describe[$columnName])) {
return $this;
}
}
$select = $attribute->getFlatUpdateSelect($storeId);
if ($select instanceof Varien_Db_Select) {
if ($productIds !== null) {
$select->where('e.entity_id IN(?)', $productIds);
}
$sql = $select->crossUpdateFromSelect(array('e' => $flatTableName));
$adapter->query($sql);
}
}
return $this;
}
示例2: _updateAttribute
/**
* add product eav Attribute to document
*
* @param int $storeId
* @param Mage_Eav_Model_Entity_Attribute $attribute
* @param array $documents
* @return array
*/
public function _updateAttribute($storeId, $attribute, $documents = null)
{
$fields = $this->getMappings($storeId);
$adapter = $this->_getReadAdapter();
if ($attribute->getBackend()->getType() == 'static') {
var_dump('not implemented yet');
return $this;
if (false === isset($describe[$attribute->getAttributeCode()])) {
return $this;
}
$select = $adapter->select()->join(array('main_table' => $this->getTable('catalog/product')), 'main_table.entity_id = e.entity_id', array($attribute->getAttributeCode() => 'main_table.' . $attribute->getAttributeCode()));
$select->where('main_table.entity_id IN(?)', array_map('intval', array_keys($documents)));
$sql = $select->crossUpdateFromSelect(array('e' => $flatTableName));
var_dump($sql);
die;
$adapter->query($sql);
} else {
//non static attributes
$columns = $attribute->getFlatColumns();
if (!$columns) {
return $this;
}
foreach (array_keys($columns) as $columnName) {
if (false === isset($fields[$columnName])) {
return $this;
}
}
$select = $attribute->getFlatUpdateSelect($storeId);
$select->from(array('e' => $this->getTable('catalog/product')), 'entity_id');
if ($select instanceof Varien_Db_Select) {
$select->where('e.entity_id IN(?)', array_map('intval', array_keys($documents)));
foreach ($adapter->query($select)->fetchAll() as $data) {
$documentId = $data['entity_id'];
//remove entity id Field
unset($data['entity_id']);
if (true === isset($documents[$documentId])) {
if (true === is_array($data) && count($data) > 0) {
foreach ($data as $field => $value) {
$documents[$documentId]->set($field, $value);
}
}
}
}
}
}
return $documents;
}