コード例 #1
0
ファイル: Category.php プロジェクト: nemphys/magento2
 /**
  * Return entities where attribute value is
  *
  * @param array|int $entityIdsFilter
  * @param Mage_Eav_Model_Entity_Attribute $attribute
  * @param mixed $expectedValue
  * @return array
  */
 public function findWhereAttributeIs($entityIdsFilter, $attribute, $expectedValue)
 {
     $bind = array('attribute_id' => $attribute->getId(), 'value' => $expectedValue);
     $select = $this->_getReadAdapter()->select()->from($attribute->getBackend()->getTable(), array('entity_id'))->where('attribute_id = :attribute_id')->where('value = :value')->where('entity_id IN(?)', $entityIdsFilter);
     return $this->_getReadAdapter()->fetchCol($select, $bind);
 }
コード例 #2
0
ファイル: Indexer.php プロジェクト: jauderho/magento-mirror
 /**
  * Update attribute flat data
  *
  * @param Mage_Eav_Model_Entity_Attribute $attribute
  * @param int $store
  * @param int|array $productIds update only product(s)
  * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Flat_Indexer
  */
 public function updateAttribute($attribute, $store, $productIds = null)
 {
     if ($attribute->getBackend()->getType() == 'static') {
         $select = $this->_getWriteAdapter()->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 (!is_null($productIds)) {
             $select->where('main_table.entity_id IN(?)', $productIds);
         }
         $sql = $select->crossUpdateFromSelect(array('e' => $this->getFlatTableName($store)));
         $this->_getWriteAdapter()->query($sql);
     } else {
         $select = $attribute->getFlatUpdateSelect($store);
         if ($select instanceof Varien_Db_Select) {
             if (!is_null($productIds)) {
                 $select->where('e.entity_id IN(?)', $productIds);
             }
             $sql = $select->crossUpdateFromSelect(array('e' => $this->getFlatTableName($store)));
             $this->_getWriteAdapter()->query($sql);
         }
     }
     return $this;
 }
コード例 #3
0
ファイル: Abstract.php プロジェクト: becchius/fiordivaniglia
 /**
  * Prepare common config values of given editable attribute
  * 
  * @param string $type Grid block type
  * @param string $code Attribute code
  * @param Mage_Eav_Model_Entity_Attribute $attribute Attribute object
  * @param array $config Field config
  * @return array
  */
 protected function _prepareEditableAttributeCommonConfig($type, $code, $attribute, $config)
 {
     if ($attribute->getBackend()->getType() == 'datetime') {
         $config['render_reload'] = true;
         $config['must_filter'] = true;
         $config['filter_type'] = 'date';
     }
     return $config;
 }
コード例 #4
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;
 }
コード例 #5
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;
 }