コード例 #1
0
 /**
  * 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
0
 /**
  * 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;
 }