/**
  * Adds an additional indexed_price column to as the regular price gets over-ridden elsewhere\
  * 
  * This field seems to only appear when the collection has ->addPriceData();
  * 
  * @see Mage_Catalog_Model_Resource_Product_Collection::_productLimitationJoinPrice()
  */
 protected function _productLimitationJoinPrice()
 {
     $filters = $this->_productLimitationFilters;
     if (empty($filters['use_price_index'])) {
         return $this;
     }
     $helper = Mage::getResourceHelper('core');
     $connection = $this->getConnection();
     $select = $this->getSelect();
     $joinCond = join(' AND ', array('price_index.entity_id = e.entity_id', $connection->quoteInto('price_index.website_id = ?', $filters['website_id']), $connection->quoteInto('price_index.customer_group_id = ?', $filters['customer_group_id'])));
     $fromPart = $select->getPart(Zend_Db_Select::FROM);
     if (!isset($fromPart['price_index'])) {
         $least = $connection->getLeastSql(array('price_index.min_price', 'price_index.tier_price'));
         $minimalExpr = $connection->getCheckSql('price_index.tier_price IS NOT NULL', $least, 'price_index.min_price');
         $indexedExpr = new Zend_Db_Expr('price_index.price');
         $colls = array('indexed_price' => $indexedExpr, 'price', 'tax_class_id', 'final_price', 'minimal_price' => $minimalExpr, 'min_price', 'max_price', 'tier_price');
         $tableName = array('price_index' => $this->getTable('catalog/product_index_price'));
         $select->join($tableName, $joinCond, $colls);
         // Set additional field filters
         foreach ($this->_priceDataFieldFilters as $filterData) {
             $select->where(call_user_func_array('sprintf', $filterData));
         }
     } else {
         $fromPart['price_index']['joinCondition'] = $joinCond;
         $select->setPart(Zend_Db_Select::FROM, $fromPart);
     }
     //Clean duplicated fields
     $helper->prepareColumnsList($select);
     return $this;
 }
Example #2
0
 /**
  * Constructor
  */
 public function __construct()
 {
     /** @var $resource Mage_Core_Model_Resource */
     $resource = Mage::getSingleton('index/resource_lock_resource');
     $this->_connection = $resource->getConnection('index_write', 'default_lock');
     $this->_helper = Mage::getResourceHelper('index');
 }
 /**
  * Prepare simple select by given parameters
  *
  * @param mixed $table
  * @param string $fields
  * @param array | string $where
  * @return string
  */
 protected function _getSimpleSelect($table, $fields, $where = null)
 {
     $_where = array();
     if (!is_null($where)) {
         if (is_array($where)) {
             $_where = $where;
         } else {
             $_where[] = $where;
         }
     }
     $likeOptions = array('position' => 'any');
     if ($this->getEvent()->getCode() !== 'rollback') {
         $itemXmlConfig = $this->getConfig();
         if ($itemXmlConfig->ignore_nodes) {
             foreach ($itemXmlConfig->ignore_nodes->children() as $node) {
                 $path = (string) $node->path;
                 /* $helper Mage_Core_Model_Resource_Helper_Abstract */
                 $helper = Mage::getResourceHelper('core');
                 $_where[] = 'path NOT LIKE ' . $helper->addLikeEscape($path, $likeOptions);
             }
         }
     }
     $select = parent::_getSimpleSelect($table, $fields, $_where);
     return $select;
 }
Example #4
0
 /**
  * Rotate logs - get from database and pump to CSV-file
  *
  * @param int $lifetime
  */
 public function rotate($lifetime)
 {
     //        $this->beginTransaction();
     //        try {
     $readAdapter = $this->_getReadAdapter();
     $writeAdapter = $this->_getWriteAdapter();
     $table = $this->getTable('enterprise_logging/event');
     // get the latest log entry required to the moment
     $clearBefore = $this->formatDate(time() - $lifetime);
     $select = $readAdapter->select()->from($this->getMainTable(), 'log_id')->where('time < ?', $clearBefore)->order('log_id DESC')->limit(1);
     $latestLogEntry = $readAdapter->fetchOne($select);
     if ($latestLogEntry) {
         // make sure folder for dump file will exist
         $archive = Mage::getModel('enterprise_logging/archive');
         $archive->createNew();
         $expr = Mage::getResourceHelper('enterprise_logging')->getInetNtoaExpr('ip');
         $select = $readAdapter->select()->from($this->getMainTable())->where('log_id <= ?', $latestLogEntry)->columns($expr);
         $rows = $readAdapter->fetchAll($select);
         // dump all records before this log entry into a CSV-file
         $csv = fopen($archive->getFilename(), 'w');
         foreach ($rows as $row) {
             fputcsv($csv, $row);
         }
         fclose($csv);
         $writeAdapter->delete($this->getMainTable(), array('log_id <= ?' => $latestLogEntry));
         //                $this->commit();
     }
     //        } catch (Exception $e) {
     //            $this->rollBack();
     //        }
 }
Example #5
0
 public function saveAttributesAfter($observer)
 {
     $data = $observer->getControllerAction()->getRequest()->getPost();
     if ($data['is_configurable'] && $data['is_global']) {
         $baseDir = Mage::getBaseDir('media') . DIRECTORY_SEPARATOR . 'swatches' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR;
         if (isset($_FILES['swatches_img']) && isset($_FILES['swatches_img']['error'])) {
             foreach ($_FILES['swatches_img']['error'] as $optionId => $errorCode) {
                 if ($errorCode == UPLOAD_ERR_OK) {
                     if (strpos($optionId, 'option') === false) {
                         move_uploaded_file($_FILES['swatches_img']['tmp_name'][$optionId], $baseDir . $optionId . '.jpg');
                     } else {
                         $newOptionId = Mage::getResourceHelper('importexport')->getNextAutoincrement(Mage::getSingleton('core/resource')->getTableName('eav/attribute_option')) - 1;
                         move_uploaded_file($_FILES['swatches_img']['tmp_name'][$optionId], $baseDir . $newOptionId . '.jpg');
                     }
                 }
             }
         }
         if (Mage::app()->getRequest()->isPost('useSwatches')) {
             $confAttr = Mage::getModel('bluecom_swatches/attribute')->load($data['attribute_id'], 'attribute_id');
             if (!$confAttr->getId()) {
                 $confAttr->setAttributeId($data['attribute_id']);
             }
             $confAttr->setUseSwatches(intval(Mage::app()->getRequest()->getPost('useSwatches')));
             $confAttr->save();
         }
         // $deleteArr = $data['swatches_img_delete'];
         if (isset($data['swatches_img_delete']) && !empty($data['swatches_img_delete'])) {
             foreach ($data['swatches_img_delete'] as $optionId => $value) {
                 if ($value) {
                     unlink($baseDir . $optionId . '.jpg');
                 }
             }
         }
     }
 }
Example #6
0
 /**
  * Prepare data index for indexable select attributes
  *
  * @param array $entityIds the entity ids limitation
  * @param int $attributeId the attribute id limitation
  * @return Mage_Catalog_Model_Resource_Product_Indexer_Eav_Source
  */
 protected function _prepareSelectIndex($entityIds = null, $attributeId = null)
 {
     $adapter = $this->_getWriteAdapter();
     $idxTable = $this->getIdxTable();
     // prepare select attributes
     if (is_null($attributeId)) {
         $attrIds = $this->_getIndexableAttributes(false);
     } else {
         $attrIds = array($attributeId);
     }
     if (!$attrIds) {
         return $this;
     }
     /**@var $subSelect Varien_Db_Select */
     $subSelect = $adapter->select()->from(array('s' => $this->getTable('core/store')), array('store_id', 'website_id'))->joinLeft(array('d' => $this->getValueTable('catalog/product', 'int')), '1 = 1 AND d.store_id = 0', array('entity_id', 'attribute_id', 'value'))->where('s.store_id != 0 and d.attribute_id IN (?)', array_map('intval', $attrIds));
     if (!is_null($entityIds)) {
         $subSelect->where('d.entity_id IN(?)', array_map('intval', $entityIds));
     }
     /**@var $select Varien_Db_Select */
     $select = $adapter->select()->from(array('pid' => new Zend_Db_Expr(sprintf('(%s)', $subSelect->assemble()))), array())->joinLeft(array('pis' => $this->getValueTable('catalog/product', 'int')), 'pis.entity_id = pid.entity_id AND pis.attribute_id = pid.attribute_id AND pis.store_id = pid.store_id', array())->columns(array('pid.entity_id', 'pid.attribute_id', 'pid.store_id', 'value' => $adapter->getIfNullSql('pis.value', 'pid.value')))->where('pid.attribute_id IN(?)', $attrIds);
     $select->where(Mage::getResourceHelper('catalog')->getIsNullNotNullCondition('pis.value', 'pid.value'));
     /**
      * Add additional external limitation
      */
     Mage::dispatchEvent('prepare_catalog_product_index_select', array('select' => $select, 'entity_field' => new Zend_Db_Expr('pid.entity_id'), 'website_field' => new Zend_Db_Expr('pid.website_id'), 'store_field' => new Zend_Db_Expr('pid.store_id')));
     $query = $select->insertFromSelect($idxTable);
     $adapter->query($query);
     return $this;
 }
 /**
  * Collection condition filter getter
  *
  * @return array
  */
 public function getCondition()
 {
     $value = $this->getValue();
     if (preg_match('/^(\\d+\\.){3}\\d+$/', $value)) {
         return ip2long($value);
     }
     $expr = Mage::getResourceHelper('enterprise_logging')->getInetNtoaExpr();
     return array('field_expr' => $expr, 'like' => "%{$this->_escapeValue($value)}%");
 }
Example #8
0
 /**
  * Collection condition filter getter
  *
  * @return array
  */
 public function getCondition()
 {
     $value = $this->getValue();
     if (preg_match('/^(\\d+\\.){3}\\d+$/', $value) || preg_match('/^(([0-9a-f]{1,4})?(:([0-9a-f]{1,4})?){1,}:([0-9a-f]{1,4}))(%[0-9a-z]+)?$/i', $value)) {
         return inet_pton($value);
     }
     $expr = Mage::getResourceHelper('enterprise_logging')->getInetNtoaExpr();
     return array('field_expr' => $expr, 'like' => "%{$this->_escapeValue($value)}%");
 }
 /**
  *
  * @param string $searchTerm
  */
 public function addFulltextSearchTerm($searchTerm)
 {
     $select = $this->getSelect();
     $preparedTerms = Mage::getResourceHelper('catalogsearch')->prepareTerms($searchTerm);
     $select->join(array('fs' => 'catalogsearch_fulltext'), 'fs.product_id = e.entity_id', array());
     $select->where(new Zend_Db_Expr('MATCH (fs.data_index) AGAINST (:query IN BOOLEAN MODE)'));
     $this->addBindParam(':query', implode(' ', $preparedTerms[0]));
     $select->group('e.entity_id');
 }
Example #10
0
 /**
  * Add IP filter to collection
  *
  * @param string $value
  * @return Enterprise_Logging_Model_Resource_Event_Collection
  */
 public function addIpFilter($value)
 {
     if (preg_match('/^(\\d+\\.){3}\\d+$/', $value)) {
         return $this->addFieldToFilter('ip', ip2long($value));
     }
     $condition = $this->getConnection()->prepareSqlCondition(Mage::getResourceHelper('enterprise_logging')->getInetNtoaExpr('ip'), array('like' => Mage::getResourceHelper('core')->addLikeEscape($value, array('position' => 'any'))));
     $this->getSelect()->where($condition);
     return $this;
 }
Example #11
0
 /**
  * Retrieve condition
  *
  * @return array
  */
 public function getCondition()
 {
     $id = $this->getValue();
     $length = strlen($id);
     $search = "{s:4:\"type\";s:{$length}:\"{$id}\"";
     $helper = Mage::getResourceHelper('core');
     $likeExpression = $helper->addLikeEscape($search, array('position' => 'any'));
     return array('like' => $likeExpression);
 }
Example #12
0
 /**
  * Prepare results for query
  *
  * @param Mage_CatalogSearch_Model_Fulltext $object
  * @param string $queryText
  * @param Mage_CatalogSearch_Model_Query $query
  * @return Mage_CatalogSearch_Model_Resource_Fulltext
  */
 public function prepareResult($object, $queryText, $query)
 {
     $adapter = $this->_getWriteAdapter();
     if (!$query->getIsProcessed()) {
         $searchType = $object->getSearchType($query->getStoreId());
         $preparedTerms = Mage::getResourceHelper('catalogsearch')->prepareTerms($queryText, $query->getMaxQueryWords());
         $bind = array();
         $like = array();
         $likeCond = '';
         if ($searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_LIKE || $searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_COMBINE) {
             $helper = Mage::getResourceHelper('core');
             $words = Mage::helper('core/string')->splitWords($queryText, true, $query->getMaxQueryWords());
             foreach ($words as $word) {
                 $like[] = $helper->getCILike('s.data_index', $word, array('position' => 'any'));
             }
             if ($like) {
                 $likeCond = '(' . join(' OR ', $like) . ')';
             }
         }
         $mainTableAlias = 's';
         $fields = array('query_id' => new Zend_Db_Expr($query->getId()), 'product_id');
         $select = $adapter->select()->from(array($mainTableAlias => $this->getMainTable()), $fields)->joinInner(array('e' => $this->getTable('catalog/product')), 'e.entity_id = s.product_id', array())->where($mainTableAlias . '.store_id = ?', (int) $query->getStoreId());
         if ($searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_FULLTEXT || $searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_COMBINE) {
             $bind[':query'] = implode(' ', $preparedTerms[0]);
             $where = Mage::getResourceHelper('catalogsearch')->chooseFulltext($this->getMainTable(), $mainTableAlias, $select);
         }
         if ($likeCond != '' && $searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_COMBINE) {
             $where .= ($where ? ' OR ' : '') . $likeCond;
         } elseif ($likeCond != '' && $searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_LIKE) {
             $select->columns(array('relevance' => new Zend_Db_Expr(0)));
             $where = $likeCond;
         }
         if ($where != '') {
             $select->where($where);
         }
         /*
         $sql = $adapter->insertFromSelect($select,
             $this->getTable('catalogsearch/result'),
             array(),
             Varien_Db_Adapter_Interface::INSERT_ON_DUPLICATE);
         $adapter->query($sql, $bind);
         */
         $conn = new Connection();
         $conn->setParams(array('host' => '127.0.0.1', 'port' => 9306));
         /** @var SphinxQL $sphinxQuery */
         $sphinxQuery = SphinxQL::create($conn)->select(array('*', SphinxQL::expr('WEIGHT()')))->from('fulltext')->option('ranker', 'bm25')->option('field_weights', SphinxQL::expr('(name=7, attributes=3, data_index=1)'))->option('cutoff', 5000)->option('max_matches', 1000)->limit(0, 100)->match('*', $queryText);
         $results = $sphinxQuery->execute();
         foreach ($results as $result) {
             // Ensure we log query results into the Magento table.
             $sql = sprintf("INSERT INTO {$this->getTable('catalogsearch/result')} " . " (query_id, product_id, relevance) VALUES " . " (%d, %d, %f) " . " ON DUPLICATE KEY UPDATE relevance = %f", $query->getId(), $result['id'], $result['weight()'] / 1000, $result['weight()'] / 1000);
             $this->_getWriteAdapter()->query($sql, $bind);
         }
         $conn->close();
         $query->setIsProcessed(1);
     }
     return $this;
 }
 /**
  * Override of parent
  *
  * - Like match position
  *
  * @param string $query
  * @return Mage_CatalogSearch_Model_Resource_Query_Collection
  */
 public function setQueryFilter($query)
 {
     $ifSynonymFor = $this->getConnection()->getIfNullSql('synonym_for', 'query_text');
     $this->getSelect()->reset(Zend_Db_Select::FROM)->distinct(true)->from(array('main_table' => $this->getTable('catalogsearch/search_query')), array('query' => $ifSynonymFor, 'num_results'))->where('num_results > 0 AND display_in_terms = 1 AND query_text LIKE ?', Mage::getResourceHelper('core')->addLikeEscape($query, array('position' => Mage::getStoreConfig('catalog/search/like_match_position'))))->order('popularity ' . Varien_Db_Select::SQL_DESC);
     if ($this->getStoreId()) {
         $this->getSelect()->where('store_id = ?', (int) $this->getStoreId());
     }
     return $this;
 }
 /**
  * Prepare base condition select which related with current condition combine
  *
  * @param $customer
  * @param $website
  * @return Varien_Db_Select
  */
 protected function _prepareConditionsSql($customer, $website)
 {
     $resource = $this->getResource();
     $select = $resource->createSelect();
     $addressEntityType = Mage::getSingleton('eav/config')->getEntityType('customer_address');
     $addressTable = $resource->getTable($addressEntityType->getEntityTable());
     $select->from(array('customer_address' => $addressTable), array(new Zend_Db_Expr(1)));
     $select->where('customer_address.entity_type_id = ?', $addressEntityType->getId());
     $select->where($this->_createCustomerFilter($customer, 'customer_address.parent_id'));
     Mage::getResourceHelper('enterprise_customersegment')->setOneRowLimit($select);
     return $select;
 }
 /**
  * Multi add entities data to fulltext search table
  *
  * @param int $storeId
  * @param array $entityIndexes
  * @param string $entity 'product'|'cms'
  * @return Mage_CatalogSearch_Model_Resource_Fulltext_Engine
  */
 public function saveEntityIndexes($storeId, $entityIndexes, $entity = 'product')
 {
     $data = array();
     $storeId = (int) $storeId;
     foreach ($entityIndexes as $entityId => $index) {
         $data[] = array('product_id' => (int) $entityId, 'store_id' => $storeId, 'data_index' => $index);
     }
     if ($data) {
         Mage::getResourceHelper('catalogsearch')->insertOnDuplicate($this->getMainTable(), $data, array('data_index'));
     }
     return $this;
 }
Example #16
0
 /**
  * Get SQL select for matching shopping cart items count
  *
  * @param $customer
  * @param int | Zend_Db_Expr $website
  * @return Varien_Db_Select
  */
 public function getConditionsSql($customer, $website)
 {
     $table = $this->getResource()->getTable('sales/quote');
     $operator = $this->getResource()->getSqlOperator($this->getOperator());
     $select = $this->getResource()->createSelect();
     $select->from(array('quote' => $table), array(new Zend_Db_Expr(1)));
     $this->_limitByStoreWebsite($select, $website, 'quote.store_id');
     $select->where('quote.is_active = 1');
     $select->where("quote.items_count {$operator} ?", $this->getValue());
     $select->where($this->_createCustomerFilter($customer, 'quote.customer_id'));
     Mage::getResourceHelper('enterprise_reminder')->setRuleLimit($select, 1);
     return $select;
 }
Example #17
0
 /**
  * Update rating position
  *
  * @param string $aggregation One of Mage_Sales_Model_Resource_Report_Bestsellers::AGGREGATION_XXX constants
  * @param array $aggregationAliases
  * @param string $mainTable
  * @param string $aggregationTable
  * @return Mage_Sales_Model_Resource_Helper_Abstract
  */
 public function getBestsellersReportUpdateRatingPos($aggregation, $aggregationAliases, $mainTable, $aggregationTable)
 {
     /** @var $reportsResourceHelper Mage_Reports_Model_Resource_Helper_Interface */
     $reportsResourceHelper = Mage::getResourceHelper('reports');
     if ($aggregation == $aggregationAliases['monthly']) {
         $reportsResourceHelper->updateReportRatingPos('month', 'qty_ordered', $mainTable, $aggregationTable);
     } elseif ($aggregation == $aggregationAliases['yearly']) {
         $reportsResourceHelper->updateReportRatingPos('year', 'qty_ordered', $mainTable, $aggregationTable);
     } else {
         $reportsResourceHelper->updateReportRatingPos('day', 'qty_ordered', $mainTable, $aggregationTable);
     }
     return $this;
 }
Example #18
0
 /**
  * Retrieve flat column definition
  *
  * @return array
  */
 public function getFlatColums()
 {
     $attributeType = $this->getAttribute()->getBackendType();
     $attributeCode = $this->getAttribute()->getAttributeCode();
     $column = array('unsigned' => false, 'default' => null, 'extra' => null);
     if (Mage::helper('core')->useDbCompatibleMode()) {
         $column['type'] = $attributeType;
         $column['is_null'] = true;
     } else {
         $column['type'] = Mage::getResourceHelper('eav')->getDdlTypeByColumnType($attributeType);
         $column['nullable'] = true;
     }
     return array($attributeCode => $column);
 }
Example #19
0
 /**
  * initialize select object
  *
  * @return Mage_Catalog_Model_Resource_Product_Attribute_Collection
  */
 protected function _initSelect()
 {
     $entityTypeId = (int) Mage::getModel('eav/entity')->setType('csmarketplace_vendor')->getTypeId();
     $columns = $this->getConnection()->describeTable($this->getResource()->getMainTable());
     unset($columns['attribute_id']);
     $retColumns = array();
     foreach ($columns as $labelColumn => $columnData) {
         $retColumns[$labelColumn] = $labelColumn;
         if ($columnData['DATA_TYPE'] == Varien_Db_Ddl_Table::TYPE_TEXT) {
             $retColumns[$labelColumn] = Mage::getResourceHelper('core')->castField('main_table.' . $labelColumn);
         }
     }
     $this->getSelect()->from(array('main_table' => $this->getResource()->getMainTable()), $retColumns)->join(array('additional_table' => $this->getTable('csmarketplace/vendor_form')), 'additional_table.attribute_id = main_table.attribute_id')->where('main_table.entity_type_id = ?', $entityTypeId);
     return $this;
 }
Example #20
0
 /**
  * Retrieve list of attributes with admin store label containing $labelPart
  *
  * @param string $labelPart
  * @return Mage_Catalog_Model_Resource_Product_Attribute_Collection
  */
 public function getSuggestedAttributes($labelPart)
 {
     $escapedLabelPart = Mage::getResourceHelper('Mage_Core')->addLikeEscape($labelPart, array('position' => 'any'));
     /** @var $collection Mage_Catalog_Model_Resource_Product_Attribute_Collection */
     $collection = Mage::getResourceModel('Mage_Catalog_Model_Resource_Product_Attribute_Collection')->addFieldToFilter('frontend_input', 'select')->addFieldToFilter('frontend_label', array('like' => $escapedLabelPart))->addFieldToFilter('is_configurable', 1)->addFieldToFilter('is_user_defined', 1)->addFieldToFilter('is_global', Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL);
     $result = array();
     $types = array(Mage_Catalog_Model_Product_Type::TYPE_SIMPLE, Mage_Catalog_Model_Product_Type::TYPE_VIRTUAL, Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE);
     foreach ($collection->getItems() as $id => $attribute) {
         /** @var $attribute Mage_Catalog_Model_Resource_Eav_Attribute */
         if (!$attribute->getApplyTo() || count(array_diff($types, $attribute->getApplyTo())) === 0) {
             $result[$id] = array('id' => $attribute->getId(), 'label' => $attribute->getFrontendLabel(), 'code' => $attribute->getAttributeCode(), 'options' => $attribute->getSource()->getAllOptions(false));
         }
     }
     return $result;
 }
Example #21
0
 /**
  * Retrieves information about log tables
  *
  * @return array
  */
 public function getTablesInfo()
 {
     $tables = array('log_customer', 'log_visitor', 'log_visitor_info', 'log_url_table', 'log_url_info_table', 'log_quote_table', 'reports_viewed_product_index', 'reports_compared_product_index', 'reports_event', 'catalog_compare_item');
     $resHelper = Mage::getResourceHelper('Mage_Log');
     $result = array();
     $resource = Mage::getSingleton('Mage_Core_Model_Resource');
     foreach ($tables as $table) {
         $info = $resHelper->getTableInfo($resource->getTableName($table));
         if (!$info) {
             continue;
         }
         $result[] = $info;
     }
     return $result;
 }
 public function isUsedBySuperProducts(Mage_Core_Model_Abstract $object, $attributeSet = null)
 {
     $adapter = $this->_getReadAdapter();
     $attrTable = $this->getTable('catalog/product_super_attribute');
     $productTable = $this->getTable('catalog/product');
     $bind = array('attribute_id' => $object->getAttributeId());
     $select = clone $adapter->select();
     $select->reset()->from(array('main_table' => $attrTable), array('psa_count' => 'COUNT(product_super_attribute_id)'))->join(array('entity' => $productTable), 'main_table.product_id = entity.entity_id')->where('main_table.attribute_id = :attribute_id')->group('main_table.attribute_id')->limit(1);
     if ($attributeSet !== null) {
         $bind['attribute_set_id'] = $attributeSet;
         $select->where('entity.attribute_set_id = :attribute_set_id');
     }
     $helper = Mage::getResourceHelper('core');
     $query = $helper->getQueryUsingAnalyticFunction($select);
     return $adapter->fetchOne($query, $bind);
 }
 /**
  * Retrieve flat column definition
  *
  * @return array
  */
 public function getFlatColums()
 {
     $attributeDefaultValue = $this->getAttribute()->getDefaultValue();
     $attributeCode = $this->getAttribute()->getAttributeCode();
     $attributeType = $this->getAttribute()->getBackendType();
     $isNullable = is_null($attributeDefaultValue) || empty($attributeDefaultValue);
     $column = array('unsigned' => false, 'extra' => null, 'default' => $isNullable ? null : $attributeDefaultValue);
     if (Mage::helper('core')->useDbCompatibleMode()) {
         $column['type'] = $attributeType;
         $column['is_null'] = $isNullable;
     } else {
         $column['type'] = Mage::getResourceHelper('eav')->getDdlTypeByColumnType($attributeType);
         $column['nullable'] = $isNullable;
         $column['comment'] = 'Enterprise Giftcard Open ' . $attributeCode . ' column';
     }
     return array($attributeCode => $column);
 }
Example #24
0
 protected function _toHtml()
 {
     //store id is store view id
     $storeId = $this->_getStoreId();
     $tagModel = Mage::registry('tag_model');
     $newurl = Mage::getUrl('rss/catalog/tag/tagName/' . $tagModel->getName());
     $title = Mage::helper('Mage_Tag_Helper_Data')->__('Products tagged with %s', $tagModel->getName());
     $lang = Mage::getStoreConfig('general/locale/code');
     $rssObj = Mage::getModel('Mage_Rss_Model_Rss');
     $data = array('title' => $title, 'description' => $title, 'link' => $newurl, 'charset' => 'UTF-8', 'language' => $lang);
     $rssObj->_addHeader($data);
     $_collection = $tagModel->getEntityCollection()->addTagFilter($tagModel->getId())->addStoreFilter($storeId);
     $_collection->setVisibility(Mage::getSingleton('Mage_Catalog_Model_Product_Visibility')->getVisibleInCatalogIds());
     $product = Mage::getModel('Mage_Catalog_Model_Product');
     Mage::getSingleton('Mage_Core_Model_Resource_Iterator')->walk(Mage::getResourceHelper('Mage_Core')->getQueryUsingAnalyticFunction($_collection->getSelect()), array(array($this, 'addTaggedItemXml')), array('rssObj' => $rssObj, 'product' => $product), $_collection->getSelect()->getAdapter());
     return $rssObj->createRssXml();
 }
 /**
  * Get SQL select for matching shopping cart items count
  *
  * @param $customer
  * @param int | Zend_Db_Expr $website
  * @return Varien_Db_Select
  */
 public function getConditionsSql($customer, $website)
 {
     $table = $this->getResource()->getTable('sales/quote');
     $operator = $this->getResource()->getSqlOperator($this->getOperator());
     $select = $this->getResource()->createSelect();
     $select->from(array('quote' => $table), array(new Zend_Db_Expr(1)))->where('quote.is_active=1');
     $this->_limitByStoreWebsite($select, $website, 'quote.store_id');
     Mage::getResourceHelper('enterprise_customersegment')->setOneRowLimit($select);
     $select->where("quote.items_count {$operator} ?", $this->getValue());
     if ($customer) {
         // Leave ability to check this condition not only by customer_id but also by quote_id
         $select->where('quote.customer_id = :customer_id OR quote.entity_id = :quote_id');
     } else {
         $select->where($this->_createCustomerFilter($customer, 'quote.customer_id'));
     }
     return $select;
 }
Example #26
0
 public function checkTypeHints(Mage_Catalog_Model_Category $category, $noHint, Mage_Core_Helper_Data $data)
 {
     $job = Mage::getModel("monkey/bulksync{$entity}")->load($id);
     $new = new Mage_Admin_Model_Acl();
     // done
     $lifetime = Mage_Core_Model_Cache::DEFAULT_LIFETIME;
     // done
     $model = Mage::getModel('customer/customer');
     $singleton = Mage::getSingleton('admin/session');
     $resource = Mage::getResourceModel('admin/roles_user_collection');
     $resourceSingleton = Mage::getResourceSingleton('catalog/category_tree');
     $createBlock = $this->getLayout()->createBlock('adminhtml/widget_button');
     $blockSingleton = Mage::getBlockSingleton('core/text_list');
     $resourceHelper = Mage::getResourceHelper('catalog');
     $controllerInstance = Mage::getControllerInstance('Mage_Adminhtml_Rss_CatalogController', new stdClass(), new stdClass());
     $dataHelper = Mage::helper('reports');
     $helper = Mage::helper('adminhtml/rss');
 }
 function getCondition()
 {
     if (trim($this->getValue()) == '') {
         return null;
     }
     $skuIds = explode(',', $this->getValue());
     $skuIdsArray = array();
     foreach ($skuIds as $skuId) {
         $skuIdsArray[] = trim($skuId);
     }
     if (count($skuIdsArray) == 1) {
         $helper = Mage::getResourceHelper('core');
         $likeExpression = $helper->addLikeEscape($this->getValue(), array('position' => 'any'));
         return array('like' => $likeExpression);
     } else {
         return array('inset' => $skuIdsArray);
     }
 }
 /**
  * Join review table to result
  *
  * @return Mage_Reports_Model_Resource_Review_Product_Collection
  */
 public function joinReview()
 {
     $helper = Mage::getResourceHelper('core');
     $subSelect = clone $this->getSelect();
     $subSelect->reset()->from(array('rev' => $this->getTable('review/review')), 'COUNT(DISTINCT rev.review_id)')->where('e.entity_id = rev.entity_pk_value');
     $this->addAttributeToSelect('name');
     $this->getSelect()->join(array('r' => $this->getTable('review/review')), 'e.entity_id = r.entity_pk_value', array('review_cnt' => new Zend_Db_Expr(sprintf('(%s)', $subSelect)), 'last_created' => 'MAX(r.created_at)'))->group('e.entity_id');
     $joinCondition = array('e.entity_id = table_rating.entity_pk_value', $this->getConnection()->quoteInto('table_rating.store_id > ?', 0));
     /**
      * @var $groupByCondition array of group by fields
      */
     $groupByCondition = $this->getSelect()->getPart(Zend_Db_Select::GROUP);
     $percentField = $this->getConnection()->quoteIdentifier('table_rating.percent');
     $sumPercentField = $helper->prepareColumn("SUM({$percentField})", $groupByCondition);
     $sumPercentApproved = $helper->prepareColumn('SUM(table_rating.percent_approved)', $groupByCondition);
     $countRatingId = $helper->prepareColumn('COUNT(table_rating.rating_id)', $groupByCondition);
     $this->getSelect()->joinLeft(array('table_rating' => $this->getTable('rating/rating_vote_aggregated')), implode(' AND ', $joinCondition), array('avg_rating' => sprintf('%s/%s', $sumPercentField, $countRatingId), 'avg_rating_approved' => sprintf('%s/%s', $sumPercentApproved, $countRatingId)));
     return $this;
 }
Example #29
0
 /**
  * Prepare results for query
  *
  * @param Mage_CatalogSearch_Model_Fulltext $object
  * @param string $queryText
  * @param Mage_CatalogSearch_Model_Query $query
  * @return Mage_CatalogSearch_Model_Resource_Fulltext
  */
 public function prepareResult($object, $queryText, $query)
 {
     $adapter = $this->_getWriteAdapter();
     if (!$query->getIsProcessed()) {
         $searchType = $object->getSearchType($query->getStoreId());
         $preparedTerms = Mage::getResourceHelper('catalogsearch')->prepareTerms($queryText, $query->getMaxQueryWords());
         $bind = array();
         $like = array();
         $likeCond = '';
         if ($searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_LIKE || $searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_COMBINE) {
             $helper = Mage::getResourceHelper('core');
             $words = Mage::helper('core/string')->splitWords($queryText, true, $query->getMaxQueryWords());
             foreach ($words as $word) {
                 $like[] = $helper->getCILike('s.data_index', $word, array('position' => 'any'));
             }
             if ($like) {
                 $likeCond = '(' . join(' AND ', $like) . ')';
             }
         }
         $mainTableAlias = 's';
         $fields = array('query_id' => new Zend_Db_Expr($query->getId()), 'product_id');
         $select = $adapter->select()->from(array($mainTableAlias => $this->getMainTable()), $fields)->joinInner(array('e' => $this->getTable('catalog/product')), 'e.entity_id = s.product_id', array())->where($mainTableAlias . '.store_id = ?', (int) $query->getStoreId());
         if ($searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_FULLTEXT || $searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_COMBINE) {
             $bind[':query'] = implode(' ', $preparedTerms[0]);
             $where = Mage::getResourceHelper('catalogsearch')->chooseFulltext($this->getMainTable(), $mainTableAlias, $select);
         }
         if ($likeCond != '' && $searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_COMBINE) {
             $where .= ($where ? ' OR ' : '') . $likeCond;
         } elseif ($likeCond != '' && $searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_LIKE) {
             $select->columns(array('relevance' => new Zend_Db_Expr(0)));
             $where = $likeCond;
         }
         if ($where != '') {
             $select->where($where);
         }
         $sql = $adapter->insertFromSelect($select, $this->getTable('catalogsearch/result'), array(), Varien_Db_Adapter_Interface::INSERT_ON_DUPLICATE);
         $adapter->query($sql, $bind);
         $query->setIsProcessed(1);
     }
     return $this;
 }
 /**
  * Constructor
  *
  * @param array $parameters
  */
 public function __construct(array $parameters = array())
 {
     if (isset($parameters['coreHelper']) && $parameters['coreHelper'] instanceof Mage_Core_Helper_Data) {
         $this->_coreHelper = $parameters['coreHelper'];
     } else {
         $this->_coreHelper = Mage::helper('core');
     }
     if (isset($parameters['catalogHelper']) && $parameters['catalogHelper'] instanceof Mage_Catalog_Helper_Data) {
         $this->_catalogHelper = $parameters['catalogHelper'];
     } else {
         $this->_catalogHelper = Mage::helper('catalog');
     }
     if (isset($parameters['connection']) && $parameters['connection'] instanceof Varien_Db_Adapter_Interface) {
         $this->_connection = $parameters['connection'];
     } else {
         $this->_connection = Mage::getSingleton('core/resource')->getConnection(Mage_Core_Model_Resource::DEFAULT_READ_RESOURCE);
     }
     if (!empty($parameters['eavHelper']) && $parameters['eavHelper'] instanceof Mage_Core_Model_Resource_Helper_Abstract) {
         $this->_eavHelper = $parameters['eavHelper'];
     } else {
         $this->_eavHelper = Mage::getResourceHelper('eav');
     }
 }