/**
  * 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;
 }
Exemple #2
0
 /**
  * Convert operator for sql where
  *
  * @param string $field
  * @param string $operator
  * @param string|array $value
  * @return string
  */
 public function getOperatorCondition($field, $operator, $value)
 {
     switch ($operator) {
         case '!=':
         case '>=':
         case '<=':
         case '>':
         case '<':
             $selectOperator = sprintf('%s?', $operator);
             break;
         case '{}':
         case '!{}':
             if (preg_match('/^.*(category_id)$/', $field) && is_array($value)) {
                 $selectOperator = ' IN (?)';
             } else {
                 $selectOperator = ' LIKE ?';
             }
             if (substr($operator, 0, 1) == '!') {
                 $selectOperator = ' NOT' . $selectOperator;
             }
             break;
         case '[]':
         case '![]':
         case '()':
         case '!()':
             $selectOperator = 'FIND_IN_SET(?,' . $this->_adapter->quoteIdentifier($field) . ')';
             if (substr($operator, 0, 1) == '!') {
                 $selectOperator = 'NOT ' . $selectOperator;
             }
             break;
         default:
             $selectOperator = '=?';
             break;
     }
     $field = $this->_adapter->quoteIdentifier($field);
     if (is_array($value) && in_array($operator, array('==', '!=', '>=', '<=', '>', '<', '{}', '!{}'))) {
         $results = array();
         foreach ($value as $v) {
             $results[] = $this->_adapter->quoteInto("{$field}{$selectOperator}", $v);
         }
         $result = implode(' AND ', $results);
     } elseif (in_array($operator, array('()', '!()', '[]', '![]'))) {
         if (!is_array($value)) {
             $value = array($value);
         }
         $results = array();
         foreach ($value as $v) {
             $results[] = $this->_adapter->quoteInto("{$selectOperator}", $v);
         }
         $result = implode(in_array($operator, array('()', '!()')) ? ' OR ' : ' AND ', $results);
     } else {
         $result = $this->_adapter->quoteInto("{$field}{$selectOperator}", $value);
     }
     return $result;
 }
 /**
  * Get events conditons SQL
  *
  * @param array $conditions
  * @param string $conditionsLogic
  *
  * @return string
  */
 public function getEventConditionsSql($conditions, $conditionsLogic)
 {
     $conditionStrings = array();
     foreach ($conditions as $condition) {
         $sql = $condition[self::INDEX_CONDITION];
         if (isset($condition[self::INDEX_PARAM])) {
             foreach ($condition[self::INDEX_PARAM] as $param) {
                 $sql = $this->_connection->quoteInto($sql, $param, null, 1);
             }
         }
         $conditionStrings[] = $sql;
     }
     return implode(' ' . $conditionsLogic . ' ', $conditionStrings);
 }
 /**
  * Join url rewrite to select
  *
  * @param Varien_Db_Select $select
  * @param int $storeId
  * @return Mage_Catalog_Helper_Category_Url_Rewrite
  */
 public function joinTableToSelect(Varien_Db_Select $select, $storeId)
 {
     $select->joinLeft(array('url_rewrite' => $this->_resource->getTableName('core/url_rewrite')), 'url_rewrite.category_id=main_table.entity_id AND url_rewrite.is_system=1 AND ' . $this->_connection->quoteInto('url_rewrite.store_id = ? AND ', (int) $storeId) . $this->_connection->prepareSqlCondition('url_rewrite.id_path', array('like' => 'category/%')), array('request_path' => 'url_rewrite.request_path'));
     return $this;
 }
 /**
  * Join url rewrite to select
  *
  * @param Varien_Db_Select $select
  * @param int $storeId
  * @return Enterprise_Catalog_Helper_Category_UrlRewrite
  */
 public function joinTableToSelect(Varien_Db_Select $select, $storeId)
 {
     $requestPath = $this->_connection->getIfNullSql('url_rewrite.request_path', 'default_ur.request_path');
     $select->joinLeft(array('url_rewrite_category' => $this->_resource->getTableName('enterprise_catalog/category')), 'url_rewrite_category.category_id = main_table.entity_id' . ' AND ' . $this->_connection->quoteInto('url_rewrite_category.store_id = ?', (int) $storeId), array(''))->joinLeft(array('url_rewrite' => $this->_resource->getTableName('enterprise_urlrewrite/url_rewrite')), 'url_rewrite_category.url_rewrite_id = url_rewrite.url_rewrite_id AND url_rewrite.is_system = 1', array(''))->joinLeft(array('default_urc' => $this->_resource->getTableName('enterprise_catalog/category')), 'default_urc.category_id = url_rewrite_category.category_id AND default_urc.store_id = 0', array(''))->joinLeft(array('default_ur' => $this->_resource->getTableName('enterprise_urlrewrite/url_rewrite')), 'default_ur.url_rewrite_id = default_urc.url_rewrite_id  AND default_ur.is_system = 1', array('request_path' => $requestPath));
     return $this;
 }
Exemple #6
0
 /**
  * Delete custom option type values
  *
  * @param array $optionIds
  * @return Mage_ImportExport_Model_Import_Entity_Product_Option
  */
 protected function _deleteSpecificTypeValues(array $optionIds)
 {
     $this->_connection->delete($this->_tables['catalog_product_option_type_value'], $this->_connection->quoteInto('option_id IN (?)', $optionIds));
     return $this;
 }
Exemple #7
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;
 }