本文整理汇总了PHP中Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection::getSelect方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection::getSelect方法的具体用法?PHP Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection::getSelect怎么用?PHP Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection::getSelect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection
的用法示例。
在下文中一共展示了Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection::getSelect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: applyToCollection
/**
* @param Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection $collection
* @param Morphes_Filters_Model_Filter_Price $model
* @param array $value
* @return Morphes_Filters_Resource_Filter_Price
*/
public function applyToCollection($collection, $model, $value)
{
$collection->addPriceData($model->getCustomerGroupId(), $model->getWebsiteId());
$select = $collection->getSelect();
$response = $this->_dispatchPreparePriceEvent($model, $select);
$table = $this->_getIndexTableAlias();
$additional = join('', $response->getAdditionalCalculations());
$fix = $this->_getConfigurablePriceFix();
$rate = $model->getCurrencyRate();
$precision = 2;
//$filter->getDecimalDigits();
if ($this->isUpperBoundInclusive()) {
$priceExpr = new Zend_Db_Expr("ROUND(({$table}.min_price {$additional} {$fix}) * {$rate}, {$precision})");
} else {
$priceExpr = new Zend_Db_Expr("({$table}.min_price {$additional} {$fix}) * {$rate}");
}
$condition = '';
foreach ($model->getMSelectedValues() as $selection) {
if (strpos($selection, ',') !== false) {
list($index, $range) = explode(',', $selection);
$range = $this->getPriceRange($index, $range);
if ($condition != '') {
$condition .= ' OR ';
}
$condition .= '((' . $priceExpr . ' >= ' . $range['from'] . ') ' . 'AND (' . $priceExpr . ($this->isUpperBoundInclusive() ? ' <= ' : ' < ') . $range['to'] . '))';
}
}
if ($condition) {
$select->distinct()->where("NOT ({$condition})");
}
return $this;
}
示例2: getFilterCounts
public function getFilterCounts($code, $cache = true)
{
$currentFilter = $this->_filters[$code];
/* @var $currentFilterModel Mana_Filters_Interface_Filter */
$currentFilterModel = $currentFilter['model'];
if (!$cache || !isset($currentFilter['processedCounts'])) {
if (!empty($currentFilter['isCounted'])) {
$currentFilter['processedCounts'] = $currentFilterModel->processCounts($currentFilter['counts']);
} else {
$mainSelect = clone $this->_productCollection->getSelect();
$collection = $this->createProductCollection();
//$sql = $collection->getSelect()->__toString();
foreach ($this->_filters as $filter) {
/* @var $filterModel Mana_Filters_Interface_Filter */
$filterModel = $filter['model'];
if ($filter['isApplied'] && $currentFilterModel->isFilterAppliedWhenCounting($filterModel)) {
$filterModel->applyToCollection($collection);
}
}
$counts = $currentFilterModel->countOnCollection($collection);
$currentFilter['processedCounts'] = $currentFilterModel->processCounts($counts);
$this->_copyParts($this->_productCollection->getSelect(), $mainSelect);
}
if ($cache) {
$this->_filters[$code] = $currentFilter;
}
}
return $currentFilter['processedCounts'];
}
示例3: _prepareProductCollection
/**
* @param Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection $collection
* @param $categoryId
*/
protected function _prepareProductCollection($collection, $categoryId)
{
$res = $collection->getResource();
$db = $res->getReadConnection();
$storeId = Mage::app()->getStore()->getId();
$subSelect = $db->select()->from(array('subcat_index' => $res->getTable('catalog/category_product_index')), new Zend_Db_Expr("`subcat_index`.`product_id`"))->joinInner(array('subcat' => $res->getTable('catalog/category')), "`subcat`.`entity_id` = `subcat_index`.`category_id`", null)->where("`subcat_index`.`store_id`={$storeId} AND `subcat_index`.`visibility` IN(2, 4) AND `subcat`.`parent_id` = ?", $categoryId);
$collection->getSelect()->where("`e`.`entity_id` IN ({$subSelect})");
}
示例4: applyToCollection
/**
* @param Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection $collection
* @param Mana_Filters_Model_Filter_Attribute $model
* @param array $value
* @return Mana_Filters_Resource_Filter_Attribute
*/
public function applyToCollection($collection, $model, $value)
{
$attribute = $model->getAttributeModel();
$connection = $this->_getReadAdapter();
$tableAlias = $attribute->getAttributeCode() . '_idx';
$conditions = array("{$tableAlias}.entity_id = e.entity_id", $connection->quoteInto("{$tableAlias}.attribute_id = ?", $attribute->getAttributeId()), $connection->quoteInto("{$tableAlias}.store_id = ?", $collection->getStoreId()), "{$tableAlias}.value in (" . implode(',', array_filter($value)) . ")");
$conditions = join(' AND ', $conditions);
$collection->getSelect()->distinct()->join(array($tableAlias => $this->getMainTable()), $conditions, array());
return $this;
}
示例5: applyToCollection
/**
* @param Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection $collection
* @param Mana_Filters_Resource_Filter_Attribute $model
* @param array $value
* @return Mana_Filters_Resource_Filter_Attribute
*/
public function applyToCollection($collection, $model, $value)
{
$attribute = $model->getAttributeModel();
$connection = $this->_getReadAdapter();
foreach ($value as $i => $singleValue) {
$tableAlias = $attribute->getAttributeCode() . '_idx' . $i;
$conditions = array("{$tableAlias}.entity_id = e.entity_id", $connection->quoteInto("{$tableAlias}.attribute_id = ?", $attribute->getAttributeId()), $connection->quoteInto("{$tableAlias}.store_id = ?", $collection->getStoreId()), "{$tableAlias}.value = {$singleValue}");
$conditions = join(' AND ', $conditions);
$collection->getSelect()->distinct()->join(array($tableAlias => $this->getMainTable()), $conditions, array());
}
return $this;
}
示例6: countOnCollection
/**
* @param Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection $collection
* @param Mana_Filters_Model_Filter_Attribute $model
* @return Mana_Filters_Resource_Filter_Decimal
*/
public function countOnCollection($collection, $model)
{
$select = $collection->getSelect();
$select->reset(Zend_Db_Select::COLUMNS);
$select->reset(Zend_Db_Select::ORDER);
$select->reset(Zend_Db_Select::LIMIT_COUNT);
$select->reset(Zend_Db_Select::LIMIT_OFFSET);
$attributeId = $model->getAttributeModel()->getId();
$storeId = $collection->getStoreId();
$select->join(array('decimal_index' => $this->getMainTable()), 'e.entity_id = decimal_index.entity_id' . ' AND ' . $this->_getReadAdapter()->quoteInto('decimal_index.attribute_id = ?', $attributeId) . ' AND ' . $this->_getReadAdapter()->quoteInto('decimal_index.store_id = ?', $storeId), array());
$adapter = $this->_getReadAdapter();
$countExpr = new Zend_Db_Expr("COUNT(*)");
$rangeExpr = new Zend_Db_Expr("FLOOR(decimal_index.value / {$model->getRange()}) + 1");
$select->columns(array('range' => $rangeExpr, 'count' => $countExpr));
$select->group('range');
return $adapter->fetchPairs($select);
}
示例7: countItems
/**
* @param Mana_Filters_Model_Filter_Attribute $filter
* @param Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection $collection
* @return Varien_Db_Select
*/
public function countItems($filter, $collection)
{
$select = $collection->getSelect();
$select->reset(Zend_Db_Select::COLUMNS);
$select->reset(Zend_Db_Select::ORDER);
$select->reset(Zend_Db_Select::GROUP);
$select->reset(Zend_Db_Select::LIMIT_COUNT);
$select->reset(Zend_Db_Select::LIMIT_OFFSET);
$db = $this->_getReadAdapter();
$attribute = $filter->getAttributeModel();
$selectedOptionIds = $filter->getMSelectedValues();
$isSelectedExpr = count($selectedOptionIds) ? "`eav`.`value` IN (" . implode(', ', $selectedOptionIds) . ")" : "NULL";
$fields = array('sort_order' => new Zend_Db_Expr("`o`.`sort_order`"), 'value' => new Zend_Db_Expr("`eav`.`value`"), 'label' => new Zend_Db_Expr("COALESCE(`vs`.`value`, `vg`.`value`)"), 'm_selected' => new Zend_Db_Expr($isSelectedExpr), 'm_show_selected' => new Zend_Db_Expr($filter->getFilterOptions()->getIsReverse() ? "NOT ({$isSelectedExpr})" : $isSelectedExpr));
$select->joinInner(array('eav' => $this->getTable('catalog/product_index_eav')), "`eav`.`entity_id` = `e`.`entity_id` AND\r\n {$db->quoteInto("`eav`.`attribute_id` = ?", $attribute->getAttributeId())} AND\r\n {$db->quoteInto("`eav`.`store_id` = ?", $filter->getStoreId())}", array('count' => "COUNT(DISTINCT `eav`.`entity_id`)"))->joinInner(array('o' => $this->getTable('eav/attribute_option')), "`o`.`option_id` = `eav`.`value`", null)->joinInner(array('vg' => $this->getTable('eav/attribute_option_value')), $db->quoteInto("`vg`.`option_id` = `eav`.`value` AND `vg`.`store_id` = ?", 0), null)->joinLeft(array('vs' => $this->getTable('eav/attribute_option_value')), $db->quoteInto("`vs`.`option_id` = `eav`.`value` AND `vs`.`store_id` = ?", $filter->getStoreId()), null)->columns($fields)->group($fields);
//$sql = $select->__toString();
return $select;
}
示例8: getAllOptimizedAttributeFilterCounts
public function getAllOptimizedAttributeFilterCounts()
{
if (!$this->_allOptimizedAttributeFilterCounts) {
$attributeIds = array();
$firstModel = null;
/* @var $firstModel Mana_Filters_Model_Filter_Attribute */
foreach ($this->_filters as $filter) {
$model = $filter['model'];
if ($this->isOptimizedAttributeFilter($model)) {
if (!$firstModel) {
$firstModel = $model;
}
/* @var $model Mana_Filters_Model_Filter_Attribute */
$id = $model->getAttributeModel()->getId();
$attributeIds[$id] = $id;
}
}
$mainSelect = clone $this->_productCollection->getSelect();
$collection = $this->createProductCollection();
foreach ($this->_filters as $filter) {
if ($filter['isApplied']) {
/* @var $filterModel Mana_Filters_Interface_Filter */
$filterModel = $filter['model'];
$applyFilter = true;
foreach ($this->_filters as $optimizedFilter) {
/* @var $model Mana_Filters_Model_Filter_Attribute */
$model = $optimizedFilter['model'];
if ($this->isOptimizedAttributeFilter($model) && !$model->isFilterAppliedWhenCounting($filterModel)) {
$applyFilter = false;
break;
}
}
if ($applyFilter) {
$filterModel->applyToCollection($collection);
}
}
}
$this->_allOptimizedAttributeFilterCounts = $firstModel ? $firstModel->optimizedCountOnCollection($collection, $attributeIds) : array();
$this->_copyParts($this->_productCollection->getSelect(), $mainSelect);
}
return $this->_allOptimizedAttributeFilterCounts;
}
示例9: applyToCollection
/**
* @param Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection $collection
* @param Morphes_Filters_Model_Filter_Decimal $model
* @param array $value
* @return Morphes_Filters_Resource_Filter_Decimal
*/
public function applyToCollection($collection, $model, $value)
{
$attribute = $model->getAttributeModel();
$connection = $this->_getReadAdapter();
$tableAlias = $attribute->getAttributeCode() . '_idx';
$conditions = array("{$tableAlias}.entity_id = e.entity_id", $connection->quoteInto("{$tableAlias}.attribute_id = ?", $attribute->getAttributeId()), $connection->quoteInto("{$tableAlias}.store_id = ?", $collection->getStoreId()));
$condition = '';
foreach ($value as $selection) {
if (strpos($selection, ',') !== false) {
list($index, $range) = explode(',', $selection);
$range = $this->getRange($index, $range);
if ($condition != '') {
$condition .= ' OR ';
}
$condition .= '((' . "{$tableAlias}.value" . ' >= ' . $range['from'] . ') ' . 'AND (' . "{$tableAlias}.value" . ($this->isUpperBoundInclusive() ? ' <= ' : ' < ') . $range['to'] . '))';
}
}
if ($condition) {
$collection->getSelect()->join(array($tableAlias => $this->getMainTable()), join(' AND ', $conditions), array())->distinct()->where("NOT ({$condition})");
}
return $this;
}
示例10: _getParentSelect
protected function _getParentSelect()
{
$collection = new Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection();
return $collection->getSelect();
}
示例11: prepareProductCollection
/**
* Filter product collection
*
* @param Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection $collection
* @return Mage_Catalog_Model_Layer
*/
public function prepareProductCollection($collection)
{
$rule = $this->getRule();
if ($rule->getData('show_outofstock') == 2) {
$collection->joinField('stock_status', 'cataloginventory/stock_status', 'stock_status', 'product_id=entity_id', array('stock_status' => Mage_CatalogInventory_Model_Stock_Status::STATUS_IN_STOCK, 'website_id' => Mage::app()->getWebsite()->getWebsiteId()));
}
$collection->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())->addMinimalPrice()->addFinalPrice()->addTaxPercents();
/*Filter min, max price*/
$this->currentRate = Mage::app()->getStore()->getCurrentCurrencyRate();
$max = $this->getMaxPriceFilter();
$min = $this->getMinPriceFilter();
if ($min && $max) {
$collection->getSelect()->where(' final_price >= "' . $min . '" AND final_price <= "' . $max . '" ');
}
/*End Filter min, max price*/
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);
//$this->_productCollections = $collection;
return $this;
}
示例12: addFilterOnlyMappedAttributes
/**
* Add WHERE statement for select only not mapped attributes with mapped value(s)
*
* @param Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection $collection
* @param $attributeSetId
* @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection
*/
public function addFilterOnlyMappedAttributes($collection, $attributeSetId)
{
$select = $this->_getMappedAttributes()->reset(Zend_Db_Select::COLUMNS)->columns(array('dummy_field' => new Zend_Db_Expr('1')))->where('main_table.attribute_id = ar.attribute_id')->where('tr.attribute_set_id = ?', $attributeSetId);
$collection->getSelect()->where(sprintf('NOT EXISTS(%s)', $select->assemble()));
return $collection;
}
示例13: prepareSqlForAtt
/**
* prepare sql for attribute compare
*
* @param object $attribute - attribute class with data
* @param array $joinedAttributes - attribute which was joined into query
* @param Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection $collection - product collection
* @param string $operator - operator for compare
* @param string $value - value for compare
* @return string $where - sql query
*/
public function prepareSqlForAtt($attribute, $joinedAttributes, $collection, $operator, $value)
{
$nOperator = array('==', '!{}', '{}', '!()', '()');
$mOperator = array('=', 'NOT LIKE', 'LIKE', 'NOT IN', 'IN');
//category operator
$cnOperator = array('==', '!=', '<=', '>=', '=', '>', '<', '!{}', '{}', '!()', '()', 'NOT LIKE', 'LIKE');
$cmOperator = array('IN', 'NOT IN', 'NOT IN', 'NOT IN', 'IN', 'NOT IN', 'NO IN', 'NOT IN', 'IN', 'NOT IN', 'IN', 'NOT IN', 'IN');
$operator = str_replace($nOperator, $mOperator, $operator);
if ($attribute == 'category_ids') {
$operator = str_replace($cnOperator, $cmOperator, $operator);
}
if (($operator == 'LIKE' || $operator == 'NOT LIKE') && is_array($value)) {
if ($operator == 'LIKE') {
$operator = 'FIND_IN_SET';
} else {
$operator = '!FIND_IN_SET';
}
}
/* Quote rule value depending operator type */
switch ($operator) {
case 'LIKE':
case 'NOT LIKE':
$value = $collection->getConnection()->quote("%{$value}%");
break;
case 'IN':
case 'NOT IN':
if (!is_array($value)) {
$value = array_filter(array_map('trim', explode(',', $value)));
}
$value = '(' . $collection->getConnection()->quote($value) . ')';
break;
case 'FIND_IN_SET':
case '!FIND_IN_SET':
$_resultSql = '(' . $collection->getConnection()->quote($value[0]) . ', att_table_' . $attribute . '.' . 'value)';
unset($value[0]);
foreach ($value as $_conditionValue) {
$_resultSql .= ' OR ' . $operator . '(' . $collection->getConnection()->quote($_conditionValue) . ', att_table_' . $attribute . '.' . 'value)';
}
$value = $_resultSql;
break;
default:
if (is_array($value)) {
$value = implode(',', $value);
}
$value = $collection->getConnection()->quote($value);
}
if (!in_array($attribute, $this->_joinedAttributes)) {
array_push($this->_joinedAttributes, $attribute);
$att = Mage::getModel('catalog/product')->getResource()->getAttribute($attribute);
if (!$att && $attribute != 'category_ids') {
return null;
}
switch ($attribute) {
case 'sku':
$collection->getSelect()->join(array('att_table_' . $attribute => $att->getBackend()->getTable()), 'att_table_' . $attribute . '.entity_id = e.entity_id', array('sku'));
break;
case 'category_ids':
$collection->getSelect()->joinLeft(array('att_table_' . $attribute => $collection->getTable('catalog/category_product')), 'att_table_' . $attribute . '.product_id = e.entity_id', array('category_id'));
break;
case 'attribute_set_id':
$collection->getSelect()->joinLeft(array('att_table_' . $attribute => $att->getBackend()->getTable()), 'att_table_' . $attribute . '.entity_id = e.entity_id', array('attribute_set_id'));
break;
case 'price':
$collection->addPriceData();
break;
default:
$collection->getSelect()->joinLeft(array('att_table_' . $attribute => $att->getBackend()->getTable()), 'att_table_' . $attribute . '.entity_id = e.entity_id AND att_table_' . $attribute . '.attribute_id = ' . $att->getId(), array('value'));
}
}
switch ($attribute) {
case 'sku':
$where = '(att_table_' . $attribute . '.' . 'sku' . ' ' . $operator . ' ' . $value . ')';
break;
case 'category_ids':
$where = '(IFNULL(att_table_' . $attribute . '.' . 'category_id,\'\')' . ' ' . $operator . ' ' . $value . ' AND e.entity_id ' . $operator . '(SELECT `product_id` FROM `' . $collection->getTable('catalog/category_product') . '` WHERE `category_id` IN' . $value . ')' . ' )';
break;
case 'price':
$where = '(price_index.final_price ' . $operator . ' ' . $value . ')' . ' AND (price_index.min_price ' . $operator . ' ' . $value . ')';
break;
case 'attribute_set_id':
$where = '(IFNULL(att_table_' . $attribute . '.' . 'attribute_set_id,\'\')' . ' ' . $operator . ' ' . $value . ')';
break;
default:
$where = '(IFNULL(att_table_' . $attribute . '.' . 'value,\'\')' . ' ' . $operator . ' ' . $value . ')';
if ($operator == 'FIND_IN_SET' || $operator == '!FIND_IN_SET') {
$where = '(' . $operator . ' ' . $value . ')';
}
}
return $where;
}
示例14: addPriceIndexFilter
/**
* Add price index filter
*
* @param Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection $collection
*
* @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection
*/
public function addPriceIndexFilter($collection)
{
$select = $collection->getSelect();
$fromPart = $select->getPart(Zend_Db_Select::FROM);
if (isset($fromPart['price_index'])) {
$joinCond = $fromPart['price_index']['joinCondition'];
if (strpos($joinCond, 'price_index.store_id') === false) {
$helper = $this->getStorePricingHelper();
$connection = $collection->getConnection();
if (!$collection->getFlag('store_id')) {
$storeId = $helper->getCurrentStoreId();
} else {
$storeId = $collection->getFlag('store_id');
}
$storeId = $connection->quote($storeId);
if ($storeId) {
$joinCond .= " AND (price_index.store_id = {$storeId})";
} else {
$joinCond .= " AND (price_index.store_id = 0)";
}
$fromPart['price_index']['joinCondition'] = $joinCond;
$select->setPart(Zend_Db_Select::FROM, $fromPart);
}
}
return $collection;
}
示例15: prepareSqlForAtt
/**
* prepare sql for attribute compare
*
* @param object $attribute - attribute class with data
* @param array $joinedAttributes - attribute which was joined into query
* @param Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection $collection - product collection
* @param string $operator - operator for compare
* @param string $value - value for compare
* @return string $where - sql query
*/
public function prepareSqlForAtt($attribute, $joinedAttributes, $collection, $operator, $value)
{
$nOperator = array('==', '!{}', '{}', '!()', '()');
$mOperator = array('=', 'NOT LIKE', 'LIKE', 'NOT IN', 'IN');
//category operator
//$cnOperator = array('==', '!=', '=', '>=', '<=', '>', '<', '!{}', '{}', '!()', '()', 'NOT LIKE', 'LIKE');
$cnOperator = array('==', '!=', '<=', '>=', '=', '>', '<', '!{}', '{}', '!()', '()', 'NOT LIKE', 'LIKE');
//$cmOperator = array('=','!=','!=','!=','!=','!=','NOT IN','IN','NOT IN','IN');
//$cmOperator = array('IN', 'NOT IN', 'IN', 'NOT IN', 'NOT IN', 'NOT IN', 'NO IN', 'NOT IN', 'IN', 'NOT IN', 'IN', 'NOT IN', 'IN');
$cmOperator = array('IN', 'NOT IN', 'NOT IN', 'NOT IN', 'IN', 'NOT IN', 'NO IN', 'NOT IN', 'IN', 'NOT IN', 'IN', 'NOT IN', 'IN');
$operator = $attribute == 'category_ids' ? str_replace($cnOperator, $cmOperator, $operator) : str_replace($nOperator, $mOperator, $operator);
/* Quote rule value depending operator type */
switch ($operator) {
case 'LIKE':
case 'NOT LIKE':
$value = $collection->getConnection()->quote("%{$value}%");
break;
case 'IN':
case 'NOT IN':
$value = '(' . $collection->getConnection()->quote(explode(',', $value)) . ')';
break;
default:
$value = $collection->getConnection()->quote($value);
}
/* */
if (!in_array($attribute, $this->_joinedAttributes)) {
array_push($this->_joinedAttributes, $attribute);
//$this->_joinedAttributes = $joinedAttributes;
$att = Mage::getModel('catalog/product')->getResource()->getAttribute($attribute);
if (!$att && $attribute != 'category_ids') {
return null;
}
switch ($attribute) {
case 'sku':
$collection->getSelect()->join(array('att_table_' . $attribute => $att->getBackend()->getTable()), 'att_table_' . $attribute . '.entity_id = e.entity_id', array('sku'));
break;
case 'category_ids':
$collection->getSelect()->joinLeft(array('att_table_' . $attribute => $collection->getTable('catalog/category_product')), 'att_table_' . $attribute . '.product_id = e.entity_id', array('category_id'));
break;
case 'attribute_set_id':
$collection->getSelect()->joinLeft(array('att_table_' . $attribute => $att->getBackend()->getTable()), 'att_table_' . $attribute . '.entity_id = e.entity_id', array('attribute_set_id'));
break;
case 'price':
$collection->addPriceData();
break;
default:
$collection->getSelect()->joinLeft(array('att_table_' . $attribute => $att->getBackend()->getTable()), 'att_table_' . $attribute . '.entity_id = e.entity_id AND att_table_' . $attribute . '.attribute_id = ' . $att->getId(), array('value'));
}
}
switch ($attribute) {
case 'sku':
$where = '(att_table_' . $attribute . '.' . 'sku' . ' ' . $operator . ' ' . $value . ')';
break;
case 'category_ids':
$where = '(IFNULL(att_table_' . $attribute . '.' . 'category_id,\'\')' . ' ' . $operator . ' ' . $value . ' AND e.entity_id ' . $operator . '(SELECT `product_id` FROM `' . $collection->getTable('catalog/category_product') . '` WHERE `category_id` IN' . $value . ')' . ' )';
break;
case 'price':
$where = $collection->getConnection()->quoteInto('(price_index.final_price ' . $operator . '?)', $value);
break;
case 'attribute_set_id':
$where = '(IFNULL(att_table_' . $attribute . '.' . 'attribute_set_id,\'\')' . ' ' . $operator . ' ' . $value . ')';
break;
default:
$where = '(IFNULL(att_table_' . $attribute . '.' . 'value,\'\')' . ' ' . $operator . ' ' . $value . ')';
}
return $where;
}