/**
  * Gets attribute options from database
  *
  * @param \Mage_Eav_Model_Entity_Attribute $attribute
  *
  * @return array
  */
 protected function getOptions($attribute)
 {
     $select = $this->readConnection->select()->from(array('o' => \Mage::getSingleton('core/resource')->getTableName('eav_attribute_option')))->join(array('ov' => \Mage::getSingleton('core/resource')->getTableName('eav_attribute_option_value')), 'o.option_id = ov.option_id')->where('o.attribute_id = ?', $attribute->getId())->where('ov.store_id = 0')->order('ov.option_id');
     $query = $select->query();
     $values = array();
     foreach ($query->fetchAll() as $row) {
         $values[] = $row['value'];
     }
     return array('values' => $values);
 }
 /**
  * @param $data
  */
 protected function _processTemplates(&$data)
 {
     $config = $this->_adapter->getConfig();
     $select = $this->_adapter->select();
     $select->from('information_schema.tables', 'AUTO_INCREMENT')->where('table_schema = ?', $config['dbname'])->where('table_name = ?', $this->_adapter->getTableName('customer_entity'));
     $nextId = $this->_adapter->fetchOne($select);
     foreach ($data['account'] as &$field) {
         $field = str_replace('{id}', $nextId, $field);
     }
     foreach ($data['address'] as &$address) {
         foreach ($address as &$field) {
             $field = str_replace('{id}', $nextId, $field);
         }
     }
 }
Exemple #3
0
 /**
  * @dataProvider insertDataProvider
  */
 public function testInsertForce($data)
 {
     $this->assertEquals(1, $this->_connection->insertForce($this->_tableName, $data));
     $select = $this->_connection->select()->from($this->_tableName);
     $result = $this->_connection->fetchRow($select);
     $this->assertEquals($data, $result);
 }
 /**
  * Copy data from temporary to main redirects table
  *
  * @return void
  */
 protected function _copyRedirectsToMainTable()
 {
     $select = $this->_connection->select();
     $select->from(array('t' => self::TMP_TABLE_NAME), array('*'));
     $query = $select->insertFromSelect($this->_resource->getTableName('enterprise_urlrewrite/redirect'), array('identifier', 'target_path', 'store_id', 'category_id', 'product_id'), Varien_Db_Adapter_Interface::INSERT_ON_DUPLICATE);
     $this->_connection->query($query);
 }
 /**
  * Prepare data for group website relation
  */
 protected function _prepareGroupWebsite($timestamp)
 {
     $this->_connection->delete($this->_resource->getTable('catalogrule/rule_group_website'), array());
     $select = $this->_connection->select()->distinct(true)->from($this->_resource->getTable('catalogrule/rule_product'), array('rule_id', 'customer_group_id', 'website_id'))->where(new Zend_Db_Expr("{$timestamp} >= from_time"))->where($this->_connection->getCheckSql(new Zend_Db_Expr('to_time = 0'), new Zend_Db_Expr(1), new Zend_Db_Expr("{$timestamp} <= to_time")));
     $query = $select->insertFromSelect($this->_resource->getTable('catalogrule/rule_group_website'));
     $this->_connection->query($query);
 }
 /**
  * Get trigger action body for event
  *
  * @param int $entityEventId
  * @return string
  */
 public function getTriggerBody($entityEventId)
 {
     $select = $this->_connection->select()->reset()->from(array(), array('status' => new Zend_Db_Expr('?')))->joinInner(array('me' => $this->_resource->getTableName('enterprise_mview/metadata_event')), new Zend_Db_Expr('mm.metadata_id = me.metadata_id'), array())->where('mview_event_id = ?', $entityEventId);
     $update = $this->_connection->updateFromSelect($select, array('mm' => $this->_resource->getTableName('enterprise_mview/metadata')));
     $update = $this->_connection->quoteInto($update, Enterprise_Mview_Model_Metadata::STATUS_INVALID, null, 1);
     return $update . ';';
 }
 /**
  * Retrieve attribute codes using for flat
  *
  * @return array
  */
 public function getAttributeCodes()
 {
     if ($this->_attributeCodes === null) {
         $this->_attributeCodes = array();
         $systemAttributes = array();
         $attributeNodes = Mage::getConfig()->getNode(self::XML_NODE_ATTRIBUTE_NODES)->children();
         foreach ($attributeNodes as $node) {
             $attributes = Mage::getConfig()->getNode((string) $node)->asArray();
             $attributes = array_keys($attributes);
             $systemAttributes = array_unique(array_merge($attributes, $systemAttributes));
         }
         $bind = array('backend_type' => Mage_Eav_Model_Entity_Attribute_Abstract::TYPE_STATIC, 'entity_type_id' => $this->getEntityTypeId());
         $select = $this->_connection->select()->from(array('main_table' => $this->getTable('eav/attribute')))->join(array('additional_table' => $this->getTable('catalog/eav_attribute')), 'additional_table.attribute_id = main_table.attribute_id')->where('main_table.entity_type_id = :entity_type_id');
         $whereCondition = array('main_table.backend_type = :backend_type', $this->_connection->quoteInto('additional_table.is_used_for_promo_rules = ?', 1), $this->_connection->quoteInto('additional_table.used_in_product_listing = ?', 1), $this->_connection->quoteInto('additional_table.used_for_sort_by = ?', 1), $this->_connection->quoteInto('main_table.attribute_code IN(?)', $systemAttributes));
         if ($this->getFlatHelper()->isAddFilterableAttributes()) {
             $whereCondition[] = $this->_connection->quoteInto('additional_table.is_filterable > ?', 0);
         }
         $select->where(implode(' OR ', $whereCondition));
         $attributesData = $this->_connection->fetchAll($select, $bind);
         Mage::getSingleton('eav/config')->importAttributesData($this->getEntityType(), $attributesData);
         foreach ($attributesData as $data) {
             $this->_attributeCodes[$data['attribute_id']] = $data['attribute_code'];
         }
         unset($attributesData);
     }
     return $this->_attributeCodes;
 }
 /**
  * Get current DB version
  *
  * @return int
  */
 protected function _getCurrentVersionId()
 {
     if (empty($this->_currentVersionId)) {
         // zend select query permanently requires FROM statement, so executing raw query
         $this->_currentVersionId = $this->_connection->query($this->_connection->select()->from($this->_metadata->getChangelogName(), array())->columns(array('max' => 'MAX(version_id)')))->fetchColumn();
     }
     return $this->_currentVersionId;
 }
 /**
  * @param Mage_Customer_Model_Customer $customer
  */
 protected function _moveAttributesData($customer)
 {
     $attributes = array('po_limit' => $this->_poLimitId, 'po_credit' => $this->_poCreditId);
     foreach ($attributes as $attributeCode => $attributeId) {
         try {
             $select = $this->_db->select()->from($customer->getResource()->getTable('customer_entity_int'), array('value'))->where('attribute_id = ?', $attributeId)->where('entity_id = ?', $customer->getId());
             $value = $this->_db->fetchOne($select);
             if ((int) $value > 0) {
                 $this->_db->insert($customer->getResource()->getTable('customer_entity_decimal'), array('entity_type_id' => $customer->getEntityTypeId(), 'attribute_id' => $attributeId, 'entity_id' => $customer->getId(), 'value' => (int) $value));
             }
         } catch (Exception $e) {
         }
         try {
             $this->_db->delete($customer->getResource()->getTable('customer_entity_int'), 'entity_type_id = ' . $customer->getEntityTypeId() . ' AND attribute_id = ' . $attributeId . ' AND ' . 'entity_id = ' . $customer->getId());
         } catch (Exception $e) {
         }
     }
 }
 /**
  * Returns last version_id from changelog table
  *
  * @return int
  */
 protected function _selectLastVersionId()
 {
     $changelogName = $this->_metadata->getChangelogName();
     if (empty($changelogName)) {
         return 0;
     }
     $select = $this->_connection->select()->from(array('changelog' => $changelogName), array('version_id'))->order('version_id DESC')->limit(1);
     return (int) $this->_connection->fetchOne($select);
 }
 /**
  * Add products to changelog by conditions
  *
  * @param int $storeId
  * @param string $attrCode
  * @param Zend_Db_Expr $attrConditionValue
  */
 protected function _refreshSpecialPriceByStore($storeId, $attrCode, $attrConditionValue)
 {
     $attribute = Mage::getSingleton('eav/config')->getAttribute(Mage_Catalog_Model_Product::ENTITY, $attrCode);
     $attributeId = $attribute->getAttributeId();
     $select = $this->_connection->select()->from($this->_getTable(array('catalog/product', 'datetime')), array('entity_id'))->where('attribute_id = ?', $attributeId)->where('store_id = ?', $storeId)->where('value = ?', $attrConditionValue);
     $client = $this->_getClient(Mage::helper('enterprise_index')->getIndexerConfigValue('catalog_product_price', 'index_table'));
     $query = $select->insertFromSelect($client->getMetadata()->changelog_name, array('entity_id'), false);
     $this->_connection->query($query);
 }
Exemple #12
0
 /**
  * Assert that session data writes to DB in base64 encoding
  */
 public function testWriteEncoded()
 {
     $data = serialize($this->_sessionData[self::SESSION_NEW]);
     $this->_model->write(self::SESSION_ID, $data);
     $select = $this->_connection->select()->from($this->_sessionTable)->where(self::COLUMN_SESSION_ID . ' = :' . self::COLUMN_SESSION_ID);
     $bind = array(self::COLUMN_SESSION_ID => self::SESSION_ID);
     $session = $this->_connection->fetchRow($select, $bind);
     $this->assertEquals(self::SESSION_ID, $session[self::COLUMN_SESSION_ID]);
     $this->assertTrue(ctype_digit((string) $session[self::COLUMN_SESSION_EXPIRES]), 'Value of session expire field must have integer type');
     $this->assertEquals($data, base64_decode($session[self::COLUMN_SESSION_DATA]));
 }
 /**
  * Removes redirect rows which have no corresponding records in redirect table from index.
  *
  * @return Enterprise_UrlRewrite_Model_Index_Action_Url_Rewrite_Redirect_Refresh_Orphan
  * @throws Enterprise_Index_Model_Action_Exception
  */
 public function execute()
 {
     try {
         $select = $this->_connection->select()->from(array('ur' => $this->_getTable('enterprise_urlrewrite/url_rewrite')), '*')->joinInner(array('rr' => $this->_getTable('enterprise_urlrewrite/redirect_rewrite')), 'ur.url_rewrite_id = rr.url_rewrite_id')->joinLeft(array('redirect' => $this->_getTable('enterprise_urlrewrite/redirect')), 'redirect.redirect_id = rr.redirect_id')->where('ur.entity_type = ?', Enterprise_UrlRewrite_Model_Redirect::URL_REWRITE_ENTITY_TYPE)->where('redirect.redirect_id IS NULL');
         $this->_connection->query($this->_connection->deleteFromSelect($select, 'ur'));
     } catch (Exception $e) {
         $this->_metadata->setInvalidStatus()->save();
         throw new Enterprise_Index_Model_Action_Exception($e->getMessage(), $e->getCode(), $e);
     }
     return $this;
 }
 /**
  * Return last version ID
  *
  * @return string
  */
 protected function _getLastVersionId()
 {
     $changelogName = $this->_metadata->getChangelogName();
     if (empty($changelogName)) {
         return 0;
     }
     if (!$this->_lastVersionId) {
         $select = $this->_connection->select()->from($changelogName, array('version_id'))->order('version_id DESC')->limit(1);
         $this->_lastVersionId = (int) $this->_connection->fetchOne($select);
     }
     return $this->_lastVersionId;
 }
 /**
  * Get select for all products
  *
  * @param $store
  * @return Varien_Db_Select
  */
 protected function _getAllProducts(Mage_Core_Model_Store $store)
 {
     if (!isset($this->_allProductsSelect[$store->getId()])) {
         /** @var $eavConfig Mage_Eav_Model_Config */
         $eavConfig = $this->_factory->getSingleton('eav/config');
         $statusAttributeId = $eavConfig->getAttribute(Mage_Catalog_Model_Product::ENTITY, 'status')->getId();
         $visibilityAttributeId = $eavConfig->getAttribute(Mage_Catalog_Model_Product::ENTITY, 'visibility')->getId();
         $select = $this->_connection->select()->from(array('cp' => $this->_getTable('catalog/product')), array())->joinInner(array('cpw' => $this->_getTable('catalog/product_website')), 'cpw.product_id = cp.entity_id', array())->joinInner(array('cpsd' => $this->_getTable(array('catalog/product', 'int'))), 'cpsd.entity_id = cp.entity_id AND cpsd.store_id = 0 AND cpsd.attribute_id = ' . $statusAttributeId, array())->joinLeft(array('cpss' => $this->_getTable(array('catalog/product', 'int'))), 'cpss.entity_id = cp.entity_id AND cpss.attribute_id = cpsd.attribute_id' . ' AND cpss.store_id = ' . $store->getId(), array())->joinInner(array('cpvd' => $this->_getTable(array('catalog/product', 'int'))), 'cpvd.entity_id = cp.entity_id AND cpvd.store_id = 0' . ' AND cpvd.attribute_id = ' . $visibilityAttributeId, array())->joinLeft(array('cpvs' => $this->_getTable(array('catalog/product', 'int'))), 'cpvs.entity_id = cp.entity_id AND cpvs.attribute_id = cpvd.attribute_id ' . 'AND cpvs.store_id = ' . $store->getId(), array())->joinLeft(array('ccp' => $this->_getTable('catalog/category_product')), 'ccp.product_id = cp.entity_id', array())->where('cpw.website_id = ?', $store->getWebsiteId())->where($this->_connection->getIfNullSql('cpss.value', 'cpsd.value') . ' = ?', Mage_Catalog_Model_Product_Status::STATUS_ENABLED)->where($this->_connection->getIfNullSql('cpvs.value', 'cpvd.value') . ' IN (?)', array(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH, Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG, Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_SEARCH))->group('cp.entity_id')->columns(array('category_id' => new Zend_Db_Expr($store->getRootCategoryId()), 'product_id' => 'cp.entity_id', 'position' => new Zend_Db_Expr($this->_connection->getCheckSql('ccp.product_id IS NOT NULL', 'ccp.position', '0')), 'is_parent' => new Zend_Db_Expr($this->_connection->getCheckSql('ccp.product_id IS NOT NULL', '0', '1')), 'store_id' => new Zend_Db_Expr($store->getId()), 'visibility' => new Zend_Db_Expr($this->_connection->getIfNullSql('cpvs.value', 'cpvd.value'))));
         $this->_allProductsSelect[$store->getId()] = $select;
     }
     return $this->_allProductsSelect[$store->getId()];
 }
Exemple #16
0
 /**
  * Update session
  *
  * @param string $sessId
  * @param string $sessData
  * @return boolean
  */
 public function write($sessId, $sessData)
 {
     $bindValues = array('session_id' => $sessId);
     $select = $this->_write->select()->from($this->_sessionTable)->where('session_id = :session_id');
     $exists = $this->_read->fetchOne($select, $bindValues);
     $bind = array('session_expires' => time(), 'session_data' => $sessData);
     if ($exists) {
         $this->_write->update($this->_sessionTable, $bind, array('session_id=?' => $sessId));
     } else {
         $bind['session_id'] = $sessId;
         $this->_write->insert($this->_sessionTable, $bind);
     }
     return true;
 }
Exemple #17
0
 /**
  * Update session
  *
  * @param string $sessionId
  * @param string $sessionData
  * @return boolean
  */
 public function write($sessionId, $sessionData)
 {
     // need to use write connection to get the most fresh DB sessions
     $bindValues = array('session_id' => $sessionId);
     $select = $this->_write->select()->from($this->_sessionTable)->where('session_id = :session_id');
     $exists = $this->_write->fetchOne($select, $bindValues);
     // encode session serialized data to prevent insertion of incorrect symbols
     $sessionData = base64_encode($sessionData);
     $bind = array('session_expires' => time(), 'session_data' => $sessionData);
     if ($exists) {
         $this->_write->update($this->_sessionTable, $bind, array('session_id=?' => $sessionId));
     } else {
         $bind['session_id'] = $sessionId;
         $this->_write->insert($this->_sessionTable, $bind);
     }
     return true;
 }
 /**
  * Generate unique url key if current url key already occupied
  *
  * @param Mage_Catalog_Model_Abstract $object
  * @return Mage_Catalog_Model_Abstract
  */
 protected function _generateNextUrlKeySuffix(Mage_Catalog_Model_Abstract $object)
 {
     $prefixValue = $object->getData($this->getAttribute()->getAttributeCode());
     $requestPathField = new Zend_Db_Expr($this->_connection->quoteIdentifier('value'));
     //select increment part of request path and cast expression to integer
     $urlIncrementPartExpression = $this->_eavHelper->getCastToIntExpression($this->_connection->getSubstringSql($requestPathField, strlen($prefixValue) + 1, $this->_connection->getLengthSql($requestPathField) . ' - ' . strlen($prefixValue)));
     $prefixRegexp = preg_quote($prefixValue);
     $orCondition = $this->_connection->select()->orWhere($this->_connection->prepareSqlCondition('value', array('regexp' => '^' . $prefixRegexp . '$')))->orWhere($this->_connection->prepareSqlCondition('value', array('regexp' => '^' . $prefixRegexp . '-[0-9]*$')))->getPart(Zend_Db_Select::WHERE);
     $select = $this->_connection->select();
     $select->from($this->getAttribute()->getBackendTable(), new Zend_Db_Expr('MAX(ABS(' . $urlIncrementPartExpression . '))'))->where('value LIKE :url_key')->where('entity_id <> :entity_id')->where(implode('', $orCondition));
     $bind = array('url_key' => $prefixValue . '%', 'entity_id' => (int) $object->getId());
     $suffix = $this->_connection->fetchOne($select, $bind);
     if (!is_null($suffix)) {
         $suffix = (int) $suffix;
         $object->setData($this->getAttribute()->getAttributeCode(), sprintf('%s-%s', $prefixValue, ++$suffix));
     }
     return $object;
 }
 /**
  * Create view and mview table
  * 1) Create view;
  * 2) Create table;
  * 3) Update view name and status in metadata.
  *
  * @return Enterprise_Mview_Model_Action_Mview_Create
  * @throws Exception
  */
 public function execute()
 {
     try {
         if (!$this->_view->isExists()) {
             $this->_view->createFromSource($this->_select);
         }
         if (!$this->_table->isExists()) {
             $select = $this->_connection->select()->from($this->_view->getObjectName());
             $this->_table->createFromSource($select);
         }
         $this->_metadata->setViewName($this->_view->getObjectName());
         $this->_metadata->setValidStatus();
         $this->_metadata->save();
     } catch (Exception $e) {
         $this->_view->drop();
         $this->_table->drop();
         throw $e;
     }
     return $this;
 }
 protected function _processTemplates(&$data)
 {
     $config = $this->_adapter->getConfig();
     $select = $this->_adapter->select();
     $magentoVersion = Mage::getVersion();
     //vietdq fix checkout 1.5
     if (version_compare($magentoVersion, '1.5', '>=') && version_compare($magentoVersion, '1.6', '<')) {
         $tableName = Mage::getSingleton('core/resource')->getTableName('customer_entity');
     } else {
         $tableName = $this->_adapter->getTableName('customer_entity');
     }
     $select->from('information_schema.tables', 'AUTO_INCREMENT')->where('table_schema = ?', $config['dbname'])->where('table_name = ?', $tableName);
     $nextId = $this->_adapter->fetchOne($select);
     foreach ($data['account'] as &$field) {
         $field = str_replace('{id}', $nextId, $field);
     }
     foreach ($data['address'] as &$address) {
         foreach ($address as &$field) {
             $field = str_replace('{id}', $nextId, $field);
         }
     }
 }
Exemple #21
0
 /**
  * Prepare and return select
  *
  * @param array $productIds
  * @param int $categoryId
  * @param int $storeId
  * @return Varien_Db_Select
  */
 public function getTableSelect(array $productIds, $categoryId, $storeId)
 {
     $select = $this->_connection->select()->from($this->_resource->getTableName('core/url_rewrite'), array('product_id', 'request_path'))->where('store_id = ?', (int) $storeId)->where('is_system = ?', 1)->where('category_id = ? OR category_id IS NULL', (int) $categoryId)->where('product_id IN(?)', $productIds)->order('category_id ' . Varien_Data_Collection::SORT_ORDER_DESC);
     return $select;
 }
 /**
  * Returns select sql
  *
  * @return Varien_Db_Select
  */
 protected function _getSelectSql()
 {
     return $this->_connection->select()->from($this->_metadata->getViewName())->where($this->_metadata->getKeyColumn() . ' = ?', $this->_keyColumnIdValue);
 }
 /**
  * Prepare and return select
  *
  * @param array $productIds
  * @param int $categoryId
  * @param int $storeId
  * @return Varien_Db_Select
  */
 public function getTableSelect(array $productIds, $categoryId, $storeId)
 {
     $requestPath = $this->_connection->getIfNullSql('url_rewrite.request_path', 'default_ur.request_path');
     return $this->_connection->select()->from(array('e' => $this->_resource->getTableName('catalog/product')), array('product_id' => 'entity_id'))->where('e.entity_id IN(?)', $productIds)->joinLeft(array('url_rewrite_product' => $this->_resource->getTableName('enterprise_catalog/product')), 'url_rewrite_product.product_id = e.entity_id and url_rewrite_product.store_id = ' . (int) $storeId, array(''))->joinLeft(array('url_rewrite' => $this->_resource->getTableName('enterprise_urlrewrite/url_rewrite')), 'url_rewrite_product.url_rewrite_id = url_rewrite.url_rewrite_id AND url_rewrite.is_system = 1', array(''))->joinLeft(array('default_urp' => $this->_resource->getTableName('enterprise_catalog/product')), 'default_urp.product_id = e.entity_id AND default_urp.store_id = 0', array(''))->joinLeft(array('default_ur' => $this->_resource->getTableName('enterprise_urlrewrite/url_rewrite')), 'default_ur.url_rewrite_id = default_urp.url_rewrite_id', array('request_path' => $requestPath));
 }
Exemple #24
0
 /**
  * Constructs the query returning purchasable products
  *
  * @param Varien_Db_Adapter_Interface $dbRead               Read connection
  * @param Varien_Data_Collection_Db   $productCollection    Products
  * @param Varien_Db_Select            $productToParentQuery Parent resolution
  * @param Varien_Data_Collection_Db   $parentCollection     Parents
  * @param array                       $purchasableFilter    Visibility filter
  * @param bool                        $resetColumns         Flat product fix
  *
  * @return Varien_Db_Select
  */
 private function _purchasableQueryHelper($dbRead, $productCollection, $productToParentQuery, $parentCollection, $purchasableFilter, $resetColumns)
 {
     $productQuery = $productCollection->getSelect();
     if ($resetColumns) {
         $productQuery->reset(Zend_Db_Select::COLUMNS)->columns(array('e.entity_id', 'e.sku', 'e.attribute_set_id', 'e.type_id'));
     }
     $query = $dbRead->select();
     $query->from(array('product' => new Zend_Db_Expr("({$productQuery})")), array('entity_id', 'sku'))->joinLeft(array('product_to_parent' => new Zend_Db_Expr("({$productToParentQuery})")), 'product_to_parent.product_id = product.entity_id', array())->joinLeft(array('parent' => new Zend_Db_Expr("({$parentCollection->getSelect()})")), $dbRead->quoteInto('parent.entity_id = product_to_parent.parent_id ' . 'AND parent.type_id = ?', Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE), array())->where('parent.status IS NULL OR parent.status = ?', Mage_Catalog_Model_Product_Status::STATUS_ENABLED);
     return $query;
 }
 /**
  * Create a select query for the supplied database adapter.
  *
  * @param \Varien_Db_Adapter_Interface $db
  * @return \Varien_Db_Select
  */
 protected function createSelect(\Varien_Db_Adapter_Interface $db)
 {
     return $db->select()->from(array('c' => 'core_config_data'), array('url' => 'DISTINCT(c.value)'))->where('c.path IN(?)', array('web/unsecure/base_url', 'web/secure/base_url'));
 }
Exemple #26
0
 /**
  * Get downloadable link final price select
  * 
  * @param Varien_Db_Adapter_Interface $write
  * @param string $table
  * 
  * @return Zend_Db_Select
  */
 public function getDownloadableLinkFinalPriceSelect($write, $table)
 {
     if ($this->getVersionHelper()->isGe1600()) {
         $ifTierPrice = $write->getCheckSql('i.tier_price IS NOT NULL', '(i.tier_price + id.min_price)', 'NULL');
         if ($this->getVersionHelper()->isGe1700()) {
             $ifGroupPrice = $write->getCheckSql('i.group_price IS NOT NULL', '(i.group_price + id.min_price)', 'NULL');
         }
         $tierPrice = new Zend_Db_Expr($ifTierPrice);
     } else {
         $tierPrice = new Zend_Db_Expr('IF(i.tier_price IS NOT NULL, i.tier_price + id.min_price, NULL)');
     }
     $select = $write->select()->join(array('id' => $table), 'i.entity_id = id.entity_id AND i.customer_group_id = id.customer_group_id' . ' AND i.website_id = id.website_id', array())->columns(array('min_price' => new Zend_Db_Expr('i.min_price + id.min_price'), 'max_price' => new Zend_Db_Expr('i.max_price + id.max_price'), 'tier_price' => $tierPrice));
     if ($this->getVersionHelper()->isGe1700()) {
         $select->columns(array('group_price' => new Zend_Db_Expr($ifGroupPrice)));
     }
     return $select;
 }
 /**
  * Return last version id
  *
  * @return int
  */
 public function getLastVersionId()
 {
     $select = $this->_connection->select()->from($this->_metadata->getChangelogName(), array('version_id'))->order('version_id DESC')->limit(1);
     return (int) $this->_connection->fetchOne($select);
 }
 /**
  * Returns select with changed rows
  *
  * @return Varien_Db_Select
  */
 protected function _selectChangedRows()
 {
     return $this->_connection->select()->from(array('source' => $this->_metadata->getViewName()))->where($this->_metadata->getKeyColumn() . ' IN ( ' . $this->_selectChangedIds() . ' )');
 }