/** * @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); } } }
/** * Return category path by id * * @param $categoryId * @return mixed */ protected function _getPathFromCategoryId($categoryId) { if (!isset($this->_categoryPath[$categoryId])) { $this->_categoryPath[$categoryId] = $this->_connection->fetchOne($this->_connection->select()->from($this->_getTable('catalog/category'), array('path'))->where('entity_id = ?', $categoryId)); } return $this->_categoryPath[$categoryId]; }
/** * Returns select with last version_id * * @return int */ protected function _selectLastVersionId() { $changelogName = $this->_metadata->getChangelogName(); if (empty($changelogName)) { return 0; } $select = $this->_connection->select()->from($changelogName, array('version_id'))->order('version_id DESC')->limit(1); return (int) $this->_connection->fetchOne($select); }
/** * @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) { } } }
/** * 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; }
/** * 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; }
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); } } }
/** * Returns current schema name * * @return string */ protected function _getCurrentSchema() { return $this->_adapter->fetchOne('SELECT SCHEMA()'); }
/** * 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); }